Browse Source

Use non blocking reads in read_socket_line

master
Con Kolivas 10 years ago
parent
commit
11023ecfec
  1. 25
      src/ckpool.c

25
src/ckpool.c

@ -530,35 +530,34 @@ int read_socket_line(connsock_t *cs, const int timeout)
eom = strchr(cs->buf, '\n'); eom = strchr(cs->buf, '\n');
} }
while (42) { ret = wait_read_select(fd, timeout);
char readbuf[PAGESIZE] = {};
int backoff = 1;
char *newbuf;
ret = wait_read_select(fd, eom ? 0 : timeout);
if (ret < 1) { if (ret < 1) {
if (eom)
break;
if (!ret) if (!ret)
LOGDEBUG("Select timed out in read_socket_line"); LOGDEBUG("Select timed out in read_socket_line");
else { else {
if (cs->ckp->proxy) if (cs->ckp->proxy)
LOGNOTICE("Select failed in read_socket_line"); LOGINFO("Select failed in read_socket_line");
else else
LOGERR("Select failed in read_socket_line"); LOGERR("Select failed in read_socket_line");
} }
goto out; goto out;
} }
ret = recv(fd, readbuf, PAGESIZE - 4, 0); while (42) {
char readbuf[PAGESIZE] = {};
int backoff = 1;
char *newbuf;
ret = recv(fd, readbuf, PAGESIZE - 4, MSG_DONTWAIT);
if (ret < 1) { if (ret < 1) {
/* Closed socket after valid message */ /* Closed socket after valid message */
if (eom) if (eom || !ret || errno == EAGAIN || errno == EWOULDBLOCK) {
ret = 0;
break; break;
}
if (cs->ckp->proxy) if (cs->ckp->proxy)
LOGNOTICE("Failed to recv in read_socket_line"); LOGINFO("Failed to recv in read_socket_line");
else else
LOGERR("Failed to recv in read_socket_line"); LOGERR("Failed to recv in read_socket_line");
ret = -1;
goto out; goto out;
} }
buflen = cs->bufofs + ret + 1; buflen = cs->bufofs + ret + 1;

Loading…
Cancel
Save