memcache.h
author Tero Marttila <terom@fixme.fi>
Wed, 27 Aug 2008 21:30:32 +0300
changeset 41 540737bf6bac
parent 39 0e21a65074a6
child 42 0e503189af2f
permissions -rw-r--r--
sending requests, and partial support for receiving -- incomplete, not tested
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef MEMCACHE_H
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define MEMCACHE_H
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
 * A libevent based memcached client that aims for high performance, concurrency and low latency.
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
#include "config.h"
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
 * Used to store the global information for a memcache context. A context contains both servers and active connections.
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
struct memcache;
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
 * A transaction.
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
struct memcache_req;
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
 * Keys used
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
struct memcache_key {
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    24
    char *buf;
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
    size_t len;
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
};
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
 * Object attributes
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
struct memcache_obj {
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
    unsigned int flags;
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
    time_t exptime;
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
    size_t bytes;
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
    unsigned long long cas;
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    36
};
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
/*
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    39
 * Object data
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    40
 */
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    41
struct memcache_buf {
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    42
    char *data;
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    43
    size_t len;
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    44
    size_t offset;
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    45
};
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    46
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    47
/*
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
 * Available commands
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
enum memcache_command {
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    51
    MEMCACHE_CMD_INVALID,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    52
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    53
    MEMCACHE_CMD_FETCH_GET,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    54
    MEMCACHE_CMD_STORE_SET,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    55
    MEMCACHE_CMD_STORE_ADD,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    56
    MEMCACHE_CMD_STORE_REPLACE,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    57
    MEMCACHE_CMD_STORE_APPEND,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    58
    MEMCACHE_CMD_STORE_PREPEND,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    59
    MEMCACHE_CMD_STORE_CAS,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    60
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    61
    MEMCACHE_CMD_MAX,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    62
};
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    63
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    64
enum memcache_reply {
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    65
    MEMCACHE_RPL_INVALID,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    66
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    67
    MEMCACHE_RPL_ERROR,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    68
    MEMCACHE_RPL_CLIENT_ERROR,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    69
    MEMCACHE_RPL_SERVER_ERROR,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    70
    
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    71
    // MEMCACHE_CMD_FETCH_*
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    72
    MEMCACHE_RPL_VALUE,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    73
    MEMCACHE_RPL_END,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    74
    
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    75
    // MEMCACHE_CMD_STORE_*
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    76
    MEMCACHE_RPL_STORED,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    77
    MEMCACHE_RPL_NOT_STORED,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    78
    MEMCACHE_RPL_EXISTS,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    79
    MEMCACHE_RPL_NOT_FOUND,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    80
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    81
    MEMCACHE_RPL_MAX,
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    82
};
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    83
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    84
enum memcache_req_state {
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    85
    MEMCACHE_STATE_INVALID,
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    86
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    87
    MEMCACHE_STATE_ERROR,
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    88
};
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    89
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    90
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    91
 * Callback used
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    92
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    93
typedef int (*memcache_cb) (struct memcache_req *, void*);
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    94
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    95
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    96
 * Allocate a new memcache context for use with other methods.
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    97
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    98
struct memcache *memcache_alloc (memcache_cb cb_fn);
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    99
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   100
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   101
 * Add a server to the pool of available servers.
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   102
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   103
int memcache_add_server (struct memcache *mc, struct config_endpoint *endpoint, int max_connections);
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   104
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   105
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   106
 * Attempt to fetch a key from the cache.
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   107
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   108
struct memcache_req *memcache_fetch (struct memcache *mc, const struct memcache_key *key, void *cb_arg);
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   109
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   110
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   111
 * Attempt to store a key into the cache
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   112
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   113
struct memcache_req *memcache_store (struct memcache *mc, enum memcache_command cmd, const struct memcache_key *key, const struct memcache_obj *obj, void *cb_arg);
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   114
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   115
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   116
 * Request state
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   117
 */ 
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   118
enum memcache_req_state memcache_req_state (struct memcache_req *req);
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   119
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   120
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   121
 * Request key
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   122
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   123
int memcache_req_key (struct memcache_req *req, const struct memcache_key *key);
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   124
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   125
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   126
 * Request data
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   127
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   128
int memcache_req_obj (struct memcache_req *req, const struct memcache_obj *obj);
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   129
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   130
#endif /* MEMCACHE_H */