|
|
@ -411,19 +411,15 @@ int connect_socket(char *url, char *port) |
|
|
|
* we can connect to quickly. */ |
|
|
|
* we can connect to quickly. */ |
|
|
|
noblock_socket(sockd); |
|
|
|
noblock_socket(sockd); |
|
|
|
if (connect(sockd, p->ai_addr, p->ai_addrlen) == -1) { |
|
|
|
if (connect(sockd, p->ai_addr, p->ai_addrlen) == -1) { |
|
|
|
struct timeval tv_timeout = {5, 0}; |
|
|
|
|
|
|
|
int selret; |
|
|
|
int selret; |
|
|
|
fd_set rw; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!sock_connecting()) { |
|
|
|
if (!sock_connecting()) { |
|
|
|
close(sockd); |
|
|
|
close(sockd); |
|
|
|
LOGDEBUG("Failed sock connect"); |
|
|
|
LOGDEBUG("Failed sock connect"); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
FD_ZERO(&rw); |
|
|
|
selret = wait_write_select(sockd, 5); |
|
|
|
FD_SET(sockd, &rw); |
|
|
|
if (selret > 0) { |
|
|
|
selret = select(sockd + 1, NULL, &rw, NULL, &tv_timeout); |
|
|
|
|
|
|
|
if (selret > 0 && FD_ISSET(sockd, &rw)) { |
|
|
|
|
|
|
|
socklen_t len; |
|
|
|
socklen_t len; |
|
|
|
int err, n; |
|
|
|
int err, n; |
|
|
|
|
|
|
|
|
|
|
@ -457,13 +453,9 @@ out: |
|
|
|
|
|
|
|
|
|
|
|
int write_socket(int fd, const void *buf, size_t nbyte) |
|
|
|
int write_socket(int fd, const void *buf, size_t nbyte) |
|
|
|
{ |
|
|
|
{ |
|
|
|
tv_t tv_timeout = {1, 0}; |
|
|
|
|
|
|
|
fd_set writefds; |
|
|
|
|
|
|
|
int ret; |
|
|
|
int ret; |
|
|
|
|
|
|
|
|
|
|
|
FD_ZERO(&writefds); |
|
|
|
ret = wait_write_select(fd, 5); |
|
|
|
FD_SET(fd, &writefds); |
|
|
|
|
|
|
|
ret = select(fd + 1, NULL, &writefds, NULL, &tv_timeout); |
|
|
|
|
|
|
|
if (ret < 1) { |
|
|
|
if (ret < 1) { |
|
|
|
if (!ret) |
|
|
|
if (!ret) |
|
|
|
LOGNOTICE("Select timed out in write_socket"); |
|
|
|
LOGNOTICE("Select timed out in write_socket"); |
|
|
@ -487,12 +479,8 @@ void empty_socket(int fd) |
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
do { |
|
|
|
char buf[PAGESIZE]; |
|
|
|
char buf[PAGESIZE]; |
|
|
|
tv_t timeout = {0, 0}; |
|
|
|
|
|
|
|
fd_set rd; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FD_ZERO(&rd); |
|
|
|
ret = wait_read_select(fd, 0); |
|
|
|
FD_SET(fd, &rd); |
|
|
|
|
|
|
|
ret = select(fd + 1, &rd, NULL, NULL, &timeout); |
|
|
|
|
|
|
|
if (ret > 0) { |
|
|
|
if (ret > 0) { |
|
|
|
ret = recv(fd, buf, PAGESIZE - 1, 0); |
|
|
|
ret = recv(fd, buf, PAGESIZE - 1, 0); |
|
|
|
buf[ret] = 0; |
|
|
|
buf[ret] = 0; |
|
|
@ -625,7 +613,9 @@ int wait_read_select(int sockd, int timeout) |
|
|
|
|
|
|
|
|
|
|
|
FD_ZERO(&readfs); |
|
|
|
FD_ZERO(&readfs); |
|
|
|
FD_SET(sockd, &readfs); |
|
|
|
FD_SET(sockd, &readfs); |
|
|
|
|
|
|
|
do { |
|
|
|
ret = select(sockd + 1, &readfs, NULL, NULL, &tv_timeout); |
|
|
|
ret = select(sockd + 1, &readfs, NULL, NULL, &tv_timeout); |
|
|
|
|
|
|
|
} while (unlikely(ret < 0 && interrupted())); |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -700,7 +690,9 @@ int wait_write_select(int sockd, int timeout) |
|
|
|
|
|
|
|
|
|
|
|
FD_ZERO(&writefds); |
|
|
|
FD_ZERO(&writefds); |
|
|
|
FD_SET(sockd, &writefds); |
|
|
|
FD_SET(sockd, &writefds); |
|
|
|
|
|
|
|
do { |
|
|
|
ret = select(sockd + 1, NULL, &writefds, NULL, &tv_timeout); |
|
|
|
ret = select(sockd + 1, NULL, &writefds, NULL, &tv_timeout); |
|
|
|
|
|
|
|
} while (unlikely(ret < 0 && interrupted())); |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|