memcached_behavior.c \
memcached_connect.c \
memcached_delete.c \
+ memcached_do.c \
memcached_flush.c \
memcached_get.c \
memcached_hash.c \
size_t memcached_string_backspace(memcached_string_st *string, size_t remove);
memcached_return memcached_string_reset(memcached_string_st *string);
void memcached_string_free(memcached_string_st *string);
+memcached_return memcached_do(memcached_st *ptr, unsigned int server_key, char *commmand,
+ size_t command_length, char with_flush);
#endif /* __COMMON_H__ */
unsigned int offset,
uint64_t *value)
{
- size_t send_length, sent_length;
+ size_t send_length;
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
unsigned int server_key;
server_key= memcached_generate_hash(ptr, key, key_length);
- if ((rc= memcached_connect(ptr, server_key)) != MEMCACHED_SUCCESS)
- return rc;
-
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"%s %.*s %u\r\n", verb,
(int)key_length, key,
offset);
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
- sent_length= memcached_io_write(ptr, server_key, buffer, send_length, 1);
- if (sent_length == -1 || sent_length != send_length)
- return MEMCACHED_WRITE_FAILURE;
+ rc= memcached_do(ptr, server_key, buffer, send_length, 1);
+ if (rc != MEMCACHED_SUCCESS)
+ return rc;
memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE);
time_t expiration)
{
char to_write;
- size_t send_length, sent_length;
+ size_t send_length;
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
unsigned int server_key;
server_key= memcached_generate_hash(ptr, key, key_length);
- if ((rc= memcached_connect(ptr, server_key)) != MEMCACHED_SUCCESS)
- return rc;
-
-
if (expiration)
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"delete %.*s %llu\r\n", (int)key_length, key,
else
to_write= 1;
- if ((sent_length= memcached_io_write(ptr, server_key, buffer, send_length, to_write)) == -1)
- {
- memcached_quit_server(ptr, server_key);
- rc= MEMCACHED_WRITE_FAILURE;
+ rc= memcached_do(ptr, server_key, buffer, send_length, to_write);
+ if (rc != MEMCACHED_SUCCESS)
goto error;
- }
if ((ptr->flags & MEM_NO_BLOCK))
{
rc= MEMCACHED_SUCCESS;
}
- LIBMEMCACHED_MEMCACHED_DELETE_END();
-
error:
+ LIBMEMCACHED_MEMCACHED_DELETE_END();
return rc;
}
--- /dev/null
+#include "common.h"
+
+memcached_return memcached_do(memcached_st *ptr, unsigned int server_key, char *command,
+ size_t command_length, char with_flush)
+{
+ memcached_return rc;
+ ssize_t sent_length;
+
+ WATCHPOINT_ASSERT(command);
+ if ((rc= memcached_connect(ptr, server_key)) != MEMCACHED_SUCCESS)
+ return rc;
+
+ sent_length= memcached_io_write(ptr, server_key, command, command_length, with_flush);
+
+ if (sent_length == -1 || sent_length != command_length)
+ {
+ memcached_quit_server(ptr, server_key);
+ rc= MEMCACHED_WRITE_FAILURE;
+ }
+
+ return rc;
+}
memcached_return memcached_flush(memcached_st *ptr, time_t expiration)
{
unsigned int x;
- size_t send_length, sent_length;
+ size_t send_length;
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
LIBMEMCACHED_MEMCACHED_FLUSH_START();
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
- sent_length= memcached_io_write(ptr, x, buffer, send_length, 1);
-
- if (sent_length == -1 || sent_length != send_length)
- return MEMCACHED_WRITE_FAILURE;
+ rc= memcached_do(ptr, x, buffer, send_length, 1);
+ if (rc != MEMCACHED_SUCCESS)
+ goto error;
rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
rc= MEMCACHED_SOME_ERRORS;
}
+error:
LIBMEMCACHED_MEMCACHED_FLUSH_END();
return rc;
}
LIBMEMCACHED_MEMCACHED_GET_START();
if (key_length == 0)
- return MEMCACHED_NO_KEY_PROVIDED;
+ {
+ *error= MEMCACHED_NO_KEY_PROVIDED;
+ return NULL;
+ }
if (ptr->hosts == NULL || ptr->number_of_hosts == 0)
{
result_buffer= &ptr->result_buffer;
*value_length= 0;
- *error= memcached_connect(ptr, server_key);
-
- if (*error != MEMCACHED_SUCCESS)
- goto error;
-
memcpy(buf_ptr, "get ", 4);
buf_ptr+= 4;
memcpy(buf_ptr, key, key_length);
memcpy(buf_ptr, "\r\n", 2);
buf_ptr+= 2;
- if ((memcached_io_write(ptr, server_key, buffer, (size_t)(buf_ptr - buffer), 1)) == -1)
- {
- *error= MEMCACHED_WRITE_FAILURE;
+ *error= memcached_do(ptr, server_key, buffer, (size_t)(buf_ptr - buffer), 1);
+ if (*error != MEMCACHED_SUCCESS)
goto error;
- }
*error= memcached_value_fetch(ptr, key, &key_length, result_buffer,
flags, 0, server_key);
{
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
- size_t send_length, sent_length;
+ size_t send_length;
rc= memcached_connect(ptr, server_key);
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
- sent_length= memcached_io_write(ptr, server_key, buffer, send_length, 1);
-
- if (sent_length == -1 || sent_length != send_length)
- return MEMCACHED_WRITE_FAILURE;
+ rc= memcached_do(ptr, server_key, buffer, send_length, 1);
+ if (rc != MEMCACHED_SUCCESS)
+ goto error;
while (1)
{
break;
}
+error:
if (rc == MEMCACHED_END)
return MEMCACHED_SUCCESS;
else
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
- rc= memcached_connect(ptr, 0);
-
- if (rc != MEMCACHED_SUCCESS)
- rc= MEMCACHED_SOME_ERRORS;
-
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"verbosity %u\r\n", verbosity);
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
+ rc= MEMCACHED_SUCCESS;
for (x= 0; x < ptr->number_of_hosts; x++)
{
- memcached_return rc;
+ memcached_return rrc;
- if ((memcached_io_write(ptr, x, buffer, send_length, 1)) == -1)
+ rrc= memcached_do(ptr, x, buffer, send_length, 1);
+ if (rrc != MEMCACHED_SUCCESS)
{
+ rc= MEMCACHED_SOME_ERRORS;
continue;
- return MEMCACHED_SOME_ERRORS;
}
- rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
-
- if (rc != MEMCACHED_SUCCESS)
+ rrc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
+ if (rrc != MEMCACHED_SUCCESS)
rc= MEMCACHED_SOME_ERRORS;
}