From 83880dbed77f9a0a3627bce2e7bfbe1b862e091d Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Thu, 3 Dec 2015 12:56:18 -0200 Subject: When zero-timeout, only try first address in connect. --- src/inet.c | 4 ++-- src/tcp.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/inet.c b/src/inet.c index 331b800..f4c8404 100644 --- a/src/inet.c +++ b/src/inet.c @@ -423,8 +423,8 @@ const char *inet_tryconnect(p_socket ps, int *family, const char *address, /* try connecting to remote address */ err = socket_strerror(socket_connect(ps, (SA *) iterator->ai_addr, (socklen_t) iterator->ai_addrlen, tm)); - /* if success, break out of loop */ - if (err == NULL) { + /* if success or timeout is zero, break out of loop */ + if (err == NULL || timeout_iszero(tm)) { *family = current_family; break; } diff --git a/src/tcp.c b/src/tcp.c index cef9d16..e4f1a4b 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -417,7 +417,7 @@ static int global_connect(lua_State *L) { bindhints.ai_family = family; bindhints.ai_flags = AI_PASSIVE; if (localaddr) { - err = inet_trybind(&tcp->sock, &tcp->family, localaddr, + err = inet_trybind(&tcp->sock, &tcp->family, localaddr, localserv, &bindhints); if (err) { lua_pushnil(L); @@ -429,7 +429,7 @@ static int global_connect(lua_State *L) { memset(&connecthints, 0, sizeof(connecthints)); connecthints.ai_socktype = SOCK_STREAM; /* make sure we try to connect only to the same family */ - connecthints.ai_family = tcp->family; + connecthints.ai_family = tcp->family; err = inet_tryconnect(&tcp->sock, &tcp->family, remoteaddr, remoteserv, &tcp->tm, &connecthints); if (err) { -- cgit v1.2.3-55-g6feb