--- a/memcache/request.c Thu Aug 28 03:14:07 2008 +0300
+++ b/memcache/request.c Fri Aug 29 23:31:17 2008 +0300
@@ -47,6 +47,7 @@
memcpy(&req->buf, buf, sizeof(req->buf));
req->have_buf = 1;
+ req->is_buf_ours = 0;
// set offset to zero
req->buf.offset = 0;
@@ -70,7 +71,7 @@
}
// accessors
-enum memcache_req_state memcache_req_state (struct memcache_req *req) {
+enum memcache_state memcache_req_state (struct memcache_req *req) {
return req->state;
}
@@ -82,7 +83,7 @@
return req->reply_type;
}
-const struct memcache_key *keymemcache_req_key (struct memcache_req *req) {
+const struct memcache_key *memcache_req_key (struct memcache_req *req) {
return &req->key;
}
@@ -112,7 +113,8 @@
}
void memcache_req_recv (struct memcache_req *req, enum memcache_reply reply_type) {
- req->state = MEMCACHE_STATE_REPLY;
+ // set state to REPLY_DATA/REPLY based on have_buf/is_buf_ours
+ req->state = (req->have_buf && req->is_buf_ours) ? MEMCACHE_STATE_REPLY_DATA : MEMCACHE_STATE_REPLY;
req->reply_type = reply_type;
// we must surely have a valid obj now
@@ -136,21 +138,8 @@
// make sure we are in the REPLY/REPLY_DATA state
assert(req->state == MEMCACHE_STATE_REPLY || req->state == MEMCACHE_STATE_REPLY_DATA);
- // are we supposed to have data?
- if (req->buf.data) {
- // make sure we really have the full data, if applicable
- assert(req->buf.offset == req->buf.len);
-
- // yes...
- req->have_buf = 1;
-
- // have data
- req->state = MEMCACHE_STATE_DATA_DONE;
-
- } else {
- // no data
- req->state = MEMCACHE_STATE_DONE;
- }
+ // set state to DONE_DATA/DONE based on have_buf/is_buf_ours
+ req->state = (req->have_buf && req->is_buf_ours) ? MEMCACHE_STATE_DONE_DATA : MEMCACHE_STATE_DONE;
// forget the connection
req->conn = NULL;
@@ -170,7 +159,10 @@
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 || req->state == MEMCACHE_STATE_DONE || req->state == MEMCACHE_STATE_DATA_DONE);
+ assert(req->state == MEMCACHE_STATE_INVALID || req->state == MEMCACHE_STATE_ERROR || req->state == MEMCACHE_STATE_DONE || req->state == MEMCACHE_STATE_DONE_DATA);
+
+ if (req->have_buf && req->is_buf_ours)
+ free(req->buf.data);
free(req->key.buf);
free(req);