MCPcopy Create free account
hub / github.com/F-Stack/f-stack / writeHandler

Function writeHandler

app/redis-6.2.6/src/redis-benchmark.c:610–654  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

608}
609
610static void writeHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
611 client c = privdata;
612 UNUSED(el);
613 UNUSED(fd);
614 UNUSED(mask);
615
616 /* Initialize request when nothing was written. */
617 if (c->written == 0) {
618 /* Enforce upper bound to number of requests. */
619 int requests_issued = 0;
620 atomicGetIncr(config.requests_issued, requests_issued, config.pipeline);
621 if (requests_issued >= config.requests) {
622 return;
623 }
624
625 /* Really initialize: randomize keys and set start time. */
626 if (config.randomkeys) randomizeClientKey(c);
627 if (config.cluster_mode && c->staglen > 0) setClusterKeyHashTag(c);
628 atomicGet(config.slots_last_update, c->slots_last_update);
629 c->start = ustime();
630 c->latency = -1;
631 }
632 const ssize_t buflen = sdslen(c->obuf);
633 const ssize_t writeLen = buflen-c->written;
634 if (writeLen > 0) {
635 void *ptr = c->obuf+c->written;
636 while(1) {
637 /* Optimistically try to write before checking if the file descriptor
638 * is actually writable. At worst we get EAGAIN. */
639 const ssize_t nwritten = cliWriteConn(c->context,ptr,writeLen);
640 if (nwritten != writeLen) {
641 if (nwritten == -1 && errno != EAGAIN) {
642 if (errno != EPIPE)
643 fprintf(stderr, "Error writing to the server: %s\n", strerror(errno));
644 freeClient(c);
645 return;
646 }
647 } else {
648 aeDeleteFileEvent(el,c->context->fd,AE_WRITABLE);
649 aeCreateFileEvent(el,c->context->fd,AE_READABLE,readHandler,c);
650 return;
651 }
652 }
653 }
654}
655
656/* Create a benchmark client, configured to send the command passed as 'cmd' of
657 * 'len' bytes.

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected