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