MCPcopy Create free account
hub / github.com/Tencent/UnLua / tcp_create

Function tcp_create

Plugins/UnLuaExtensions/LuaSocket/Source/src/tcp.cpp:387–411  ·  view source on GitHub ↗

=========================================================================*\ * Library functions \*=========================================================================*/ -------------------------------------------------------------------------*\ * Creates a master tcp object \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

385* Creates a master tcp object
386\*-------------------------------------------------------------------------*/
387static int tcp_create(lua_State *L, int family) {
388 p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp));
389 memset(tcp, 0, sizeof(t_tcp));
390 /* set its type as master object */
391 auxiliar_setclass(L, "tcp{master}", -1);
392 /* if family is AF_UNSPEC, we leave the socket invalid and
393 * store AF_UNSPEC into family. This will allow it to later be
394 * replaced with an AF_INET6 or AF_INET socket upon first use. */
395 tcp->sock = SOCKET_INVALID;
396 tcp->family = family;
397 io_init(&tcp->io, (p_send) socket_send, (p_recv) socket_recv,
398 (p_error) socket_ioerror, &tcp->sock);
399 timeout_init(&tcp->tm, -1, -1);
400 buffer_init(&tcp->buf, &tcp->io, &tcp->tm);
401 if (family != AF_UNSPEC) {
402 const char *err = inet_trycreate(&tcp->sock, family, SOCK_STREAM, 0);
403 if (err != NULL) {
404 lua_pushnil(L);
405 lua_pushstring(L, err);
406 return 2;
407 }
408 socket_setnonblocking(&tcp->sock);
409 }
410 return 1;
411}
412
413static int global_create(lua_State *L) {
414 return tcp_create(L, AF_UNSPEC);

Callers 3

global_createFunction · 0.85
global_create4Function · 0.85
global_create6Function · 0.85

Calls 8

auxiliar_setclassFunction · 0.85
io_initFunction · 0.85
timeout_initFunction · 0.85
buffer_initFunction · 0.85
inet_trycreateFunction · 0.85
lua_pushnilFunction · 0.85
lua_pushstringFunction · 0.85
socket_setnonblockingFunction · 0.70

Tested by

no test coverage detected