memcache.h
author Tero Marttila <terom@fixme.fi>
Thu, 28 Aug 2008 01:42:28 +0300
changeset 45 10d514029c64
parent 44 03a7e064f833
child 46 8a832c0e01ee
permissions -rw-r--r--
documentation tweaks, add req_abort function prototype
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.
45
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
    12
 *
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
    13
 * Each context has one callback function defined, which is used for all requests.
38
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
struct memcache;
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
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
 * A transaction.
45
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
    19
 *
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
    20
 * Each request has one callback argument defined, which is used for that request's callbacks.
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
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
    23
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
/*
45
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
    25
 * Object keys
38
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
struct memcache_key {
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    28
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    29
     * Pointer to a char buffer containing the key itself.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    30
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    31
     * A key is a text tring which should uniquely identify a cache entry.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    32
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    33
     * The length limit for a key is usually 250 characters, but this is imposed by the server side (a longer key will
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    34
     * presumeably cause a CLIENT_ERROR reply).
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    35
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    36
     * The key should presumeably also not contain any spaces, carriage returns or newlines, as these are used to
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    37
     * delimit tokens in the protocol itself.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    38
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    39
     * The buffer does not need to be zero-terminated.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    40
     */
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    41
    char *buf;
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    42
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    43
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    44
     * The length of the key buffer in bytes. This does not include a NUL byte.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    45
     */
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
    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
    47
};
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
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
 * Object attributes
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
struct memcache_obj {
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    53
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    54
     * An arbitrary 16-bit (32-bit for >1.2.1) that the server stores transparently.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    55
     */
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    56
    unsigned int flags;
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    57
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    58
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    59
     * Expiration time. If non-zero, either an offset in seconds from current time (up to 60*60*24*30 seconds, or 30d),
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    60
     * or an absolute 32-bit unix timestamp.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    61
     */
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    62
    time_t exptime;
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    63
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    64
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    65
     * Number of bytes in the entry. This may be zero, in which case there will be no data.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    66
     */
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
    size_t bytes;
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    68
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    69
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    70
     * Used for the CMD_STORE_CAS command. An unique 64-bit value that changes if the entry is modified.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    71
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    72
     * Not needed for other commands, and may or may not be provided by CMD_FETCH_GET (will be set to zero).
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    73
     */
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    74
    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
    75
};
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    76
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    77
/*
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    78
 * Object data
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    79
 */
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    80
struct memcache_buf {
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    81
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    82
     * The char buffer containing the data.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    83
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    84
    char *data;
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    85
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    86
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    87
     * The total length of the char buffer, and thence the cache entry.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    88
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    89
    size_t len;
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    90
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    91
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    92
     * The amount of data currently available in the buffer. This is used to provide streaming fetches.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    93
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    94
     * This field is *IMPORTANT*! Don't disregard it, or you *will* get incomplete data.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    95
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    96
    size_t offset;
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    97
};
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    98
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    99
/*
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   100
 * Available commands
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   101
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   102
enum memcache_command {
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   103
    MEMCACHE_CMD_INVALID,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   104
    
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   105
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   106
     * Retrieve the value of a key from the memcached server. 
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   107
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   108
     * If the key exists, you will get a RPL_VALUE reply followed by a RPL_END reply. 
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   109
     * If it does not exist, you will just get a RPL_END reply.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   110
     */
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   111
    MEMCACHE_CMD_FETCH_GET,
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   112
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   113
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   114
     * Store this data.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   115
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   116
     * Returns either RPL_STORED or RPL_NOT_STORED.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   117
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   118
    MEMCACHE_CMD_STORE_SET,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   119
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   120
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   121
     * Store this data, but only if the server doesn't already hold data for this key.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   122
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   123
     * Returns either RPL_STORED or RPL_NOT_STORED.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   124
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   125
    MEMCACHE_CMD_STORE_ADD,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   126
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   127
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   128
     * Store this data, but only if the server does already hold data for this key.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   129
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   130
     * Returns either RPL_STORED or RPL_NOT_STORED.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   131
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   132
    MEMCACHE_CMD_STORE_REPLACE,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   133
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   134
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   135
     * Add this data to an existing key after existing data.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   136
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   137
     * obj.flags and obj.exptime are ignored.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   138
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   139
     * Returns ???
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   140
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   141
    MEMCACHE_CMD_STORE_APPEND,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   142
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   143
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   144
     * Add this data to an existing key before existing data.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   145
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   146
     * obj.flags and obj.exptime are ignored.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   147
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   148
     * Returns ???
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   149
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   150
    MEMCACHE_CMD_STORE_PREPEND,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   151
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   152
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   153
     * Check and Set - store this data but only if no one else had updated it since I last fetched it.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   154
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   155
     * obj.cas is required.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   156
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   157
     * Returns RPL_STORED, RPL_NOT_STORED, RPL_EXISTS (data has been modified), or RPL_NOT_FOUND (the item does not
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   158
     * exist or has been deleted).
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   159
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   160
    MEMCACHE_CMD_STORE_CAS,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   161
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   162
    MEMCACHE_CMD_MAX,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   163
};
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   164
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   165
/*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   166
 * Replies from the server
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   167
 */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   168
enum memcache_reply {
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   169
    MEMCACHE_RPL_INVALID,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   170
    
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   171
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   172
     * The library sent an unknown command. This probably means the server is not compatible with said command.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   173
     */
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   174
    MEMCACHE_RPL_ERROR,
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   175
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   176
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   177
     * There was an error in the request that the library sent. The error message is printed out via ERROR.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   178
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   179
    MEMCACHE_RPL_CLIENT_ERROR,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   180
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   181
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   182
     * There was an error with the server when processing the request. The error message is printed out via ERROR.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   183
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   184
    MEMCACHE_RPL_SERVER_ERROR,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   185
    
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   186
    // CMD_FETCH_*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   187
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   188
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   189
     * The given key was found in the cache. The obj attributes are now known, and the buf data is on the way.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   190
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   191
    MEMCACHE_RPL_VALUE,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   192
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   193
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   194
     * No more RPL_VALUE replies will be sent. This may be the only reply sent if the key was not found.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   195
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   196
    MEMCACHE_RPL_END,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   197
    
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   198
    // CMD_STORE_*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   199
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   200
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   201
     * The object was succesfully stored in the cache.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   202
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   203
    MEMCACHE_RPL_STORED,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   204
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   205
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   206
     * The object was not stored in the cache.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   207
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   208
     * This could be for a number of reasons, perhaps the object is too large, the cache is full, the key is in the
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   209
     * delete queue, or some condition imposed by the STORE_* command was not met.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   210
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   211
    MEMCACHE_RPL_NOT_STORED,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   212
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   213
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   214
     * The item you were trying to store with a STORE_CAS request has been modified since you last fetched it (i.e.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   215
     * obj.cas does not match).
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   216
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   217
    MEMCACHE_RPL_EXISTS,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   218
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   219
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   220
     * The item you were trying to store with a STORE_CAS request did not exist (or has been deleted).
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   221
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   222
    MEMCACHE_RPL_NOT_FOUND,
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   223
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   224
    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
   225
};
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   226
45
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   227
/*
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   228
 * Request states
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   229
 */
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   230
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
   231
    MEMCACHE_STATE_INVALID,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   232
    
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   233
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   234
     * The request is queued, and has not been sent yet
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   235
     */
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   236
    MEMCACHE_STATE_QUEUED,
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   237
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   238
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   239
     * The request is being sent, and the reply has not yet been received
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   240
     */
42
0e503189af2f more reply-receiving code, but still incomplete
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   241
    MEMCACHE_STATE_SEND,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   242
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   243
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   244
     * The reply has been received.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   245
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   246
     * req_reply and req_obj will return a non-NULL value, but there is no reply data yet.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   247
     */
42
0e503189af2f more reply-receiving code, but still incomplete
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   248
    MEMCACHE_STATE_REPLY,
43
e5b714190dee the request/reply code should be complete now, but still needs testing
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   249
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   250
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   251
     * The reply and part of the reply data has been received.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   252
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   253
     * req_reply, req_obj and req_buf will all return non-NULL values, but buf.offset will be smaller than buf.len.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   254
     */
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   255
    MEMCACHE_STATE_REPLY_DATA,
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   256
    
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   257
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   258
     * The full reply has been received.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   259
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   260
     * req_reply, req_obj will return a non-NULL value, but there is no reply data.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   261
     */
43
e5b714190dee the request/reply code should be complete now, but still needs testing
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   262
    MEMCACHE_STATE_DONE,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   263
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   264
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   265
     * The full reply and reply data has been received.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   266
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   267
     * req_reply, req_obj and req_buf will all return non-NULL values, and buf.offset will be equal to buf.len.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   268
     */
43
e5b714190dee the request/reply code should be complete now, but still needs testing
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
   269
    MEMCACHE_STATE_DATA_DONE,
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   270
    
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   271
    /*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   272
     * An error has occurred.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   273
     *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   274
     * req_reply, req_obj and req_buf may or may not work.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   275
     */
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   276
    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
   277
};
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   278
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   279
/*
45
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   280
 * Callback used.
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   281
 *
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   282
 * This is called whenever the request's state changes, including when new data is received in the STATE_REPLY_DATA
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   283
 * state.
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   284
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   285
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
   286
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   287
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   288
 * Allocate a new memcache context for use with other methods.
45
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   289
 *
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   290
 * The given callback function is used for all requests in this context.
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   291
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   292
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
   293
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   294
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   295
 * Add a server to the pool of available servers.
45
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   296
 *
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   297
 * At most <max_connections> connections will be kept open to this server, and additional requests will be queued.
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   298
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   299
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
   300
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   301
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   302
 * Attempt to fetch a key from the cache.
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   303
 *
45
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   304
 * The given callback argument will be used when invoking the context's callback for this request.
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   305
 *
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   306
 * The state machine will work as follows:
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   307
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   308
 *  req_state                  multi   req_reply
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   309
 *  ---------------------------------------------
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   310
 *  STATE_QUEUE                 ?
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   311
 *  STATE_SEND
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   312
 *  STATE_REPLY                         RPL_VALUE
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   313
 *      STATE_REPLY_DATA        *       RPL_VALUE
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   314
 *      STATE_DATA_DONE                 RPL_END
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   315
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   316
 *      STATE_DONE                      RPL_END
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   317
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   318
 *  STATE_ERROR                         RPL_{ERROR,CLIENT_ERROR,SERVER_ERROR}
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   319
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   320
 * The item attributes/data can be accessed via req_obj/req_buf as described in `enum memcache_state`.
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   321
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   322
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
   323
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   324
/*
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   325
 * Attempt to store an item into the cache.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   326
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   327
 * The cmd argument can be used to specify what CMD_STORE_* command to use.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   328
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   329
 * The given memcache_key is copied, including the char array pointed to by buf.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   330
 * Both obj and buf are also copied, but buf.data will not be copied - the pointer must remain valid until the request is done.
45
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   331
 * 
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   332
 * The given callback argument will be used when invoking the context's callback for this request.
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   333
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   334
 * The state machine will work as follows:
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   335
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   336
 *  req_state               multi       req_reply
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   337
 *  ---------------------------------------------
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   338
 *  STATE_QUEUE             ?
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   339
 *  STATE_SEND
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   340
 *  STATE_REPLY                         RPL_{STORED,NOT_STORED,EXISTS,NOT_FOUND}
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   341
 *  STATE_DONE                          RPL_{STORED,NOT_STORED,EXISTS,NOT_FOUND}
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   342
 * 
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   343
 *  STATE_ERROR                         RPL_{ERROR,CLIENT_ERROR,SERVER_ERROR}
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   344
 *
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   345
 */
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   346
struct memcache_req *memcache_store (struct memcache *mc, enum memcache_command cmd, const struct memcache_key *key, const struct memcache_obj *obj, const struct memcache_buf *buf, void *cb_arg);
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   347
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   348
/*
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   349
 * Request state.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   350
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   351
 * Should always return a valid value.
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   352
 */ 
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
   353
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
   354
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   355
/*
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   356
 * Request command.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   357
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   358
 * Should always return a valid value.
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   359
 */
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   360
enum memcache_command memcache_req_cmd (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
   361
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   362
/*
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   363
 * Request reply.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   364
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   365
 * Will return a valid value in the STATE_REPLY, STATE_REPLY_DATA, STATE_DONE and STATE_DATA_DONE states.
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   366
 */
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   367
enum memcache_reply memcache_req_reply (struct memcache_req *req);
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   368
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   369
/*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   370
 * Request key.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   371
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   372
 * Will return a valid valuein all states
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   373
 */
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   374
const struct memcache_key *keymemcache_req_key (struct memcache_req *req);
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   375
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   376
/*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   377
 * Request data.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   378
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   379
 * Will return a valid value in the STATE_REPLY, STATE_REPLY_DATA, STATE_DONE and STATE_DATA_DONE states.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   380
 */
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   381
const struct memcache_obj *memcache_req_obj (struct memcache_req *req);
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   382
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   383
/*
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   384
 * Request buf.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   385
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   386
 * Will return a valid value in the STATE_REPLY_DATA and STATE_DATA_DONE states.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   387
 *
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   388
 * Note that buf.offset may be less than buf.len in the STATE_REPLY_DATA state.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   389
 */
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   390
const struct memcache_buf *memcache_req_buf (struct memcache_req *req);
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   391
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   392
/*
45
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   393
 * Abort a running request, regardless of what state it is in.
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   394
 *
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   395
 * You do not need to call req_free after this.
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   396
 *
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   397
 * XXX: unimplemented
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   398
 */
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   399
void memcache_req_abort (struct memcache_req *req);
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   400
10d514029c64 documentation tweaks, add req_abort function prototype
Tero Marttila <terom@fixme.fi>
parents: 44
diff changeset
   401
/*
44
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   402
 * Free a req that is in the STATE_DONE, STATE_DATA_DONE or STATE_ERROR state.
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   403
 */
03a7e064f833 stub functions and documentation
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
   404
void memcache_req_free (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
   405
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   406
#endif /* MEMCACHE_H */