diff options
author | Diego Nehab <diego.nehab@gmail.com> | 2015-12-03 12:56:18 -0200 |
---|---|---|
committer | Diego Nehab <diego.nehab@gmail.com> | 2015-12-03 12:56:18 -0200 |
commit | 83880dbed77f9a0a3627bce2e7bfbe1b862e091d (patch) | |
tree | b5c9dcf94fe311c27a42096c04907fcd17265404 | |
parent | be67f63f4e11e53690bf1431a236f86b484c9bf0 (diff) | |
download | luasocket-83880dbed77f9a0a3627bce2e7bfbe1b862e091d.tar.gz luasocket-83880dbed77f9a0a3627bce2e7bfbe1b862e091d.tar.bz2 luasocket-83880dbed77f9a0a3627bce2e7bfbe1b862e091d.zip |
When zero-timeout, only try first address in connect.
-rw-r--r-- | doc/tcp.html | 13 | ||||
-rw-r--r-- | src/inet.c | 4 | ||||
-rw-r--r-- | src/tcp.c | 4 |
3 files changed, 12 insertions, 9 deletions
diff --git a/doc/tcp.html b/doc/tcp.html index fb627a1..c86853d 100644 --- a/doc/tcp.html +++ b/doc/tcp.html | |||
@@ -242,11 +242,14 @@ established. | |||
242 | 242 | ||
243 | <p class=note> | 243 | <p class=note> |
244 | Note: Starting with LuaSocket 3.0, the host name resolution | 244 | Note: Starting with LuaSocket 3.0, the host name resolution |
245 | depends on whether the socket was created by <a | 245 | depends on whether the socket was created by |
246 | href=#socket.tcp><tt>socket.tcp</tt></a> or <a | 246 | <a href=#socket.tcp><tt>socket.tcp</tt></a>, |
247 | href=#socket.tcp6><tt>socket.tcp6</tt></a>. Addresses from | 247 | <a href=#socket.tcp4><tt>socket.tcp4</tt></a> or |
248 | the appropriate family are tried in succession until the | 248 | <a href=#socket.tcp6><tt>socket.tcp6</tt></a>. Addresses from |
249 | first success or until the last failure. | 249 | the appropriate family (or both) are tried in the order |
250 | returned by the resolver until the | ||
251 | first success or until the last failure. If the timeout was | ||
252 | set to zero, only the first address is tried. | ||
250 | </p> | 253 | </p> |
251 | 254 | ||
252 | <!-- getpeername ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 255 | <!-- getpeername ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
@@ -423,8 +423,8 @@ const char *inet_tryconnect(p_socket ps, int *family, const char *address, | |||
423 | /* try connecting to remote address */ | 423 | /* try connecting to remote address */ |
424 | err = socket_strerror(socket_connect(ps, (SA *) iterator->ai_addr, | 424 | err = socket_strerror(socket_connect(ps, (SA *) iterator->ai_addr, |
425 | (socklen_t) iterator->ai_addrlen, tm)); | 425 | (socklen_t) iterator->ai_addrlen, tm)); |
426 | /* if success, break out of loop */ | 426 | /* if success or timeout is zero, break out of loop */ |
427 | if (err == NULL) { | 427 | if (err == NULL || timeout_iszero(tm)) { |
428 | *family = current_family; | 428 | *family = current_family; |
429 | break; | 429 | break; |
430 | } | 430 | } |
@@ -417,7 +417,7 @@ static int global_connect(lua_State *L) { | |||
417 | bindhints.ai_family = family; | 417 | bindhints.ai_family = family; |
418 | bindhints.ai_flags = AI_PASSIVE; | 418 | bindhints.ai_flags = AI_PASSIVE; |
419 | if (localaddr) { | 419 | if (localaddr) { |
420 | err = inet_trybind(&tcp->sock, &tcp->family, localaddr, | 420 | err = inet_trybind(&tcp->sock, &tcp->family, localaddr, |
421 | localserv, &bindhints); | 421 | localserv, &bindhints); |
422 | if (err) { | 422 | if (err) { |
423 | lua_pushnil(L); | 423 | lua_pushnil(L); |
@@ -429,7 +429,7 @@ static int global_connect(lua_State *L) { | |||
429 | memset(&connecthints, 0, sizeof(connecthints)); | 429 | memset(&connecthints, 0, sizeof(connecthints)); |
430 | connecthints.ai_socktype = SOCK_STREAM; | 430 | connecthints.ai_socktype = SOCK_STREAM; |
431 | /* make sure we try to connect only to the same family */ | 431 | /* make sure we try to connect only to the same family */ |
432 | connecthints.ai_family = tcp->family; | 432 | connecthints.ai_family = tcp->family; |
433 | err = inet_tryconnect(&tcp->sock, &tcp->family, remoteaddr, remoteserv, | 433 | err = inet_tryconnect(&tcp->sock, &tcp->family, remoteaddr, remoteserv, |
434 | &tcp->tm, &connecthints); | 434 | &tcp->tm, &connecthints); |
435 | if (err) { | 435 | if (err) { |