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

Function processInputBuffer

src/networking.cpp:2637–2682  ·  view source on GitHub ↗

This function is called every time, in the client structure 'c', there is * more query buffer to process, because we read more data from the socket * or because a client was blocked and later reactivated, so there could be * pending query buffer, already representing a full command, to process. */

Source from the content-addressed store, hash-verified

2635 * or because a client was blocked and later reactivated, so there could be
2636 * pending query buffer, already representing a full command, to process. */
2637void processInputBuffer(client *c, bool fParse, int callFlags) {
2638 AssertCorrectThread(c);
2639
2640 if (fParse)
2641 parseClientCommandBuffer(c);
2642
2643 /* Keep processing while there is something in the input buffer */
2644 while (!c->vecqueuedcmd.empty()) {
2645 /* Return if we're still parsing this command */
2646 auto &cmd = c->vecqueuedcmd.front();
2647 if (cmd.argc != cmd.argcMax) break;
2648 if (c->flags & CLIENT_EXECUTING_COMMAND) break;
2649
2650 if (!FClientReady(c)) break;
2651
2652 if ((callFlags & CMD_CALL_ASYNC) && !FAsyncCommand(cmd))
2653 break;
2654
2655 zfree(c->argv);
2656 c->argc = cmd.argc;
2657 c->argv = cmd.argv;
2658 cmd.argv = nullptr;
2659 c->argv_len_sumActive = cmd.argv_len_sum;
2660 cmd.argv_len_sum = 0;
2661 c->reploff_cmd = cmd.reploff;
2662 serverAssert(c->argv != nullptr);
2663
2664 c->vecqueuedcmd.erase(c->vecqueuedcmd.begin());
2665
2666 /* Multibulk processing could see a <= 0 length. */
2667 if (c->argc == 0) {
2668 resetClient(c);
2669 } else {
2670 c->flags |= CLIENT_EXECUTING_COMMAND;
2671 /* We are finally ready to execute the command. */
2672 if (processCommandAndResetClient(c, callFlags) == C_ERR) {
2673 /* If the client is no longer valid, we avoid exiting this
2674 * loop and trimming the client buffer later. So we return
2675 * ASAP in that case. */
2676 c->flags &= ~CLIENT_EXECUTING_COMMAND;
2677 return;
2678 }
2679 c->flags &= ~CLIENT_EXECUTING_COMMAND;
2680 }
2681 }
2682}
2683
2684void readQueryFromClient(connection *conn) {
2685 client *c = (client*)connGetPrivateData(conn);

Callers 4

replicaReplayCommandFunction · 0.85
processUnblockedClientsFunction · 0.85
readQueryFromClientFunction · 0.85
processClientsFunction · 0.85

Calls 9

parseClientCommandBufferFunction · 0.85
FClientReadyFunction · 0.85
FAsyncCommandFunction · 0.85
zfreeFunction · 0.85
resetClientFunction · 0.70
emptyMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected