Skip to content
This repository
Browse code

Merge branch '2.2' of github.com:antirez/redis into 2.2

  • Loading branch information...
commit 0b01578d2e278a942a07d965c2f054c097aba28b 2 parents 920c45b + fb90934
Salvatore Sanfilippo authored

Showing 1 changed file with 23 additions and 3 deletions. Show diff stats Hide diff stats

  1. 26  src/networking.c
26  src/networking.c
@@ -60,9 +60,6 @@ redisClient *createClient(int fd) {
60 60
 /* Set the event loop to listen for write events on the client's socket.
61 61
  * Typically gets called every time a reply is built. */
62 62
 int _installWriteEvent(redisClient *c) {
63  
-    /* When CLOSE_AFTER_REPLY is set, no more replies may be added! */
64  
-    redisAssert(!(c->flags & REDIS_CLOSE_AFTER_REPLY));
65  
-
66 63
     if (c->fd <= 0) return REDIS_ERR;
67 64
     if (c->bufpos == 0 && listLength(c->reply) == 0 &&
68 65
         (c->replstate == REDIS_REPL_NONE ||
@@ -88,9 +85,15 @@ robj *dupLastObjectIfNeeded(list *reply) {
88 85
     return listNodeValue(ln);
89 86
 }
90 87
 
  88
+/* -----------------------------------------------------------------------------
  89
+ * Low level functions to add more data to output buffers.
  90
+ * -------------------------------------------------------------------------- */
  91
+
91 92
 int _addReplyToBuffer(redisClient *c, char *s, size_t len) {
92 93
     size_t available = sizeof(c->buf)-c->bufpos;
93 94
 
  95
+    if (c->flags & REDIS_CLOSE_AFTER_REPLY) return REDIS_OK;
  96
+
94 97
     /* If there already are entries in the reply list, we cannot
95 98
      * add anything more to the static buffer. */
96 99
     if (listLength(c->reply) > 0) return REDIS_ERR;
@@ -105,6 +108,9 @@ int _addReplyToBuffer(redisClient *c, char *s, size_t len) {
105 108
 
106 109
 void _addReplyObjectToList(redisClient *c, robj *o) {
107 110
     robj *tail;
  111
+
  112
+    if (c->flags & REDIS_CLOSE_AFTER_REPLY) return;
  113
+
108 114
     if (listLength(c->reply) == 0) {
109 115
         incrRefCount(o);
110 116
         listAddNodeTail(c->reply,o);
@@ -128,6 +134,12 @@ void _addReplyObjectToList(redisClient *c, robj *o) {
128 134
  * needed it will be free'd, otherwise it ends up in a robj. */
129 135
 void _addReplySdsToList(redisClient *c, sds s) {
130 136
     robj *tail;
  137
+
  138
+    if (c->flags & REDIS_CLOSE_AFTER_REPLY) {
  139
+        sdsfree(s);
  140
+        return;
  141
+    }
  142
+
131 143
     if (listLength(c->reply) == 0) {
132 144
         listAddNodeTail(c->reply,createObject(REDIS_STRING,s));
133 145
     } else {
@@ -148,6 +160,9 @@ void _addReplySdsToList(redisClient *c, sds s) {
148 160
 
149 161
 void _addReplyStringToList(redisClient *c, char *s, size_t len) {
150 162
     robj *tail;
  163
+
  164
+    if (c->flags & REDIS_CLOSE_AFTER_REPLY) return;
  165
+
151 166
     if (listLength(c->reply) == 0) {
152 167
         listAddNodeTail(c->reply,createStringObject(s,len));
153 168
     } else {
@@ -165,6 +180,11 @@ void _addReplyStringToList(redisClient *c, char *s, size_t len) {
165 180
     }
166 181
 }
167 182
 
  183
+/* -----------------------------------------------------------------------------
  184
+ * Higher level functions to queue data on the client output buffer.
  185
+ * The following functions are the ones that commands implementations will call.
  186
+ * -------------------------------------------------------------------------- */
  187
+
168 188
 void addReply(redisClient *c, robj *obj) {
169 189
     if (_installWriteEvent(c) != REDIS_OK) return;
170 190
     redisAssert(!server.vm_enabled || obj->storage == REDIS_VM_MEMORY);

0 notes on commit 0b01578

Please sign in to comment.
Something went wrong with that request. Please try again.