From 6c0c7dd7c43df51f50591845c42d8e0cd8c544b6 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 25 Apr 2015 09:51:12 +1000 Subject: [PATCH] Rework parse_client_msg to use the non blocking recv return values avoiding the need for an extra wait_read_select --- src/connector.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/connector.c b/src/connector.c index b74e53fe..65c77bd6 100644 --- a/src/connector.c +++ b/src/connector.c @@ -343,21 +343,13 @@ static void parse_client_msg(cdata_t *cdata, client_instance_t *client) json_t *val; retry: - ret = wait_read_select(client->fd, 0); - if (ret < 1) { - if (!ret) - return; - LOGINFO("Client fd %d disconnected - select fail with bufofs %d ret %d errno %d %s", - client->fd, client->bufofs, ret, errno, ret && errno ? strerror(errno) : ""); - invalidate_client(ckp, cdata, client); - return; - } buflen = PAGESIZE - client->bufofs; ret = recv(client->fd, client->buf + client->bufofs, buflen, MSG_DONTWAIT); if (ret < 1) { - /* We should have something to read if called since poll set - * this fd's revents status so if there's nothing it means the - * client has disconnected. */ + if (!ret) + return; + if (errno == EAGAIN || errno == EWOULDBLOCK) + return; LOGINFO("Client fd %d disconnected - recv fail with bufofs %d ret %d errno %d %s", client->fd, client->bufofs, ret, errno, ret && errno ? strerror(errno) : ""); invalidate_client(ckp, cdata, client);