MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / clientInstallWriteHandler

Function clientInstallWriteHandler

src/networking.cpp:242–263  ·  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

240 * If we fail and there is more data to write, compared to what the socket
241 * buffers can hold, then we'll really install the handler. */
242void clientInstallWriteHandler(client *c) {
243 /* Schedule the client to write the output buffers to the socket only
244 * if not already done and, for slaves, if the replica can actually receive
245 * writes at this stage. */
246
247 if (!(c->flags & CLIENT_PENDING_WRITE) &&
248 (c->replstate == REPL_STATE_NONE || c->replstate == SLAVE_STATE_FASTSYNC_TX || c->replstate == SLAVE_STATE_FASTSYNC_DONE ||
249 (c->replstate == SLAVE_STATE_ONLINE && !c->repl_put_online_on_ack)))
250 {
251 AssertCorrectThread(c);
252 serverAssert(c->lock.fOwnLock());
253 /* Here instead of installing the write handler, we just flag the
254 * client and put it into a list of clients that have something
255 * to write to the socket. This way before re-entering the event
256 * loop, we can try to directly write to the client sockets avoiding
257 * a system call. We'll only really install the write handler if
258 * we'll not be able to write the whole reply at once. */
259 c->flags |= CLIENT_PENDING_WRITE;
260 std::unique_lock<fastlock> lockf(g_pserver->rgthreadvar[c->iel].lockPendingWrite);
261 g_pserver->rgthreadvar[c->iel].clients_pending_write.push_back(c);
262 }
263}
264
265void clientInstallAsyncWriteHandler(client *c) {
266 serverAssert(GlobalLocksAcquired());

Callers 3

prepareClientToWriteFunction · 0.85
unprotectClientFunction · 0.85

Calls 1

fOwnLockMethod · 0.45

Tested by

no test coverage detected