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

Function meth_bind

engine/script/src/luasocket/tcp.c:221–240  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

219* Binds an object to an address
220\*-------------------------------------------------------------------------*/
221static int meth_bind(lua_State *L)
222{
223 p_tcp tcp = (p_tcp) auxiliar_checkclass(L, "tcp{master}", 1);
224 const char *address = luaL_checkstring(L, 2);
225 const char *port = luaL_checkstring(L, 3);
226 const char *err;
227 struct addrinfo bindhints;
228 memset(&bindhints, 0, sizeof(bindhints));
229 bindhints.ai_socktype = SOCK_STREAM;
230 bindhints.ai_family = tcp->family;
231 bindhints.ai_flags = AI_PASSIVE;
232 err = inet_trybind(&tcp->sock, address, port, &bindhints);
233 if (err) {
234 lua_pushnil(L);
235 lua_pushstring(L, err);
236 return 2;
237 }
238 lua_pushnumber(L, 1);
239 return 1;
240}
241
242/*-------------------------------------------------------------------------*\
243* 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