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

Function meth_bind

Plugins/UnLuaExtensions/LuaSocket/Source/src/tcp.cpp:242–260  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * Binds an object to an address \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

240* Binds an object to an address
241\*-------------------------------------------------------------------------*/
242static int meth_bind(lua_State *L) {
243 p_tcp tcp = (p_tcp) auxiliar_checkclass(L, "tcp{master}", 1);
244 const char *address = luaL_checkstring(L, 2);
245 const char *port = luaL_checkstring(L, 3);
246 const char *err;
247 struct addrinfo bindhints;
248 memset(&bindhints, 0, sizeof(bindhints));
249 bindhints.ai_socktype = SOCK_STREAM;
250 bindhints.ai_family = tcp->family;
251 bindhints.ai_flags = AI_PASSIVE;
252 err = inet_trybind(&tcp->sock, &tcp->family, address, port, &bindhints);
253 if (err) {
254 lua_pushnil(L);
255 lua_pushstring(L, err);
256 return 2;
257 }
258 lua_pushnumber(L, 1);
259 return 1;
260}
261
262/*-------------------------------------------------------------------------*\
263* Turns a master tcp object into a client object.

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