-------------------------------------------------------------------------*\ * Turns a master udp object into a client object. \*-------------------------------------------------------------------------*/
| 388 | * Turns a master udp object into a client object. |
| 389 | \*-------------------------------------------------------------------------*/ |
| 390 | static int meth_setpeername(lua_State *L) { |
| 391 | p_udp udp = (p_udp) auxiliar_checkgroup(L, "udp{any}", 1); |
| 392 | p_timeout tm = &udp->tm; |
| 393 | const char *address = luaL_checkstring(L, 2); |
| 394 | int connecting = strcmp(address, "*"); |
| 395 | const char *port = connecting? luaL_checkstring(L, 3): "0"; |
| 396 | struct addrinfo connecthints; |
| 397 | const char *err; |
| 398 | memset(&connecthints, 0, sizeof(connecthints)); |
| 399 | connecthints.ai_socktype = SOCK_DGRAM; |
| 400 | /* make sure we try to connect only to the same family */ |
| 401 | connecthints.ai_family = udp->family; |
| 402 | if (connecting) { |
| 403 | err = inet_tryconnect(&udp->sock, &udp->family, address, |
| 404 | port, tm, &connecthints); |
| 405 | if (err) { |
| 406 | lua_pushnil(L); |
| 407 | lua_pushstring(L, err); |
| 408 | return 2; |
| 409 | } |
| 410 | auxiliar_setclass(L, "udp{connected}", 1); |
| 411 | } else { |
| 412 | /* we ignore possible errors because Mac OS X always |
| 413 | * returns EAFNOSUPPORT */ |
| 414 | inet_trydisconnect(&udp->sock, udp->family, tm); |
| 415 | auxiliar_setclass(L, "udp{unconnected}", 1); |
| 416 | } |
| 417 | lua_pushnumber(L, 1); |
| 418 | return 1; |
| 419 | } |
| 420 | |
| 421 | /*-------------------------------------------------------------------------*\ |
| 422 | * Closes socket used by object |
nothing calls this directly
no test coverage detected