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

Function writeHandler

src/keydb-diagnostic-tool.cpp:404–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

402}
403
404static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
405 client c = (client)privdata;
406 UNUSED(el);
407 UNUSED(fd);
408 UNUSED(mask);
409
410 /* Initialize request when nothing was written. */
411 if (c->written == 0) {
412 /* Really initialize: randomize keys and set start time. */
413 if (config.randomkeys) randomizeClientKey(c);
414 atomicGet(config.slots_last_update, c->slots_last_update);
415 c->start = ustime();
416 c->latency = -1;
417 }
418 if (sdslen(c->obuf) > c->written) {
419 void *ptr = c->obuf+c->written;
420 ssize_t nwritten = write(c->context->fd,ptr,sdslen(c->obuf)-c->written);
421 if (nwritten == -1) {
422 if (errno != EPIPE)
423 fprintf(stderr, "Writing to socket: %s\n", strerror(errno));
424 freeClient(c);
425 return;
426 }
427 c->written += nwritten;
428 if (sdslen(c->obuf) == c->written) {
429 aeDeleteFileEvent(el,c->context->fd,AE_WRITABLE);
430 aeCreateFileEvent(el,c->context->fd,AE_READABLE,readHandler,c);
431 }
432 }
433}
434
435/* Create a benchmark client, configured to send the command passed as 'cmd' of
436 * 'len' bytes.

Callers

nothing calls this directly

Calls 6

sdslenFunction · 0.85
aeDeleteFileEventFunction · 0.85
aeCreateFileEventFunction · 0.85
randomizeClientKeyFunction · 0.70
ustimeFunction · 0.70
freeClientFunction · 0.70

Tested by

no test coverage detected