--- a/cache.h Thu Aug 07 20:28:06 2008 +0300
+++ b/cache.h Fri Aug 08 00:15:29 2008 +0300
@@ -1,6 +1,8 @@
#ifndef CACHE_H
#define CACHE_H
+#include <sys/types.h>
+
/*
* The interface to the internal caching mechanism.
*
@@ -29,8 +31,8 @@
* What we use as keys in the cache. Key is a pointer to an arbitrary char buffer, length is the size of the key
* in bytes. If this is given as zero, it will be calcuated using strlen(). Zero-length keys are invalid.
*/
-struct cache_key_t {
- const char *buf;
+struct cache_key {
+ char *buf;
size_t length;
};
@@ -41,9 +43,8 @@
CACHE_STATE_INVALID,
CACHE_STATE_LOOKUP,
-
- CACHE_STATE_OPEN,
-
+ CACHE_STATE_WRITE_BEGIN,
+ CACHE_STATE_READ_BEGIN,
CACHE_STATE_WRITE,
CACHE_STATE_WRITE_PAUSE,
CACHE_STATE_READ,
@@ -53,13 +54,14 @@
};
/*
+/ *
* Transitions between states
- */
+ * /
enum cache_req_event {
// LOOKUP -> OPEN
CACHE_EVENT_HIT,
CACHE_EVENT_MISS,
-
+
// OPEN -> WRITE
CACHE_EVENT_BEGIN_WRITE,
@@ -81,11 +83,13 @@
// * -> ERROR
CACHE_EVENT_ERROR,
};
+*/
/*
* The callback used for cache_reqs
*/
-typedef (int) (*cache_callback) (struct cache_req *, enum cache_req_event, void *arg);
+//typedef int (*cache_callback) (struct cache_req *, enum cache_req_event, void *arg);
+typedef int (*cache_callback) (struct cache_req *, void *arg);
@@ -101,12 +105,17 @@
* Create a new request. The given callback function will be called at the various stages in the request, and can then
* drive the request forward.
*/
-struct cache_req *cache_request (struct cache *cache, struct cache_key *key, cache_callback cb_func, void *cb_data);
+struct cache_req *cache_req (struct cache *cache, const struct cache_key *key, cache_callback cb_func, void *cb_data);
/*
* Get the request's state.
*/
-enum cache_req_state cache_request_state (struct cache_req *req);
+enum cache_req_state cache_req_state (struct cache_req *req);
+
+/*
+ * Get the rquest's key
+ */
+const struct cache_key *cache_req_key (struct cache_req *req);
/*
* Get information about the amount of data in this cache entry.
@@ -117,6 +126,11 @@
void cache_req_available (struct cache_req *req, ssize_t *size, ssize_t *offset, ssize_t *available);
/*
+ * Prepare this cache req for writing in the data. Hint, if nonzero, is used to pre-allocate resources for the entry.
+ */
+int cache_req_begin_write(struct cache_req *req, size_t hint);
+
+/*
* Add some data into this cache entry, reading from the given fd. This is only valid for cache_req's in
* CACHE_REQ_WRITE mode.
*