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