=========================================================================*\ * Library functions \*=========================================================================*/ -------------------------------------------------------------------------*\ * Creates a master udp object \*-------------------------------------------------------------------------*/
| 458 | * Creates a master udp object |
| 459 | \*-------------------------------------------------------------------------*/ |
| 460 | static 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 | |
| 482 | static int global_create(lua_State *L) { |
| 483 | return udp_create(L, AF_UNSPEC); |
no test coverage detected