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

Function meth_setsockname

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

-------------------------------------------------------------------------*\ * Turns a master object into a server object \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

432* Turns a master object into a server object
433\*-------------------------------------------------------------------------*/
434static int meth_setsockname(lua_State *L) {
435 p_udp udp = (p_udp) auxiliar_checkclass(L, "udp{unconnected}", 1);
436 const char *address = luaL_checkstring(L, 2);
437 const char *port = luaL_checkstring(L, 3);
438 const char *err;
439 struct addrinfo bindhints;
440 memset(&bindhints, 0, sizeof(bindhints));
441 bindhints.ai_socktype = SOCK_DGRAM;
442 bindhints.ai_family = udp->family;
443 bindhints.ai_flags = AI_PASSIVE;
444 err = inet_trybind(&udp->sock, &udp->family, address, port, &bindhints);
445 if (err) {
446 lua_pushnil(L);
447 lua_pushstring(L, err);
448 return 2;
449 }
450 lua_pushnumber(L, 1);
451 return 1;
452}
453
454/*=========================================================================*\
455* Library functions

Callers

nothing calls this directly

Calls 5

auxiliar_checkclassFunction · 0.85
inet_trybindFunction · 0.85
lua_pushnilFunction · 0.85
lua_pushstringFunction · 0.85
lua_pushnumberFunction · 0.85

Tested by

no test coverage detected