diff options
| author | Diego Nehab <diego@impa.br> | 2013-05-26 21:26:26 +0800 |
|---|---|---|
| committer | Diego Nehab <diego@impa.br> | 2013-05-26 21:26:26 +0800 |
| commit | 427220c7b177cdae2379ac419d975c69764ba8ee (patch) | |
| tree | b2690db3cb9cde4505ad51eaac83d3fe4a854ff5 /src/tcp.c | |
| parent | 6d93fd7c8f04fecbcdc28994da8b8357f712463f (diff) | |
| download | luasocket-427220c7b177cdae2379ac419d975c69764ba8ee.tar.gz luasocket-427220c7b177cdae2379ac419d975c69764ba8ee.tar.bz2 luasocket-427220c7b177cdae2379ac419d975c69764ba8ee.zip | |
Merge tryconnect6 into inet_tryconnect.
Diffstat (limited to 'src/tcp.c')
| -rw-r--r-- | src/tcp.c | 18 |
1 files changed, 6 insertions, 12 deletions
| @@ -248,7 +248,8 @@ static int meth_connect(lua_State *L) | |||
| 248 | /* make sure we try to connect only to the same family */ | 248 | /* make sure we try to connect only to the same family */ |
| 249 | connecthints.ai_family = tcp->family; | 249 | connecthints.ai_family = tcp->family; |
| 250 | timeout_markstart(&tcp->tm); | 250 | timeout_markstart(&tcp->tm); |
| 251 | err = inet_tryconnect(&tcp->sock, address, port, &tcp->tm, &connecthints); | 251 | err = inet_tryconnect(&tcp->sock, &tcp->family, address, port, |
| 252 | &tcp->tm, &connecthints); | ||
| 252 | /* have to set the class even if it failed due to non-blocking connects */ | 253 | /* have to set the class even if it failed due to non-blocking connects */ |
| 253 | auxiliar_setclass(L, "tcp{client}", 1); | 254 | auxiliar_setclass(L, "tcp{client}", 1); |
| 254 | if (err) { | 255 | if (err) { |
| @@ -388,20 +389,11 @@ static int global_create6(lua_State *L) { | |||
| 388 | return tcp_create(L, AF_INET6); | 389 | return tcp_create(L, AF_INET6); |
| 389 | } | 390 | } |
| 390 | 391 | ||
| 391 | const char *strfamily(int family) { | 392 | #if 0 |
| 392 | switch (family) { | ||
| 393 | case PF_UNSPEC: return "unspec"; | ||
| 394 | case PF_INET: return "inet"; | ||
| 395 | case PF_INET6: return "inet6"; | ||
| 396 | default: return "invalid"; | ||
| 397 | } | ||
| 398 | } | ||
| 399 | |||
| 400 | static const char *tryconnect6(const char *remoteaddr, const char *remoteserv, | 393 | static const char *tryconnect6(const char *remoteaddr, const char *remoteserv, |
| 401 | struct addrinfo *connecthints, p_tcp tcp) { | 394 | struct addrinfo *connecthints, p_tcp tcp) { |
| 402 | struct addrinfo *iterator = NULL, *resolved = NULL; | 395 | struct addrinfo *iterator = NULL, *resolved = NULL; |
| 403 | const char *err = NULL; | 396 | const char *err = NULL; |
| 404 | int i = 0; | ||
| 405 | /* try resolving */ | 397 | /* try resolving */ |
| 406 | err = socket_gaistrerror(getaddrinfo(remoteaddr, remoteserv, | 398 | err = socket_gaistrerror(getaddrinfo(remoteaddr, remoteserv, |
| 407 | connecthints, &resolved)); | 399 | connecthints, &resolved)); |
| @@ -442,6 +434,7 @@ static const char *tryconnect6(const char *remoteaddr, const char *remoteserv, | |||
| 442 | /* here, if err is set, we failed */ | 434 | /* here, if err is set, we failed */ |
| 443 | return err; | 435 | return err; |
| 444 | } | 436 | } |
| 437 | #endif | ||
| 445 | 438 | ||
| 446 | static int global_connect(lua_State *L) { | 439 | static int global_connect(lua_State *L) { |
| 447 | const char *remoteaddr = luaL_checkstring(L, 1); | 440 | const char *remoteaddr = luaL_checkstring(L, 1); |
| @@ -479,7 +472,8 @@ static int global_connect(lua_State *L) { | |||
| 479 | connecthints.ai_socktype = SOCK_STREAM; | 472 | connecthints.ai_socktype = SOCK_STREAM; |
| 480 | /* make sure we try to connect only to the same family */ | 473 | /* make sure we try to connect only to the same family */ |
| 481 | connecthints.ai_family = bindhints.ai_family; | 474 | connecthints.ai_family = bindhints.ai_family; |
| 482 | err = tryconnect6(remoteaddr, remoteserv, &connecthints, tcp); | 475 | err = inet_tryconnect(&tcp->sock, &tcp->family, remoteaddr, remoteserv, |
| 476 | &tcp->tm, &connecthints); | ||
| 483 | if (err) { | 477 | if (err) { |
| 484 | socket_destroy(&tcp->sock); | 478 | socket_destroy(&tcp->sock); |
| 485 | lua_pushnil(L); | 479 | lua_pushnil(L); |
