memcache.h
changeset 48 1c67f512779b
parent 46 8a832c0e01ee
child 49 10c7dce1a043
equal deleted inserted replaced
47:a5c09677ca6f 48:1c67f512779b
    41     char *buf;
    41     char *buf;
    42 
    42 
    43     /*
    43     /*
    44      * The length of the key buffer in bytes. This does not include a NUL byte.
    44      * The length of the key buffer in bytes. This does not include a NUL byte.
    45      *
    45      *
    46      * If this is given as zero, then the length will be calculsted from buf using strlen(). Empty keys are not
    46      * If this is given as zero, then the length will be calculated from buf using strlen(). Empty keys are not
    47      * allowed, so this will result in an error if buf is an empty string.
    47      * allowed, so this will result in an error if buf is an empty string.
    48      */
    48      */
    49     size_t len;
    49     size_t len;
    50 };
    50 };
    51 
    51 
    52 /*
    52 /*
    53  * Object attributes
    53  * Object attributes
    54  */
    54  */
    55 struct memcache_obj {
    55 struct memcache_obj {
    56     /*
    56     /*
    57      * An arbitrary 16-bit (32-bit for >1.2.1) that the server stores transparently.
    57      * An arbitrary 16-bit (32-bit for >1.2.1) integer that the server stores transparently.
    58      */
    58      */
    59     unsigned int flags;
    59     unsigned int flags;
    60 
    60 
    61     /*
    61     /*
    62      * Expiration time. If non-zero, either an offset in seconds from current time (up to 60*60*24*30 seconds, or 30d),
    62      * Expiration time. If non-zero, either an offset in seconds from current time (up to 60*60*24*30 seconds, or 30d),
   228 };
   228 };
   229 
   229 
   230 /*
   230 /*
   231  * Request states
   231  * Request states
   232  */
   232  */
   233 enum memcache_req_state {
   233 enum memcache_state {
   234     MEMCACHE_STATE_INVALID,
   234     MEMCACHE_STATE_INVALID,
   235     
   235     
   236     /*
   236     /*
   237      * The request is queued, and has not been sent yet
   237      * The request is queued, and has not been sent yet
   238      */
   238      */
   267     /*
   267     /*
   268      * The full reply and reply data has been received.
   268      * The full reply and reply data has been received.
   269      *
   269      *
   270      * req_reply, req_obj and req_buf will all return non-NULL values, and buf.offset will be equal to buf.len.
   270      * req_reply, req_obj and req_buf will all return non-NULL values, and buf.offset will be equal to buf.len.
   271      */
   271      */
   272     MEMCACHE_STATE_DATA_DONE,
   272     MEMCACHE_STATE_DONE_DATA,
   273     
   273     
   274     /*
   274     /*
   275      * An error has occurred.
   275      * An error has occurred.
   276      *
   276      *
   277      * req_reply, req_obj and req_buf may or may not work.
   277      * req_reply, req_obj and req_buf may or may not work.
   310  *
   310  *
   311  *  req_state                  multi   req_reply
   311  *  req_state                  multi   req_reply
   312  *  ---------------------------------------------
   312  *  ---------------------------------------------
   313  *  STATE_QUEUE                 ?
   313  *  STATE_QUEUE                 ?
   314  *  STATE_SEND
   314  *  STATE_SEND
   315  *  STATE_REPLY                         RPL_VALUE
   315  *      STATE_REPLY                     RPL_VALUE
   316  *      STATE_REPLY_DATA        *       RPL_VALUE
   316  *      STATE_REPLY_DATA        *       RPL_VALUE
   317  *      STATE_DATA_DONE                 RPL_END
   317  *      STATE_REPLY_DATA                RPL_END
   318  *
   318  *      STATE_DONE_DATA                 RPL_END
       
   319  *
       
   320  *      STATE_REPLY                     RPL_END
   319  *      STATE_DONE                      RPL_END
   321  *      STATE_DONE                      RPL_END
   320  *
   322  *
   321  *  STATE_ERROR                         RPL_{ERROR,CLIENT_ERROR,SERVER_ERROR}
   323  *  STATE_ERROR                         RPL_{ERROR,CLIENT_ERROR,SERVER_ERROR}
   322  *
   324  *
   323  * The item attributes/data can be accessed via req_obj/req_buf as described in `enum memcache_state`.
   325  * The item attributes/data can be accessed via req_obj/req_buf as described in `enum memcache_state`.
   351 /*
   353 /*
   352  * Request state.
   354  * Request state.
   353  *
   355  *
   354  * Should always return a valid value.
   356  * Should always return a valid value.
   355  */ 
   357  */ 
   356 enum memcache_req_state memcache_req_state (struct memcache_req *req);
   358 enum memcache_state memcache_req_state (struct memcache_req *req);
   357 
   359 
   358 /*
   360 /*
   359  * Request command.
   361  * Request command.
   360  *
   362  *
   361  * Should always return a valid value.
   363  * Should always return a valid value.
   363 enum memcache_command memcache_req_cmd (struct memcache_req *req);
   365 enum memcache_command memcache_req_cmd (struct memcache_req *req);
   364 
   366 
   365 /*
   367 /*
   366  * Request reply.
   368  * Request reply.
   367  *
   369  *
   368  * Will return a valid value in the STATE_REPLY, STATE_REPLY_DATA, STATE_DONE and STATE_DATA_DONE states.
   370  * Will return a valid value in the STATE_REPLY, STATE_REPLY_DATA, STATE_DONE and STATE_DONE_DATA states.
   369  */
   371  */
   370 enum memcache_reply memcache_req_reply (struct memcache_req *req);
   372 enum memcache_reply memcache_req_reply (struct memcache_req *req);
   371 
   373 
   372 /*
   374 /*
   373  * Request key.
   375  * Request key.
   374  *
   376  *
   375  * Will return a valid valuein all states
   377  * Will return a valid valuein all states
   376  */
   378  */
   377 const struct memcache_key *keymemcache_req_key (struct memcache_req *req);
   379 const struct memcache_key *memcache_req_key (struct memcache_req *req);
   378 
   380 
   379 /*
   381 /*
   380  * Request data.
   382  * Request data.
   381  *
   383  *
   382  * Will return a valid value in the STATE_REPLY, STATE_REPLY_DATA, STATE_DONE and STATE_DATA_DONE states.
   384  * Will return a valid value in the STATE_REPLY, STATE_REPLY_DATA, STATE_DONE and STATE_DONE_DATA states.
   383  */
   385  */
   384 const struct memcache_obj *memcache_req_obj (struct memcache_req *req);
   386 const struct memcache_obj *memcache_req_obj (struct memcache_req *req);
   385 
   387 
   386 /*
   388 /*
   387  * Request buf.
   389  * Request buf.
   388  *
   390  *
   389  * Will return a valid value in the STATE_REPLY_DATA and STATE_DATA_DONE states.
   391  * Will return a valid value in the STATE_REPLY_DATA and STATE_DONE_DATA states.
   390  *
   392  *
   391  * Note that buf.offset may be less than buf.len in the STATE_REPLY_DATA state.
   393  * Note that buf.offset may be less than buf.len in the STATE_REPLY_DATA state.
   392  */
   394  */
   393 const struct memcache_buf *memcache_req_buf (struct memcache_req *req);
   395 const struct memcache_buf *memcache_req_buf (struct memcache_req *req);
   394 
   396 
   400  * XXX: unimplemented
   402  * XXX: unimplemented
   401  */
   403  */
   402 void memcache_req_abort (struct memcache_req *req);
   404 void memcache_req_abort (struct memcache_req *req);
   403 
   405 
   404 /*
   406 /*
   405  * Free a req that is in the STATE_DONE, STATE_DATA_DONE or STATE_ERROR state.
   407  * Free a req that is in the STATE_DONE, STATE_DONE_DATA or STATE_ERROR state.
   406  */
   408  */
   407 void memcache_req_free (struct memcache_req *req);
   409 void memcache_req_free (struct memcache_req *req);
   408 
   410 
   409 /*
   411 /*
   410  * Translate commands/replies/states into strings.
   412  * Translate commands/replies/states into strings.
   411  */
   413  */
   412 const char *memcache_command_str (enum memcache_command cmd);
   414 const char *memcache_command_str (enum memcache_command cmd);
   413 const char *memcache_reply_str (enum memcache_reply reply);
   415 const char *memcache_reply_str (enum memcache_reply reply);
   414 const char *memcache_state_str (enum memcache_req_state state);
   416 const char *memcache_state_str (enum memcache_state state);
   415 
   417 
   416 #endif /* MEMCACHE_H */
   418 #endif /* MEMCACHE_H */