-------------------------------------------------------------------------*\ * Binds an object to an address \*-------------------------------------------------------------------------*/
| 240 | * Binds an object to an address |
| 241 | \*-------------------------------------------------------------------------*/ |
| 242 | static 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. |
nothing calls this directly
no test coverage detected