| 122 | } |
| 123 | |
| 124 | client *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; |
no test coverage detected