memcache/strings.c
author Tero Marttila <terom@fixme.fi>
Fri, 29 Aug 2008 23:31:17 +0300
changeset 48 1c67f512779b
parent 46 8a832c0e01ee
permissions -rw-r--r--
fix doc tpyos, rename some enums, fix printf format len for non-zero terminated strings (hg status), pass args to memcache_cmd_format_header via memcache_req_*, handle zero-length STORE requests, memcache_req is_buf_ours + free, other function name typos (keymemcache_req_key), fix req state behaviour re *_DATA_* for STORE requests and FETCH/END, better memcache_server connpool events/management, modular memcache_test with a working benchmark. This is a long commit message.

#include "../memcache.h"

#define CASE_STR(val) case val: return #val
#define CASE_DEFAULT(prefix) default: return #prefix "_???"

const char *memcache_command_str (enum memcache_command cmd) {
    switch (cmd) {
        CASE_STR(MEMCACHE_CMD_INVALID);
        CASE_STR(MEMCACHE_CMD_FETCH_GET);
        CASE_STR(MEMCACHE_CMD_STORE_SET);
        CASE_STR(MEMCACHE_CMD_STORE_ADD);
        CASE_STR(MEMCACHE_CMD_STORE_REPLACE);
        CASE_STR(MEMCACHE_CMD_STORE_APPEND);
        CASE_STR(MEMCACHE_CMD_STORE_PREPEND);
        CASE_STR(MEMCACHE_CMD_STORE_CAS);
        CASE_DEFAULT(MEMCACHE_CMD);
    }
}

const char *memcache_reply_str (enum memcache_reply reply) {
    switch (reply) {
        CASE_STR(MEMCACHE_RPL_INVALID);
        CASE_STR(MEMCACHE_RPL_ERROR);
        CASE_STR(MEMCACHE_RPL_CLIENT_ERROR);
        CASE_STR(MEMCACHE_RPL_SERVER_ERROR);
        CASE_STR(MEMCACHE_RPL_VALUE);
        CASE_STR(MEMCACHE_RPL_END);
        CASE_STR(MEMCACHE_RPL_STORED);
        CASE_STR(MEMCACHE_RPL_NOT_STORED);
        CASE_STR(MEMCACHE_RPL_EXISTS);
        CASE_STR(MEMCACHE_RPL_NOT_FOUND);
        CASE_DEFAULT(MEMCACHE_RPL);
    }
}

const char *memcache_state_str (enum memcache_state state) {
    switch (state) {
        CASE_STR(MEMCACHE_STATE_INVALID);
        CASE_STR(MEMCACHE_STATE_QUEUED);
        CASE_STR(MEMCACHE_STATE_SEND);
        CASE_STR(MEMCACHE_STATE_REPLY);
        CASE_STR(MEMCACHE_STATE_REPLY_DATA);
        CASE_STR(MEMCACHE_STATE_DONE);
        CASE_STR(MEMCACHE_STATE_DONE_DATA);
        CASE_STR(MEMCACHE_STATE_ERROR);
        CASE_DEFAULT(MEMCACHE_STATE);
    }
}