X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2Fmemcached.c;h=0bab79580661fc79781e7286d54389e224a8e3b3;hb=7add2cb42be7d072888ab916eb35cdef8a2774a1;hp=66a96f043325e1ba40a8707b2bc471d7a8ac088d;hpb=1fc4b1ae18810551553837b4c67c6075f1ad5941;p=awesomized%2Flibmemcached diff --git a/lib/memcached.c b/lib/memcached.c index 66a96f04..0bab7958 100644 --- a/lib/memcached.c +++ b/lib/memcached.c @@ -1,9 +1,9 @@ /* Memcached library */ -#include +#include "common.h" -memcached_st *memcached_init(memcached_st *ptr) +memcached_st *memcached_create(memcached_st *ptr) { if (!ptr) { @@ -23,89 +23,13 @@ memcached_st *memcached_init(memcached_st *ptr) return ptr; } -memcached_return memcached_increment(memcached_st *ptr, char *key, size_t key_length, - unsigned int count) +void memcached_free(memcached_st *ptr) { - return MEMCACHED_SUCCESS; -} - -memcached_return memcached_decrement(memcached_st *ptr, char *key, size_t key_length, - unsigned int count) -{ - return MEMCACHED_SUCCESS; -} - -memcached_return memcached_flush(memcached_st *ptr, time_t expiration) -{ - size_t send_length; - memcached_return rc; - char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - - rc= memcached_connect(ptr); - - if (expiration) - send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "flush_all %u\r\n", expiration); - else - send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "flush_all\r\n"); - if ((send(ptr->hosts[0].fd, buffer, send_length, 0) == -1)) - { - fprintf(stderr, "failed flush_all TCP\n"); - - return MEMCACHED_WRITE_FAILURE; - } - - return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE); -} - -memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity) -{ - size_t send_length; - memcached_return rc; - char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - - rc= memcached_connect(ptr); - - send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "verbosity %u\r\n", verbosity); - - if ((send(ptr->hosts[0].fd, buffer, send_length, 0) == -1)) - { - fprintf(stderr, "failed verbosity\n"); - - return MEMCACHED_WRITE_FAILURE; - } - - return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE); -} - -/* - When this is implemented you will be able to remove single hosts - from your current pool of hosts. -*/ -memcached_return memcached_quit(memcached_st *ptr, char *hostname, unsigned port) -{ - return MEMCACHED_SUCCESS; -} - -void memcached_deinit(memcached_st *ptr) -{ - unsigned int x; - memcached_host_st *host_ptr; - if (ptr->hosts) { - for (x= 0; x < ptr->number_of_hosts; x++) - { - if (ptr->hosts[x].fd > 0) - close(ptr->hosts[x].fd); - - if (ptr->hosts[x].hostname) - free(ptr->hosts[x].hostname); - } - - free(ptr->hosts); + memcached_quit(ptr); + memcached_server_list_free(ptr->hosts); + ptr->hosts= NULL; } if (ptr->is_allocated == MEMCACHED_ALLOCATED) @@ -113,46 +37,3 @@ void memcached_deinit(memcached_st *ptr) else memset(ptr, 0, sizeof(memcached_st)); } - -char *memcached_strerror(memcached_st *ptr, memcached_return rc) -{ - switch (rc) - { - case MEMCACHED_SUCCESS: - return "SUCCESS"; - case MEMCACHED_FAILURE: - return "FAILURE"; - case MEMCACHED_HOST_LOCKUP_FAILURE: - return "HOSTNAME LOOKUP FAILURE"; - case MEMCACHED_CONNECTION_FAILURE: - return "CONNECTION FAILURE"; - case MEMCACHED_CONNECTION_BIND_FAILURE: - return "CONNECTION BIND FAILURE"; - case MEMCACHED_READ_FAILURE: - return "READ FAILURE"; - case MEMCACHED_UNKNOWN_READ_FAILURE: - return "UNKNOWN READ FAILURE"; - case MEMCACHED_PROTOCOL_ERROR: - return "PROTOCOL ERROR"; - case MEMCACHED_CLIENT_ERROR: - return "CLIENT ERROR"; - case MEMCACHED_SERVER_ERROR: - return "SERVER ERROR"; - case MEMCACHED_WRITE_FAILURE: - return "WRITE FAILURE"; - case MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE: - return "CONNECTION SOCKET CREATE FAILURE"; - case MEMCACHED_DATA_EXISTS: - return "CONNECTION DATA EXISTS"; - case MEMCACHED_DATA_DOES_NOT_EXIST: - return "CONNECTION DATA DOES NOT EXIST"; - case MEMCACHED_NOTSTORED: - return "NOT STORED"; - case MEMCACHED_NOTFOUND: - return "NOT FOUND"; - case MEMCACHED_MEMORY_ALLOCATION_FAILURE: - return "MEMORY ALLOCATION FAILURE"; - case MEMCACHED_PARTIAL_READ: - return "PARTIAL READ"; - }; -}