zfree(c);
}
+#define GLUEREPLY_UP_TO (1024)
static void glueReplyBuffersIfNeeded(redisClient *c) {
- int totlen = 0;
+ int copylen = 0;
+ char buf[GLUEREPLY_UP_TO];
listNode *ln;
robj *o;
listRewind(c->reply);
while((ln = listYield(c->reply))) {
+ int objlen;
+
o = ln->value;
- totlen += sdslen(o->ptr);
- /* This optimization makes more sense if we don't have to copy
- * too much data */
- if (totlen > 1024) return;
- }
- if (totlen > 0) {
- char buf[1024];
- int copylen = 0;
-
- listRewind(c->reply);
- while((ln = listYield(c->reply))) {
- o = ln->value;
- memcpy(buf+copylen,o->ptr,sdslen(o->ptr));
- copylen += sdslen(o->ptr);
+ objlen = sdslen(o->ptr);
+ if (copylen + objlen <= GLUEREPLY_UP_TO) {
+ memcpy(buf+copylen,o->ptr,objlen);
+ copylen += objlen;
listDelNode(c->reply,ln);
+ } else {
+ if (copylen == 0) return;
+ break;
}
- /* Now the output buffer is empty, add the new single element */
- o = createObject(REDIS_STRING,sdsnewlen(buf,totlen));
- listAddNodeTail(c->reply,o);
}
+ /* Now the output buffer is empty, add the new single element */
+ o = createObject(REDIS_STRING,sdsnewlen(buf,copylen));
+ listAddNodeHead(c->reply,o);
}
static void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
REDIS_NOTUSED(el);
REDIS_NOTUSED(mask);
- if (server.glueoutputbuf && listLength(c->reply) > 1)
- glueReplyBuffersIfNeeded(c);
/* Use writev() if we have enough buffers to send */
-#if 0
- if (listLength(c->reply) > REDIS_WRITEV_THRESHOLD &&
- !(c->flags & REDIS_MASTER))
+ #if 0
+ if (!server.glueoutputbuf &&
+ listLength(c->reply) > REDIS_WRITEV_THRESHOLD &&
+ !(c->flags & REDIS_MASTER))
{
sendReplyToClientWritev(el, fd, privdata, mask);
return;
}
-#endif
+ #endif
while(listLength(c->reply)) {
+ if (server.glueoutputbuf && listLength(c->reply) > 1)
+ glueReplyBuffersIfNeeded(c);
+
o = listNodeValue(listFirst(c->reply));
objlen = sdslen(o->ptr);