Non-blocking IO :)
[awesomized/libmemcached] / lib / memcached.c
1 /*
2 Memcached library
3 */
4 #include "common.h"
5
6 memcached_st *memcached_create(memcached_st *ptr)
7 {
8 if (!ptr)
9 {
10 ptr= (memcached_st *)malloc(sizeof(memcached_st));
11
12 if (!ptr)
13 return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
14
15 memset(ptr, 0, sizeof(memcached_st));
16 ptr->is_allocated= MEMCACHED_ALLOCATED;
17 }
18 else
19 {
20 memset(ptr, 0, sizeof(memcached_st));
21 }
22
23 return ptr;
24 }
25
26 void memcached_free(memcached_st *ptr)
27 {
28 if (ptr->hosts)
29 {
30 memcached_quit(ptr);
31 memcached_server_list_free(ptr->hosts);
32 ptr->hosts= NULL;
33 }
34
35 if (ptr->is_allocated == MEMCACHED_ALLOCATED)
36 free(ptr);
37 else
38 memset(ptr, 0, sizeof(memcached_st));
39 }