unsigned int offset,
unsigned int *value)
{
- size_t send_length;
+ size_t send_length, sent_length;
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
unsigned int server_key;
"%s %.*s %u\r\n", verb,
(int)key_length, key,
offset);
-
- if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
+ if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
+ return MEMCACHED_WRITE_FAILURE;
+ if ((sent_length= write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
+ return MEMCACHED_WRITE_FAILURE;
+ if (sent_length != send_length)
return MEMCACHED_WRITE_FAILURE;
memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE);
memcached_return memcached_delete(memcached_st *ptr, char *key, size_t key_length,
time_t expiration)
{
- size_t send_length;
+ size_t send_length, sent_length;
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
unsigned int server_key;
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"delete %.*s\r\n", (int)key_length, key);
- if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
+ if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
+ return MEMCACHED_WRITE_FAILURE;
+
+ if ((sent_length = write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
+ return MEMCACHED_WRITE_FAILURE;
+ if (sent_length != send_length)
return MEMCACHED_WRITE_FAILURE;
return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key);
memcached_return memcached_flush(memcached_st *ptr, time_t expiration)
{
unsigned int x;
- size_t send_length;
+ size_t send_length, sent_length;
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
else
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"flush_all\r\n");
- if ((write(ptr->hosts[x].fd, buffer, send_length) == -1))
+
+ if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
+ return MEMCACHED_WRITE_FAILURE;
+
+ if ((sent_length= write(ptr->hosts[x].fd, buffer, send_length) == -1))
+ return MEMCACHED_WRITE_FAILURE;
+ if (sent_length != send_length)
return MEMCACHED_WRITE_FAILURE;
rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
uint16_t *flags,
memcached_return *error)
{
- size_t send_length;
+ size_t send_length, sent_length;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
char *string_ptr;
unsigned int server_key;
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "get %.*s\r\n",
(int)key_length, key);
- if (*error != MEMCACHED_SUCCESS)
- return NULL;
- if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
+ if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
+ return MEMCACHED_WRITE_FAILURE;
+
+ if ((sent_length = write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
{
*error= MEMCACHED_WRITE_FAILURE;
return NULL;
}
+ if (sent_length != send_length) {
+ *error= MEMCACHED_WRITE_FAILURE;
+ return NULL;
+ }
memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE);
*error= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key);
{
memcached_return rc;
char buffer[HUGE_STRING_LEN];
- size_t send_length;
+ size_t send_length, sent_length;
rc= memcached_connect(ptr);
send_length= snprintf(buffer, HUGE_STRING_LEN,
"stats\r\n");
- if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
+ if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
+ return MEMCACHED_WRITE_FAILURE;
+
+ if ((sent_length= write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
{
fprintf(stderr, "failed on stats\n");
return MEMCACHED_WRITE_FAILURE;
}
+ if (sent_length != send_length)
+ return MEMCACHED_WRITE_FAILURE;
+
rc= memcached_response(ptr, buffer, HUGE_STRING_LEN, 0);
"%s %.*s %x %llu %zu\r\n", verb,
(int)key_length, key, flags,
(unsigned long long)expiration, value_length);
+ if (write_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
+ return MEMCACHED_WRITE_FAILURE;
if ((sent_length= write(ptr->hosts[server_key].fd, buffer, write_length)) == -1)
return MEMCACHED_WRITE_FAILURE;
assert(write_length == sent_length);
memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity)
{
unsigned int x;
- size_t send_length;
+ size_t send_length, sent_length;
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"verbosity %u\r\n", verbosity);
+ if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
+ return MEMCACHED_WRITE_FAILURE;
for (x= 0; x < ptr->number_of_hosts; x++)
{
memcached_return rc;
- if ((write(ptr->hosts[x].fd, buffer, send_length) == -1))
+ if ((sent_length= write(ptr->hosts[x].fd, buffer, send_length) == -1))
+ return MEMCACHED_WRITE_FAILURE;
+ if (sent_length != send_length)
return MEMCACHED_WRITE_FAILURE;
rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);