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

Function setProtocolError

src/networking.cpp:2274–2301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2272 * CLIENT_PROTOCOL_ERROR. */
2273#define PROTO_DUMP_LEN 128
2274static void setProtocolError(const char *errstr, client *c) {
2275 if (cserver.verbosity <= LL_VERBOSE || c->flags & CLIENT_MASTER) {
2276 sds client = catClientInfoString(sdsempty(),c);
2277
2278 /* Sample some protocol to given an idea about what was inside. */
2279 char buf[256];
2280 if (sdslen(c->querybuf)-c->qb_pos < PROTO_DUMP_LEN) {
2281 snprintf(buf,sizeof(buf),"Query buffer during protocol error: '%s'", c->querybuf+c->qb_pos);
2282 } else {
2283 snprintf(buf,sizeof(buf),"Query buffer during protocol error: '%.*s' (... more %zu bytes ...) '%.*s'", PROTO_DUMP_LEN/2, c->querybuf+c->qb_pos, sdslen(c->querybuf)-c->qb_pos-PROTO_DUMP_LEN, PROTO_DUMP_LEN/2, c->querybuf+sdslen(c->querybuf)-PROTO_DUMP_LEN/2);
2284 }
2285
2286 /* Remove non printable chars. */
2287 char *p = buf;
2288 while (*p != '\0') {
2289 if (!isprint(*p)) *p = '.';
2290 p++;
2291 }
2292
2293 /* Log all the client and protocol info. */
2294 int loglevel = (c->flags & CLIENT_MASTER) ? LL_WARNING :
2295 LL_VERBOSE;
2296 serverLog(loglevel,
2297 "Protocol error (%s) from client: %s. %s", errstr, client, buf);
2298 sdsfree(client);
2299 }
2300 c->flags |= (CLIENT_CLOSE_AFTER_REPLY|CLIENT_PROTOCOL_ERROR);
2301}
2302
2303/* Process the query buffer for client 'c', setting up the client argument
2304 * vector for command execution. Returns C_OK if after running the function

Callers 2

processInlineBufferFunction · 0.85
processMultibulkBufferFunction · 0.85

Calls 5

catClientInfoStringFunction · 0.85
sdsemptyFunction · 0.85
sdslenFunction · 0.85
serverLogFunction · 0.85
sdsfreeFunction · 0.85

Tested by

no test coverage detected