diff --git a/src/networking.c b/src/networking.c index 4f6441de0..150ca4d84 100644 --- a/src/networking.c +++ b/src/networking.c @@ -900,6 +900,34 @@ void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) { } } +/* This function is called just before entering the event loop, in the hope + * we can just write the replies to the client output buffer without any + * need to use a syscall in order to install the writable event handler, + * get it called, and so forth. */ +void handleClientsWithPendingWrites(void) { + listIter li; + listNode *ln; + + listRewind(server.clients_pending_write,&li); + while((ln = listNext(&li))) { + client *c = listNodeValue(ln); + c->flags &= ~CLIENT_PENDING_WRITE; + listDelNode(server.clients_pending_write,ln); + + /* Try to write buffers to the client socket. */ + sendReplyToClient(server.el,c->fd,c,0); + + /* If there is nothing left, do nothing. Otherwise install + * the write handler. */ + if ((c->bufpos || listLength(c->reply)) && + aeCreateFileEvent(server.el, c->fd, AE_WRITABLE, + sendReplyToClient, c) == AE_ERR) + { + freeClientAsync(c); + } + } +} + /* resetClient prepare the client to process the next command */ void resetClient(client *c) { redisCommandProc *prevcmd = c->cmd ? c->cmd->proc : NULL; diff --git a/src/server.c b/src/server.c index 316eba496..9125ccfa8 100644 --- a/src/server.c +++ b/src/server.c @@ -1274,34 +1274,6 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { return 1000/server.hz; } -/* This function is called just before entering the event loop, in the hope - * we can just write the replies to the client output buffer without any - * need to use a syscall in order to install the writable event handler, - * get it called, and so forth. */ -void handleClientsWithPendingWrites(void) { - listIter li; - listNode *ln; - - listRewind(server.clients_pending_write,&li); - while((ln = listNext(&li))) { - client *c = listNodeValue(ln); - c->flags &= ~CLIENT_PENDING_WRITE; - listDelNode(server.clients_pending_write,ln); - - /* Try to write buffers to the client socket. */ - sendReplyToClient(server.el,c->fd,c,0); - - /* If there is nothing left, do nothing. Otherwise install - * the write handler. */ - if ((c->bufpos || listLength(c->reply)) && - aeCreateFileEvent(server.el, c->fd, AE_WRITABLE, - sendReplyToClient, c) == AE_ERR) - { - freeClientAsync(c); - } - } -} - /* This function gets called every time Redis is entering the * main loop of the event driven library, that is, before to sleep * for ready file descriptors. */ diff --git a/src/server.h b/src/server.h index 998112893..fdcc45c2b 100644 --- a/src/server.h +++ b/src/server.h @@ -1110,6 +1110,7 @@ int listenToPort(int port, int *fds, int *count); void pauseClients(mstime_t duration); int clientsArePaused(void); int processEventsWhileBlocked(void); +void handleClientsWithPendingWrites(void); #ifdef __GNUC__ void addReplyErrorFormat(client *c, const char *fmt, ...)