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

Function createClient

src/networking.cpp:124–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124client *createClient(connection *conn, int iel) {
125 client *c = new client;
126 serverAssert(conn == nullptr || (iel == (serverTL - g_pserver->rgthreadvar)));
127
128 c->iel = iel;
129 /* passing NULL as conn it is possible to create a non connected client.
130 * This is useful since all the commands needs to be executed
131 * in the context of a client. When commands are executed in other
132 * contexts (for instance a Lua script) we need a non connected client. */
133 if (conn) {
134 serverAssert(iel == (serverTL - g_pserver->rgthreadvar));
135 connNonBlock(conn);
136 connEnableTcpNoDelay(conn);
137 if (cserver.tcpkeepalive)
138 connKeepAlive(conn,cserver.tcpkeepalive);
139 connSetReadHandler(conn, readQueryFromClient, true);
140 connSetPrivateData(conn, c);
141 }
142
143 selectDb(c,0);
144 uint64_t client_id;
145 client_id = g_pserver->next_client_id.fetch_add(1);
146 c->iel = iel;
147 c->id = client_id;
148 snprintf(c->lock.szName, sizeof(c->lock.szName), "client %" PRIu64, client_id);
149 c->resp = 2;
150 c->conn = conn;
151 c->name = NULL;
152 c->bufpos = 0;
153 c->qb_pos = 0;
154 c->querybuf = sdsempty();
155 c->pending_querybuf = sdsempty();
156 c->querybuf_peak = 0;
157 c->reqtype = 0;
158 c->argc = 0;
159 c->argv = NULL;
160 c->original_argc = 0;
161 c->original_argv = NULL;
162 c->cmd = c->lastcmd = NULL;
163 c->multibulklen = 0;
164 c->bulklen = -1;
165 c->sentlen = 0;
166 c->flags = 0;
167 c->fPendingAsyncWrite = FALSE;
168 c->fPendingAsyncWriteHandler = FALSE;
169 c->ctime = c->lastinteraction = g_pserver->unixtime;
170 /* If the default user does not require authentication, the user is
171 * directly authenticated. */
172 clientSetDefaultAuth(c);
173 c->replstate = REPL_STATE_NONE;
174 c->repl_put_online_on_ack = 0;
175 c->reploff = 0;
176 c->read_reploff = 0;
177 c->reploff_cmd = 0;
178 c->repl_ack_off = 0;
179 c->repl_ack_time = 0;
180 c->repl_down_since = 0;
181 c->repl_last_partial_write = 0;

Callers 12

replicaReplayCommandFunction · 0.70
RM_CallFunction · 0.70
moduleBlockClientFunction · 0.70
RM_GetThreadSafeContextFunction · 0.70
moduleFireServerEventFunction · 0.70
executeCronJobExpireHookFunction · 0.70
acceptCommonHandlerFunction · 0.70
scriptingInitFunction · 0.70

Calls 12

connNonBlockFunction · 0.85
connEnableTcpNoDelayFunction · 0.85
connKeepAliveFunction · 0.85
connSetReadHandlerFunction · 0.85
connSetPrivateDataFunction · 0.85
selectDbFunction · 0.85
sdsemptyFunction · 0.85
clientSetDefaultAuthFunction · 0.85
listCreateFunction · 0.85
linkClientFunction · 0.85
initClientMultiStateFunction · 0.85
dictCreateFunction · 0.70

Tested by

no test coverage detected