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

Function udp_create

Plugins/UnLuaExtensions/LuaSocket/Source/src/udp.cpp:460–480  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

458* Creates a master udp object
459\*-------------------------------------------------------------------------*/
460static int udp_create(lua_State *L, int family) {
461 /* allocate udp object */
462 p_udp udp = (p_udp) lua_newuserdata(L, sizeof(t_udp));
463 auxiliar_setclass(L, "udp{unconnected}", -1);
464 /* if family is AF_UNSPEC, we leave the socket invalid and
465 * store AF_UNSPEC into family. This will allow it to later be
466 * replaced with an AF_INET6 or AF_INET socket upon first use. */
467 udp->sock = SOCKET_INVALID;
468 timeout_init(&udp->tm, -1, -1);
469 udp->family = family;
470 if (family != AF_UNSPEC) {
471 const char *err = inet_trycreate(&udp->sock, family, SOCK_DGRAM, 0);
472 if (err != NULL) {
473 lua_pushnil(L);
474 lua_pushstring(L, err);
475 return 2;
476 }
477 socket_setnonblocking(&udp->sock);
478 }
479 return 1;
480}
481
482static int global_create(lua_State *L) {
483 return udp_create(L, AF_UNSPEC);

Callers 3

global_createFunction · 0.85
global_create4Function · 0.85
global_create6Function · 0.85

Calls 6

auxiliar_setclassFunction · 0.85
timeout_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