MCPcopy Create free account
hub / github.com/defold/defold / udp_create

Function udp_create

engine/script/src/luasocket/udp.c:417–443  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

415* Creates a master udp object
416\*-------------------------------------------------------------------------*/
417static int udp_create(lua_State *L, int family) {
418 t_socket sock;
419 const char *err = inet_trycreate(&sock, family, SOCK_DGRAM);
420 /* try to allocate a system socket */
421 if (!err) {
422 /* allocate udp object */
423 p_udp udp = (p_udp) lua_newuserdata(L, sizeof(t_udp));
424 auxiliar_setclass(L, "udp{unconnected}", -1);
425 /* initialize remaining structure fields */
426 socket_setnonblocking(&sock);
427#if !defined(DM_IPV6_UNSUPPORTED) && !defined(__EMSCRIPTEN__)
428 if (family == PF_INET6) {
429 int yes = 1;
430 setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
431 (void *)&yes, sizeof(yes));
432 }
433#endif // DM_IPV6_UNSUPPORTED
434 udp->sock = sock;
435 timeout_init(&udp->tm, -1, -1);
436 udp->family = family;
437 return 1;
438 } else {
439 lua_pushnil(L);
440 lua_pushstring(L, err);
441 return 2;
442 }
443}
444
445static int global_create(lua_State *L) {
446 return udp_create(L, AF_INET);

Callers 2

global_createFunction · 0.85
global_create6Function · 0.85

Calls 7

inet_trycreateFunction · 0.85
lua_newuserdataFunction · 0.85
auxiliar_setclassFunction · 0.85
timeout_initFunction · 0.85
lua_pushnilFunction · 0.85
lua_pushstringFunction · 0.85
socket_setnonblockingFunction · 0.70

Tested by

no test coverage detected