From 883d870060217449fc8b9f2dcb19a11f23f32195 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 27 Apr 2015 17:34:38 +1000 Subject: [PATCH] Use the simpler read/write calls and make all client sockets non-blocking --- src/connector.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/connector.c b/src/connector.c index 2ac6bb40..fc4637b3 100644 --- a/src/connector.c +++ b/src/connector.c @@ -224,6 +224,7 @@ static int accept_client(cdata_t *cdata, const int epfd, const uint64_t server) } keep_sockalive(fd); + noblock_socket(fd); LOGINFO("Connected new client %d on socket %d to %d active clients from %s:%d", cdata->nfds, fd, no_clients, client->address_name, port); @@ -352,7 +353,8 @@ static void parse_client_msg(cdata_t *cdata, client_instance_t *client) retry: buflen = PAGESIZE - client->bufofs; - ret = recv(client->fd, client->buf + client->bufofs, buflen, MSG_DONTWAIT); + /* This read call is non-blocking since the socket is set to O_NOBLOCK */ + ret = read(client->fd, client->buf + client->bufofs, buflen); if (ret < 1) { if (!ret) return; @@ -569,7 +571,7 @@ static bool send_sender_send(ckpool_t *ckp, cdata_t *cdata, sender_send_t *sende return true; while (sender_send->len) { - int ret = send(client->fd, sender_send->buf + sender_send->ofs, sender_send->len , MSG_DONTWAIT); + int ret = write(client->fd, sender_send->buf + sender_send->ofs, sender_send->len); if (unlikely(ret < 1)) { if (!ret) @@ -593,8 +595,9 @@ static void clear_sender_send(sender_send_t *sender_send, cdata_t *cdata) free(sender_send); } -/* Use a thread to send queued messages, using select() to only send to sockets - * ready for writing immediately to not delay other messages. */ +/* Use a thread to send queued messages, appending them to the sends list and + * iterating over all of them, attempting to send them all non-blocking to + * only send to those clients ready to receive data. */ static void *sender(void *arg) { cdata_t *cdata = (cdata_t *)arg;