MCPcopy Create free account
hub / github.com/F-Stack/f-stack / clientInstallWriteHandler

Function clientInstallWriteHandler

app/redis-6.2.6/src/networking.c:213–230  ·  view source on GitHub ↗

This function puts the client in the queue of clients that should write * their output buffers to the socket. Note that it does not *yet* install * the write handler, to start clients are put in a queue of clients that need * to write, so we try to do that before returning in the event loop (see the * handleClientsWithPendingWrites() function). * If we fail and there is more data to write, co

Source from the content-addressed store, hash-verified

211 * If we fail and there is more data to write, compared to what the socket
212 * buffers can hold, then we'll really install the handler. */
213void clientInstallWriteHandler(client *c) {
214 /* Schedule the client to write the output buffers to the socket only
215 * if not already done and, for slaves, if the slave can actually receive
216 * writes at this stage. */
217 if (!(c->flags & CLIENT_PENDING_WRITE) &&
218 (c->replstate == REPL_STATE_NONE ||
219 (c->replstate == SLAVE_STATE_ONLINE && !c->repl_put_online_on_ack)))
220 {
221 /* Here instead of installing the write handler, we just flag the
222 * client and put it into a list of clients that have something
223 * to write to the socket. This way before re-entering the event
224 * loop, we can try to directly write to the client sockets avoiding
225 * a system call. We'll only really install the write handler if
226 * we'll not be able to write the whole reply at once. */
227 c->flags |= CLIENT_PENDING_WRITE;
228 listAddNodeHead(server.clients_pending_write,c);
229 }
230}
231
232/* This function is called every time we are going to transmit new data
233 * to the client. The behavior is the following:

Callers 3

prepareClientToWriteFunction · 0.85
unprotectClientFunction · 0.85

Calls 1

listAddNodeHeadFunction · 0.85

Tested by

no test coverage detected