|
|
@ -367,11 +367,11 @@ void empty_buffer(connsock_t *cs) |
|
|
|
* of the buffer for use on the next receive. */ |
|
|
|
* of the buffer for use on the next receive. */ |
|
|
|
int read_socket_line(connsock_t *cs, int timeout) |
|
|
|
int read_socket_line(connsock_t *cs, int timeout) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
int fd = cs->fd, ret = -1; |
|
|
|
char *eom = NULL; |
|
|
|
char *eom = NULL; |
|
|
|
size_t buflen; |
|
|
|
size_t buflen; |
|
|
|
int ret = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(cs->fd < 0)) |
|
|
|
if (unlikely(fd < 0)) |
|
|
|
goto out; |
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(!cs->buf)) |
|
|
|
if (unlikely(!cs->buf)) |
|
|
@ -388,7 +388,7 @@ int read_socket_line(connsock_t *cs, int timeout) |
|
|
|
while (42) { |
|
|
|
while (42) { |
|
|
|
char readbuf[PAGESIZE] = {}; |
|
|
|
char readbuf[PAGESIZE] = {}; |
|
|
|
|
|
|
|
|
|
|
|
ret = wait_read_select(cs->fd, eom ? 0 : timeout); |
|
|
|
ret = wait_read_select(fd, eom ? 0 : timeout); |
|
|
|
if (eom && !ret) |
|
|
|
if (eom && !ret) |
|
|
|
break; |
|
|
|
break; |
|
|
|
if (ret < 1) { |
|
|
|
if (ret < 1) { |
|
|
@ -398,7 +398,7 @@ int read_socket_line(connsock_t *cs, int timeout) |
|
|
|
LOGERR("Select failed in read_socket_line"); |
|
|
|
LOGERR("Select failed in read_socket_line"); |
|
|
|
goto out; |
|
|
|
goto out; |
|
|
|
} |
|
|
|
} |
|
|
|
ret = recv(cs->fd, readbuf, PAGESIZE - 4, 0); |
|
|
|
ret = recv(fd, readbuf, PAGESIZE - 4, 0); |
|
|
|
if (ret < 1) { |
|
|
|
if (ret < 1) { |
|
|
|
LOGERR("Failed to recv in read_socket_line"); |
|
|
|
LOGERR("Failed to recv in read_socket_line"); |
|
|
|
ret = -1; |
|
|
|
ret = -1; |
|
|
@ -423,6 +423,7 @@ int read_socket_line(connsock_t *cs, int timeout) |
|
|
|
*eom = '\0'; |
|
|
|
*eom = '\0'; |
|
|
|
out: |
|
|
|
out: |
|
|
|
if (ret < 0) { |
|
|
|
if (ret < 0) { |
|
|
|
|
|
|
|
empty_buffer(cs); |
|
|
|
dealloc(cs->buf); |
|
|
|
dealloc(cs->buf); |
|
|
|
Close(cs->fd); |
|
|
|
Close(cs->fd); |
|
|
|
} |
|
|
|
} |
|
|
|