}
ptr->io_bytes_sent = 0;
- ptr->read_data_length= data_read;
- ptr->read_buffer_length= data_read;
+ ptr->read_data_length= (size_t) data_read;
+ ptr->read_buffer_length= (size_t) data_read;
ptr->read_ptr= ptr->read_buffer;
}
}
ptr->server_failure_counter= 0;
- *nread = (size_t)(buffer_ptr - (char*)buffer);
+ *nread = (ssize_t)(buffer_ptr - (char*)buffer);
return MEMCACHED_SUCCESS;
}
return -1;
}
- return original_length;
+ return (ssize_t) original_length;
}
memcached_return memcached_io_close(memcached_server_st *ptr)
return -1;
}
- ptr->io_bytes_sent += sent_length;
+ ptr->io_bytes_sent += (uint32_t) sent_length;
local_write_ptr+= sent_length;
- write_length-= sent_length;
- return_length+= sent_length;
+ write_length-= (uint32_t) sent_length;
+ return_length+= (uint32_t) sent_length;
}
WATCHPOINT_ASSERT(write_length == 0);
else
ptr->write_buffer_offset= 0;
- return return_length;
+ return (ssize_t) return_length;
}
/*
if (rc != MEMCACHED_SUCCESS)
return rc;
- offset+= nread;
+ offset+= (size_t) nread;
}
return MEMCACHED_SUCCESS;
{
struct udp_datagram_header_st *header= (struct udp_datagram_header_st *)ptr->write_buffer;
uint16_t cur_req= get_udp_datagram_request_id(header);
- uint16_t msg_num= get_msg_num_from_request_id(cur_req);
- uint16_t thread_id= get_thread_id_from_request_id(cur_req);
+ int msg_num= get_msg_num_from_request_id(cur_req);
+ int thread_id= get_thread_id_from_request_id(cur_req);
if (((++msg_num) & UDP_REQUEST_ID_THREAD_MASK) != 0)
msg_num= 0;
- header->request_id= htons(thread_id | msg_num);
+ header->request_id= htons((uint16_t) (thread_id | msg_num));
}
memcached_return memcached_io_init_udp_header(memcached_server_st *ptr, uint16_t thread_id)
return MEMCACHED_FAILURE;
struct udp_datagram_header_st *header= (struct udp_datagram_header_st *)ptr->write_buffer;
- header->request_id= htons(generate_udp_request_thread_id(thread_id));
+ header->request_id= htons((uint16_t) (generate_udp_request_thread_id(thread_id)));
header->num_datagrams= htons(1);
header->sequence_number= htons(0);
memcached_server_st *memcached_servers_parse(const char *server_strings)
{
char *string;
- unsigned int port;
+ uint32_t port;
uint32_t weight;
const char *begin_ptr;
const char *end_ptr;
if (string)
{
- memcpy(buffer, begin_ptr, string - begin_ptr);
+ memcpy(buffer, begin_ptr, (size_t) (string - begin_ptr));
buffer[(unsigned int)(string - begin_ptr)]= 0;
begin_ptr= string+1;
}
ptr++;
- port= strtoul(ptr, (char **)NULL, 10);
+ port= (uint32_t) strtoul(ptr, (char **)NULL, 10);
ptr2= index(ptr, ' ');
if (! ptr2)
if (ptr2)
{
ptr2++;
- weight = strtoul(ptr2, (char **)NULL, 10);
+ weight = (uint32_t) strtoul(ptr2, (char **)NULL, 10);
}
}
* data to be sent from the server (the commands was in the output buffer
* and just flushed
*/
- long timeo= ptr->root->poll_timeout;
+ int32_t timeo= ptr->root->poll_timeout;
ptr->root->poll_timeout= 2000;
result_ptr= memcached_result_create(ptr->root, &result);
}
memcached_result_free(result_ptr);
- ptr->root->poll_timeout=timeo;
+ ptr->root->poll_timeout= timeo;
}
ptr->root->purging= 0;
memcached_io_close(ptr);
ptr->fd= -1;
- ptr->write_buffer_offset= (ptr->type == MEMCACHED_CONNECTION_UDP) ? UDP_DATAGRAM_HEADER_LENGTH : 0 ;
+ ptr->write_buffer_offset= (size_t) ((ptr->type == MEMCACHED_CONNECTION_UDP) ? UDP_DATAGRAM_HEADER_LENGTH : 0);
ptr->read_buffer_length= 0;
ptr->read_ptr= ptr->read_buffer;
memcached_server_response_reset(ptr);
if (end_ptr == string_ptr)
goto read_error;
for (next_ptr= string_ptr; isdigit(*string_ptr); string_ptr++);
- result->flags= strtoul(next_ptr, &string_ptr, 10);
+ result->flags= (uint32_t) strtoul(next_ptr, &string_ptr, 10);
if (end_ptr == string_ptr)
goto read_error;
memory in the struct, which is important, for something that
rarely should happen?
*/
- rel_ptr= (char *)ptr->root->call_realloc(ptr->root, ptr->cached_server_error, endptr - startptr + 1);
+ rel_ptr= (char *)ptr->root->call_realloc(ptr->root,
+ ptr->cached_server_error,
+ (size_t) (endptr - startptr + 1));
if (rel_ptr == NULL)
{
}
ptr->cached_server_error= rel_ptr;
- memcpy(ptr->cached_server_error, startptr, endptr - startptr);
+ memcpy(ptr->cached_server_error, startptr, (size_t) (endptr - startptr));
ptr->cached_server_error[endptr - startptr]= 0;
return MEMCACHED_SERVER_ERROR;
}
size_t nr= (bodylen > SMALL_STRING_LEN) ? SMALL_STRING_LEN : bodylen;
if (memcached_safe_read(ptr, hole, nr) != MEMCACHED_SUCCESS)
return MEMCACHED_UNKNOWN_READ_FAILURE;
- bodylen -= nr;
+ bodylen-= (uint32_t) nr;
}
/* This might be an error from one of the quiet commands.. if
}
else if (!strcmp("pid", key))
{
- memc_stat->pid= strtol(value, (char **)NULL, 10);
+ memc_stat->pid= (uint32_t) strtol(value, (char **)NULL, 10);
}
else if (!strcmp("uptime", key))
{
- memc_stat->uptime= strtol(value, (char **)NULL, 10);
+ memc_stat->uptime= (uint32_t) strtol(value, (char **)NULL, 10);
}
else if (!strcmp("time", key))
{
- memc_stat->time= strtol(value, (char **)NULL, 10);
+ memc_stat->time= (uint32_t) strtol(value, (char **)NULL, 10);
}
else if (!strcmp("version", key))
{
}
else if (!strcmp("pointer_size", key))
{
- memc_stat->pointer_size= strtol(value, (char **)NULL, 10);
+ memc_stat->pointer_size= (uint32_t) strtol(value, (char **)NULL, 10);
}
else if (!strcmp("rusage_user", key))
{
for (walk_ptr= value; (!ispunct(*walk_ptr)); walk_ptr++);
*walk_ptr= 0;
walk_ptr++;
- memc_stat->rusage_user_seconds= strtol(value, (char **)NULL, 10);
- memc_stat->rusage_user_microseconds= strtol(walk_ptr, (char **)NULL, 10);
+ memc_stat->rusage_user_seconds= (uint32_t) strtol(value, (char **)NULL, 10);
+ memc_stat->rusage_user_microseconds= (uint32_t) strtol(walk_ptr, (char **)NULL, 10);
}
else if (!strcmp("rusage_system", key))
{
for (walk_ptr= value; (!ispunct(*walk_ptr)); walk_ptr++);
*walk_ptr= 0;
walk_ptr++;
- memc_stat->rusage_system_seconds= strtol(value, (char **)NULL, 10);
- memc_stat->rusage_system_microseconds= strtol(walk_ptr, (char **)NULL, 10);
+ memc_stat->rusage_system_seconds= (uint32_t) strtol(value, (char **)NULL, 10);
+ memc_stat->rusage_system_microseconds= (uint32_t) strtol(walk_ptr, (char **)NULL, 10);
}
else if (!strcmp("curr_items", key))
{
- memc_stat->curr_items= strtol(value, (char **)NULL, 10);
+ memc_stat->curr_items= (uint32_t) strtol(value, (char **)NULL, 10);
}
else if (!strcmp("total_items", key))
{
- memc_stat->total_items= strtol(value, (char **)NULL, 10);
+ memc_stat->total_items= (uint32_t) strtol(value, (char **)NULL, 10);
}
else if (!strcmp("bytes_read", key))
{
- memc_stat->bytes_read= strtoll(value, (char **)NULL, 10);
+ memc_stat->bytes_read= (uint32_t) strtoll(value, (char **)NULL, 10);
}
else if (!strcmp("bytes_written", key))
{
- memc_stat->bytes_written= strtoll(value, (char **)NULL, 10);
+ memc_stat->bytes_written= (uint32_t) strtoll(value, (char **)NULL, 10);
}
else if (!strcmp("bytes", key))
{
- memc_stat->bytes= strtoll(value, (char **)NULL, 10);
+ memc_stat->bytes= (uint32_t) strtoll(value, (char **)NULL, 10);
}
else if (!strcmp("curr_connections", key))
{
- memc_stat->curr_connections= strtoll(value, (char **)NULL, 10);
+ memc_stat->curr_connections= (uint32_t) strtoll(value, (char **)NULL, 10);
}
else if (!strcmp("total_connections", key))
{
- memc_stat->total_connections= strtoll(value, (char **)NULL, 10);
+ memc_stat->total_connections= (uint32_t) strtoll(value, (char **)NULL, 10);
}
else if (!strcmp("connection_structures", key))
{
- memc_stat->connection_structures= strtol(value, (char **)NULL, 10);
+ memc_stat->connection_structures= (uint32_t) strtol(value, (char **)NULL, 10);
}
else if (!strcmp("cmd_get", key))
{
- memc_stat->cmd_get= strtoll(value, (char **)NULL, 10);
+ memc_stat->cmd_get= (uint64_t) strtoll(value, (char **)NULL, 10);
}
else if (!strcmp("cmd_set", key))
{
- memc_stat->cmd_set= strtoll(value, (char **)NULL, 10);
+ memc_stat->cmd_set= (uint64_t) strtoll(value, (char **)NULL, 10);
}
else if (!strcmp("get_hits", key))
{
- memc_stat->get_hits= strtoll(value, (char **)NULL, 10);
+ memc_stat->get_hits= (uint64_t) strtoll(value, (char **)NULL, 10);
}
else if (!strcmp("get_misses", key))
{
}
else if (!strcmp("limit_maxbytes", key))
{
- memc_stat->limit_maxbytes= strtoll(value, (char **)NULL, 10);
+ memc_stat->limit_maxbytes= (uint64_t) strtoll(value, (char **)NULL, 10);
}
else if (!strcmp("threads", key))
{
- memc_stat->threads= strtol(value, (char **)NULL, 10);
+ memc_stat->threads= (uint32_t) strtol(value, (char **)NULL, 10);
}
else if (!(strcmp("delete_misses", key) == 0 ||/* New stats in the 1.3 beta */
strcmp("delete_hits", key) == 0 ||/* Just swallow them for now.. */
const char *key, memcached_return *error)
{
char buffer[SMALL_STRING_LEN];
- size_t length;
+ int length;
char *ret;
*error= MEMCACHED_SUCCESS;
return NULL;
}
- ret= ptr->call_malloc(ptr, length + 1);
- memcpy(ret, buffer, length);
+ ret= ptr->call_malloc(ptr, (size_t) (length + 1));
+ memcpy(ret, buffer, (size_t) length);
ret[length]= '\0';
return ret;
if (args != NULL)
{
- int len= strlen(args);
+ size_t len= strlen(args);
rc= memcached_validate_key_length(len, true);
unlikely (rc != MEMCACHED_SUCCESS)
return rc;
request.message.header.request.keylen= htons((uint16_t)len);
- request.message.header.request.bodylen= htonl(len);
+ request.message.header.request.bodylen= htonl((uint32_t) len);
if ((memcached_do(&ptr->hosts[server_key], request.bytes,
sizeof(request.bytes), 0) != MEMCACHED_SUCCESS) ||
size_t send_length;
if (args)
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "stats %s\r\n", args);
+ send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
+ "stats %s\r\n", args);
else
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "stats\r\n");
+ send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
+ "stats\r\n");
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
if (cas)
- write_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "%s %s%.*s %u %llu %zu %llu%s\r\n",
- storage_op_string(verb),
- ptr->prefix_key,
- (int)key_length, key, flags,
- (unsigned long long)expiration, value_length,
- (unsigned long long)cas,
- (ptr->flags & MEM_NOREPLY) ? " noreply" : "");
+ write_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
+ "%s %s%.*s %u %llu %zu %llu%s\r\n",
+ storage_op_string(verb),
+ ptr->prefix_key,
+ (int)key_length, key, flags,
+ (unsigned long long)expiration, value_length,
+ (unsigned long long)cas,
+ (ptr->flags & MEM_NOREPLY) ? " noreply" : "");
else
{
char *buffer_ptr= buffer;
buffer_ptr++;
write_length= (size_t)(buffer_ptr - buffer);
- write_length+= snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "%u %llu %zu%s\r\n",
- flags,
- (unsigned long long)expiration, value_length,
- (ptr->flags & MEM_NOREPLY) ? " noreply" : "");
+ write_length+= (size_t) snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE,
+ "%u %llu %zu%s\r\n",
+ flags,
+ (unsigned long long)expiration, value_length,
+ (ptr->flags & MEM_NOREPLY) ? " noreply" : "");
}
if (ptr->flags & MEM_USE_UDP && ptr->flags & MEM_BUFFER_REQUESTS)
uint64_t cas,
memcached_storage_action verb)
{
- char flush;
+ uint8_t flush;
protocol_binary_request_set request= {.bytes= {0}};
size_t send_length= sizeof(request.bytes);
uint32_t server_key= memcached_generate_hash(ptr, master_key,
request.message.body.expiration= htonl((uint32_t)expiration);
}
- request.message.header.request.bodylen= htonl(key_length + value_length +
- request.message.header.request.extlen);
+ request.message.header.request.bodylen= htonl((uint32_t) (key_length + value_length +
+ request.message.header.request.extlen));
if (cas)
request.message.header.request.cas= htonll(cas);
- flush= ((server->root->flags & MEM_BUFFER_REQUESTS) && verb == SET_OP) ? 0 : 1;
+ flush= (uint8_t) (((server->root->flags & MEM_BUFFER_REQUESTS) && verb == SET_OP) ? 0 : 1);
if ((server->root->flags & MEM_USE_UDP) && !flush)
{
/* write the header */
if ((memcached_do(server, (const char*)request.bytes, send_length, 0) != MEMCACHED_SUCCESS) ||
(memcached_io_write(server, key, key_length, 0) == -1) ||
- (memcached_io_write(server, value, value_length, flush) == -1))
+ (memcached_io_write(server, value, value_length, (char) flush) == -1))
{
memcached_io_reset(server);
return MEMCACHED_WRITE_FAILURE;
if ((memcached_do(srv, (const char*)request.bytes,
send_length, 0) != MEMCACHED_SUCCESS) ||
(memcached_io_write(srv, key, key_length, 0) == -1) ||
- (memcached_io_write(srv, value, value_length, flush) == -1))
+ (memcached_io_write(srv, value, value_length, (char) flush) == -1))
memcached_io_reset(srv);
else
memcached_server_response_decrement(srv);
{
if (need && need > (size_t)(string->current_size - (size_t)(string->end - string->string)))
{
- size_t current_offset= string->end - string->string;
+ size_t current_offset= (size_t) (string->end - string->string);
char *new_value;
size_t adjust;
size_t new_size;
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "verbosity %u\r\n", verbosity);
+ send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
+ "verbosity %u\r\n", verbosity);
unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
*/
const unsigned int m= 0x5bd1e995;
- const unsigned int seed= (0xdeadbeef * length);
+ const size_t seed= (0xdeadbeef * length);
const int r= 24;
// Initialize the hash to a 'random' value
- unsigned int h= seed ^ length;
+ size_t h= seed ^ length;
// Mix 4 bytes at a time into the hash
h *= m;
h ^= h >> 15;
- return h;
+ return (uint32_t) h;
}