# HG changeset patch # User Tero Marttila # Date 1219821218 -10800 # Node ID 9cecd22e643aad328334bf3de954d14f44793807 # Parent 0e21a65074a694905fbff8aebcf9f78eb64258a1 *queuing, and add missing file diff -r 0e21a65074a6 -r 9cecd22e643a memcache/request.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memcache/request.c Wed Aug 27 10:13:38 2008 +0300 @@ -0,0 +1,67 @@ + +#include +#include + +#include "request.h" +#include "memcache.h" +#include "../common.h" + +struct memcache_req *memcache_req_alloc (struct memcache *mc, struct memcache_key *key, void *cb_arg) { + struct memcache_req *req = NULL; + + // allocate it + if ((req = calloc(1, sizeof(*req))) == NULL) + ERROR("calloc"); + + // state + req->state = STATE_INVALID; + + // copy the key + if ((req->key.buf = malloc(key->len)) == NULL) + ERROR("malloc key buf"); + + // copy over the key + memcpy(req->key.buf, key->buf, key->len); + req->key.len = key->len; + + // store the mc + callback argument + req->mc = mc; + req->cb_arg = cb_arg; + + // success + return req; + +error: + if (req) { + free(req->key.buf); + free(req); + } + + return NULL; +} + +static int _memcache_req_notify (struct memcache_req *req) { + return req->mc->cb_fn(req, req->cb_arg); +} + +void memcache_req_error (struct memcache_req *req) { + // forget our connection + req->conn = NULL; + + // enter ERROR state + req->state = STATE_ERROR; + + // notify + if (_memcache_req_notify(req)) + WARNING("req error callback failed, ignoring"); +} + +void memcache_req_free (struct memcache_req *req) { + // must be unused + assert(req->conn == NULL); + assert(req->state == STATE_INVALID || req->state == STATE_ERROR); + + free(req->key.buf); + free(req); +} +