6 memcached_st
*memcached_init(memcached_st
*ptr
)
10 ptr
= (memcached_st
*)malloc(sizeof(memcached_st
));
13 return NULL
; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */
15 memset(ptr
, 0, sizeof(memcached_st
));
16 ptr
->is_allocated
= MEMCACHED_ALLOCATED
;
20 memset(ptr
, 0, sizeof(memcached_st
));
27 void memcached_server_add(memcached_st
*ptr
, char *server_name
, unsigned int port
)
32 memcached_return
memcached_delete(memcached_st
*ptr
, char *key
, size_t key_length
,
37 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
39 rc
= memcached_connect(ptr
);
42 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
43 "delete %.*s %u\r\n", key_length
, key
, expiration
);
45 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
46 "delete %.*s\r\n", key_length
, key
);
47 if ((write(ptr
->fd
, buffer
, send_length
) == -1))
49 fprintf(stderr
, "failed set on %.*s TCP\n", key_length
+1, key
);
51 return MEMCACHED_WRITE_FAILURE
;
54 return memcached_response(ptr
, buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
);
57 memcached_return
memcached_increment(memcached_st
*ptr
, char *key
, size_t key_length
,
60 return MEMCACHED_SUCCESS
;
63 memcached_return
memcached_decrement(memcached_st
*ptr
, char *key
, size_t key_length
,
66 return MEMCACHED_SUCCESS
;
69 memcached_return
memcached_flush(memcached_st
*ptr
, time_t expiration
)
73 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
75 rc
= memcached_connect(ptr
);
78 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
79 "flush_all %u\r\n", expiration
);
81 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
83 if ((send(ptr
->fd
, buffer
, send_length
, 0) == -1))
85 fprintf(stderr
, "failed flush_all TCP\n");
87 return MEMCACHED_WRITE_FAILURE
;
90 return memcached_response(ptr
, buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
);
93 char *memcached_version(memcached_st
*ptr
, memcached_return
*error
)
95 return MEMCACHED_SUCCESS
;
98 memcached_return
memcached_verbosity(memcached_st
*ptr
, unsigned int verbosity
)
100 return MEMCACHED_SUCCESS
;
103 memcached_return
memcached_quit(memcached_st
*ptr
)
105 return MEMCACHED_SUCCESS
;
108 void memcached_deinit(memcached_st
*ptr
)
113 if (ptr
->is_allocated
== MEMCACHED_ALLOCATED
)
116 memset(ptr
, 0, sizeof(memcached_st
));
119 char *memcached_strerror(memcached_st
*ptr
, memcached_return rc
)
123 case MEMCACHED_SUCCESS
:
125 case MEMCACHED_FAILURE
:
127 case MEMCACHED_HOST_LOCKUP_FAILURE
:
128 return "HOSTNAME LOOKUP FAILURE";
129 case MEMCACHED_CONNECTION_FAILURE
:
130 return "CONNECTION FAILURE";
131 case MEMCACHED_CONNECTION_BIND_FAILURE
:
132 return "CONNECTION BIND FAILURE";
133 case MEMCACHED_READ_FAILURE
:
134 return "READ FAILURE";
135 case MEMCACHED_UNKNOWN_READ_FAILURE
:
136 return "UNKNOWN READ FAILURE";
137 case MEMCACHED_PROTOCOL_ERROR
:
138 return "PROTOCOL ERROR";
139 case MEMCACHED_CLIENT_ERROR
:
140 return "CLIENT ERROR";
141 case MEMCACHED_SERVER_ERROR
:
142 return "SERVER ERROR";
143 case MEMCACHED_WRITE_FAILURE
:
144 return "WRITE FAILURE";
145 case MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE
:
146 return "CONNECTION SOCKET CREATE FAILURE";
147 case MEMCACHED_DATA_EXISTS
:
148 return "CONNECTION DATA EXISTS";
149 case MEMCACHED_DATA_DOES_NOT_EXIST
:
150 return "CONNECTION DATA DOES NOT EXIST";
151 case MEMCACHED_NOTSTORED
:
153 case MEMCACHED_NOTFOUND
:
155 case MEMCACHED_MEMORY_ALLOCATION_FAILURE
:
156 return "MEMORY ALLOCATION FAILURE";
157 case MEMCACHED_PARTIAL_READ
:
158 return "PARTIAL READ";