Move handleClientsWithPendingWrites() in networking.c.

This commit is contained in:
antirez
2015-09-28 19:06:36 +02:00
parent 1c7d87df0c
commit 481a0db315
3 changed files with 29 additions and 28 deletions

View File

@ -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;