memcache/request.c
changeset 43 e5b714190dee
parent 42 0e503189af2f
child 44 03a7e064f833
--- a/memcache/request.c	Wed Aug 27 22:42:27 2008 +0300
+++ b/memcache/request.c	Thu Aug 28 00:29:39 2008 +0300
@@ -45,15 +45,6 @@
     req->mc->cb_fn(req, req->cb_arg);
 }
 
-void memcache_req_error (struct memcache_req *req) {
-    // forget our connection
-    req->conn = NULL;
-
-    req->state = MEMCACHE_STATE_ERROR;
-
-    _memcache_req_notify(req);
-}
-
 void memcache_req_queued (struct memcache_req *req) {
     req->state = MEMCACHE_STATE_QUEUED;
 
@@ -73,21 +64,41 @@
     _memcache_req_notify(req);
 }
 
+void memcache_req_data (struct memcache_req *req) {
+    assert(req->state == MEMCACHE_STATE_REPLY || req->state == MEMCACHE_STATE_REPLY_DATA);
+
+    req->state = MEMCACHE_STATE_REPLY_DATA;
+    
+    _memcache_req_notify(req);
+}
+
 void memcache_req_done (struct memcache_req *req) {
-    // make sure we are in the STATE_SEND state
-    assert(req->state == MEMCACHE_STATE_SEND);
+    // make sure we are in the REPLY/REPLY_DATA state
+    assert(req->state == MEMCACHE_STATE_REPLY || req->state == MEMCACHE_STATE_REPLY_DATA);
+
+    // make sure we really have the full data, if applicable
+    assert(req->buf.data == NULL || req->buf.offset == req->buf.len);
 
     // forget the connection
     req->conn = NULL;
+    
+    // state depends on if we have data or not...
+    req->state = req->buf.data ? MEMCACHE_STATE_DATA_DONE : MEMCACHE_STATE_DONE;
+}
 
-    // our state is currently indeterminate until req_reply is called
-    req->state = MEMCACHE_STATE_INVALID;
+void memcache_req_error (struct memcache_req *req) {
+    // forget our connection
+    req->conn = NULL;
+
+    req->state = MEMCACHE_STATE_ERROR;
+
+    _memcache_req_notify(req);
 }
 
 void memcache_req_free (struct memcache_req *req) {
     // must be unused
     assert(req->conn == NULL);
-    assert(req->state == MEMCACHE_STATE_INVALID || req->state == MEMCACHE_STATE_ERROR);
+    assert(req->state == MEMCACHE_STATE_INVALID || req->state == MEMCACHE_STATE_ERROR || req->state == MEMCACHE_STATE_DONE || req->state == MEMCACHE_STATE_DATA_DONE);
 
     free(req->key.buf);
     free(req);