Browse Source

Use the retry on EINTR only on unix sockets

master
Con Kolivas 11 years ago
parent
commit
a3a586ee6e
  1. 6
      src/connector.c
  2. 14
      src/libckpool.c

6
src/connector.c

@ -93,11 +93,8 @@ void *acceptor(void *arg)
retry: retry:
client = ckzalloc(sizeof(client_instance_t)); client = ckzalloc(sizeof(client_instance_t));
client->address_len = sizeof(client->address); client->address_len = sizeof(client->address);
reaccept:
fd = accept(ci->serverfd, &client->address, &client->address_len); fd = accept(ci->serverfd, &client->address, &client->address_len);
if (unlikely(fd < 0)) { if (unlikely(fd < 0)) {
if (interrupted())
goto reaccept;
LOGERR("Failed to accept on socket %d in acceptor", ci->serverfd); LOGERR("Failed to accept on socket %d in acceptor", ci->serverfd);
dealloc(client); dealloc(client);
goto out; goto out;
@ -258,11 +255,8 @@ retry:
cksleep_ms(100); cksleep_ms(100);
goto retry; goto retry;
} }
repoll:
ret = poll(fds, nfds, 1000); ret = poll(fds, nfds, 1000);
if (ret < 0) { if (ret < 0) {
if (interrupted())
goto repoll;
LOGERR("Failed to poll in receiver"); LOGERR("Failed to poll in receiver");
goto out; goto out;
} }

14
src/libckpool.c

@ -403,7 +403,6 @@ int connect_socket(char *url, char *port)
LOGDEBUG("Failed sock connect"); LOGDEBUG("Failed sock connect");
continue; continue;
} }
retry:
FD_ZERO(&rw); FD_ZERO(&rw);
FD_SET(sockd, &rw); FD_SET(sockd, &rw);
selret = select(sockd + 1, NULL, &rw, NULL, &tv_timeout); selret = select(sockd + 1, NULL, &rw, NULL, &tv_timeout);
@ -419,8 +418,6 @@ retry:
break; break;
} }
} }
if (selret < 0 && interrupted())
goto retry;
close(sockd); close(sockd);
sockd = -1; sockd = -1;
LOGDEBUG("Select timeout/failed connect"); LOGDEBUG("Select timeout/failed connect");
@ -447,12 +444,9 @@ int write_socket(int fd, const void *buf, size_t nbyte)
fd_set writefds; fd_set writefds;
int ret; int ret;
retry:
FD_ZERO(&writefds); FD_ZERO(&writefds);
FD_SET(fd, &writefds); FD_SET(fd, &writefds);
ret = select(fd + 1, NULL, &writefds, NULL, &tv_timeout); ret = select(fd + 1, NULL, &writefds, NULL, &tv_timeout);
if (ret < 0 && interrupted())
goto retry;
if (ret < 1) { if (ret < 1) {
if (!ret) if (!ret)
LOGNOTICE("Select timed out in write_socket"); LOGNOTICE("Select timed out in write_socket");
@ -472,14 +466,14 @@ out:
int read_socket_line(connsock_t *cs, int timeout) int read_socket_line(connsock_t *cs, int timeout)
{ {
size_t buflen = 0, bufofs = 0; size_t buflen = 0, bufofs = 0;
int ret = -1, bufsiz;
char *eom = NULL; char *eom = NULL;
tv_t tv_timeout; tv_t tv_timeout;
int ret, bufsiz;
fd_set rd; fd_set rd;
dealloc(cs->buf); dealloc(cs->buf);
if (unlikely(cs->fd < 0)) if (unlikely(cs->fd < 0))
return -1; return ret;
bufsiz = PAGESIZE; bufsiz = PAGESIZE;
while (!eom) { while (!eom) {
@ -491,8 +485,6 @@ int read_socket_line(connsock_t *cs, int timeout)
tv_timeout.tv_sec = timeout; tv_timeout.tv_sec = timeout;
tv_timeout.tv_usec = 0; tv_timeout.tv_usec = 0;
ret = select(cs->fd + 1, &rd, NULL, NULL, &tv_timeout); ret = select(cs->fd + 1, &rd, NULL, NULL, &tv_timeout);
if (ret < 0 && interrupted())
continue;
if (ret < 1) { if (ret < 1) {
if (!ret) if (!ret)
LOGDEBUG("Select timed out in read_socket_line"); LOGDEBUG("Select timed out in read_socket_line");
@ -545,8 +537,6 @@ void empty_socket(int fd)
FD_ZERO(&rd); FD_ZERO(&rd);
FD_SET(fd, &rd); FD_SET(fd, &rd);
ret = select(fd + 1, &rd, NULL, NULL, &timeout); ret = select(fd + 1, &rd, NULL, NULL, &timeout);
if (ret < 0 && interrupted())
continue;
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;

Loading…
Cancel
Save