memcache/command.c
changeset 43 e5b714190dee
parent 42 0e503189af2f
child 46 8a832c0e01ee
--- a/memcache/command.c	Wed Aug 27 22:42:27 2008 +0300
+++ b/memcache/command.c	Thu Aug 28 00:29:39 2008 +0300
@@ -92,7 +92,7 @@
         case MEMCACHE_CMD_STORE_PREPEND:
             assert(key != NULL && obj != NULL);
             assert(key->len > 0 && key->buf != NULL);
-            assert(obj->bytes > 0);
+            // XXX: ensure that we have a valid buf
 
             if (evbuffer_add_printf(buf, "%s %*s %u %lu %zu\r\n", cmd_name, (int) key->len, key->buf, obj->flags, obj->exptime, obj->bytes))
                 ERROR("evbuffer_add_printf");
@@ -117,32 +117,33 @@
     size_t line_length, buf_size;
     char *line = NULL, *token_cursor, *token, *invalid;
     int i;
-
-    // take note of how long the buffer is
-    buf_size = evbuffer_get_length(buf);
+   
+    // read lines until we find one that isn't empty
+    do {
+        // take note of how long the buffer is
+        buf_size = evbuffer_get_length(buf);
 
-    // first, try and read a full line
-    if ((line = evbuffer_readln(buf, &line_length, EVBUFFER_EOL_CRLF_STRICT)) == NULL) {
-        // check if any data was consumed
-        if (evbuffer_get_length(buf) != buf_size) {
-            // faaaail!
-            return -1;
+        // free the prvious line in case it was empty
+        free(line);
 
-        } else {
-            // no complete line found
-            return 0;
+        // try and read a line
+        if ((line = evbuffer_readln(buf, &line_length, EVBUFFER_EOL_CRLF_STRICT)) == NULL) {
+            // check if any data was consumed
+            if (evbuffer_get_length(buf) != buf_size) {
+                // faaaail!
+                return -1;
+
+            } else {
+                // no complete line found
+                return 0;
+            }
         }
-    }
+
+    } while (line_length == 0);
     
     // just check to make sure that it really is null-delimited
     assert(line[line_length - 1] == '\0');
 
-    // empty lines?
-    if (line_length == 0) {
-        PWARNING("empty reply line !?!");
-        return 0;
-    }
-
     // use strsep
     token_cursor = line;