#include "adlist.h"
#include "zmalloc.h"
-#define CLIENT_CONNECTING 0
-#define CLIENT_SENDQUERY 1
-#define CLIENT_READREPLY 2
-
#define REDIS_NOTUSED(V) ((void) V)
static struct config {
typedef struct _client {
redisContext *context;
- int state;
sds obuf;
char *randptr[10]; /* needed for MSET against 10 keys */
size_t randlen;
aeDeleteFileEvent(config.el,c->context->fd,AE_READABLE);
aeCreateFileEvent(config.el,c->context->fd,AE_WRITABLE,writeHandler,c);
c->written = 0;
- c->state = CLIENT_SENDQUERY;
- c->start = ustime();
- c->latency = -1;
}
static void randomizeClientKey(client c) {
}
if (config.keepalive) {
resetClient(c);
- if (config.randomkeys) randomizeClientKey(c);
} else {
config.liveclients--;
createMissingClients(c);
REDIS_NOTUSED(fd);
REDIS_NOTUSED(mask);
- if (c->state == CLIENT_CONNECTING) {
- c->state = CLIENT_SENDQUERY;
+ /* When nothing was written yet, randomize keys and set start time. */
+ if (c->written == 0) {
+ if (config.randomkeys) randomizeClientKey(c);
c->start = ustime();
c->latency = -1;
}
+
if (sdslen(c->obuf) > c->written) {
void *ptr = c->obuf+c->written;
int nwritten = write(c->context->fd,ptr,sdslen(c->obuf)-c->written);
if (sdslen(c->obuf) == c->written) {
aeDeleteFileEvent(config.el,c->context->fd,AE_WRITABLE);
aeCreateFileEvent(config.el,c->context->fd,AE_READABLE,readHandler,c);
- c->state = CLIENT_READREPLY;
}
}
}
fprintf(stderr,"%s: %s\n",config.hostsocket,c->context->errstr);
exit(1);
}
- c->state = CLIENT_CONNECTING;
c->obuf = sdsnewlen(cmd,len);
c->randlen = 0;
c->written = 0;
int n = 0;
while(config.liveclients < config.numclients) {
- client new = createClient(c->obuf,sdslen(c->obuf));
- if (config.randomkeys) randomizeClientKey(new);
+ createClient(c->obuf,sdslen(c->obuf));
/* Listen backlog is quite limited on most systems */
if (++n > 64) {