Browse Source

Use non blocking reads in read_socket_line

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

35
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');
} }
ret = wait_read_select(fd, timeout);
if (ret < 1) {
if (!ret)
LOGDEBUG("Select timed out in read_socket_line");
else {
if (cs->ckp->proxy)
LOGINFO("Select failed in read_socket_line");
else
LOGERR("Select failed in read_socket_line");
}
goto out;
}
while (42) { while (42) {
char readbuf[PAGESIZE] = {}; char readbuf[PAGESIZE] = {};
int backoff = 1; int backoff = 1;
char *newbuf; char *newbuf;
ret = wait_read_select(fd, eom ? 0 : timeout); ret = recv(fd, readbuf, PAGESIZE - 4, MSG_DONTWAIT);
if (ret < 1) {
if (eom)
break;
if (!ret)
LOGDEBUG("Select timed out in read_socket_line");
else {
if (cs->ckp->proxy)
LOGNOTICE("Select failed in read_socket_line");
else
LOGERR("Select failed in read_socket_line");
}
goto out;
}
ret = recv(fd, readbuf, PAGESIZE - 4, 0);
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