projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
Version will now have a default we can use to look for invalid versions.
[awesomized/libmemcached]
/
libmemcached
/
version.c
diff --git
a/libmemcached/version.c
b/libmemcached/version.c
index d854efdca3825a7a626e95f751e0605b4cb8d7f6..8fcc11a0fb6b95b2ed95eedd17a9a69735f768f3 100644
(file)
--- a/
libmemcached/version.c
+++ b/
libmemcached/version.c
@@
-13,15
+13,23
@@
memcached_return_t memcached_version(memcached_st *ptr)
if (ptr->flags.use_udp)
return MEMCACHED_NOT_SUPPORTED;
if (ptr->flags.use_udp)
return MEMCACHED_NOT_SUPPORTED;
+ bool was_blocking= ptr->flags.no_block;
+ memcached_return_t rc;
+
+ ptr->flags.no_block= false;
+
if (ptr->flags.binary_protocol)
if (ptr->flags.binary_protocol)
- r
eturn
memcached_version_binary(ptr);
+ r
c=
memcached_version_binary(ptr);
else
else
- return memcached_version_textual(ptr);
+ rc= memcached_version_textual(ptr);
+
+ ptr->flags.no_block= was_blocking;
+
+ return rc;
}
static inline memcached_return_t memcached_version_textual(memcached_st *ptr)
{
}
static inline memcached_return_t memcached_version_textual(memcached_st *ptr)
{
- unsigned int x;
size_t send_length;
memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
size_t send_length;
memcached_return_t rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
@@
-31,15
+39,20
@@
static inline memcached_return_t memcached_version_textual(memcached_st *ptr)
send_length= strlen(command);
rc= MEMCACHED_SUCCESS;
send_length= strlen(command);
rc= MEMCACHED_SUCCESS;
- for (x= 0; x < memcached_server_count(ptr); x++)
+ for (
uint32_t
x= 0; x < memcached_server_count(ptr); x++)
{
memcached_return_t rrc;
{
memcached_return_t rrc;
- memcached_server_
instance_st *
instance=
+ memcached_server_
write_instance_st
instance=
memcached_server_instance_fetch(ptr, x);
memcached_server_instance_fetch(ptr, x);
- rrc= memcached_do(instance, command, send_length, 1);
+ // Optimization, we only fetch version once.
+ if (instance->major_version != UINT8_MAX)
+ continue;
+
+ rrc= memcached_do(instance, command, send_length, true);
if (rrc != MEMCACHED_SUCCESS)
{
if (rrc != MEMCACHED_SUCCESS)
{
+ instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
rc= MEMCACHED_SOME_ERRORS;
continue;
}
rc= MEMCACHED_SOME_ERRORS;
continue;
}
@@
-47,6
+60,7
@@
static inline memcached_return_t memcached_version_textual(memcached_st *ptr)
rrc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
if (rrc != MEMCACHED_SUCCESS)
{
rrc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
if (rrc != MEMCACHED_SUCCESS)
{
+ instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
rc= MEMCACHED_SOME_ERRORS;
continue;
}
rc= MEMCACHED_SOME_ERRORS;
continue;
}
@@
-56,12
+70,33
@@
static inline memcached_return_t memcached_version_textual(memcached_st *ptr)
response_ptr++;
instance->major_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10);
response_ptr++;
instance->major_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10);
+ if (errno == ERANGE)
+ {
+ instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
+ rc= MEMCACHED_SOME_ERRORS;
+ continue;
+ }
+
response_ptr= index(response_ptr, '.');
response_ptr++;
response_ptr= index(response_ptr, '.');
response_ptr++;
+
instance->minor_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10);
instance->minor_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10);
+ if (errno == ERANGE)
+ {
+ instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
+ rc= MEMCACHED_SOME_ERRORS;
+ continue;
+ }
+
response_ptr= index(response_ptr, '.');
response_ptr++;
instance->micro_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10);
response_ptr= index(response_ptr, '.');
response_ptr++;
instance->micro_version= (uint8_t)strtol(response_ptr, (char **)NULL, 10);
+ if (errno == ERANGE)
+ {
+ instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
+ rc= MEMCACHED_SOME_ERRORS;
+ continue;
+ }
}
return rc;
}
return rc;
@@
-70,21
+105,23
@@
static inline memcached_return_t memcached_version_textual(memcached_st *ptr)
static inline memcached_return_t memcached_version_binary(memcached_st *ptr)
{
memcached_return_t rc;
static inline memcached_return_t memcached_version_binary(memcached_st *ptr)
{
memcached_return_t rc;
- unsigned int x;
protocol_binary_request_version request= { .bytes= {0}};
request.message.header.request.magic= PROTOCOL_BINARY_REQ;
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_VERSION;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
rc= MEMCACHED_SUCCESS;
protocol_binary_request_version request= { .bytes= {0}};
request.message.header.request.magic= PROTOCOL_BINARY_REQ;
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_VERSION;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
rc= MEMCACHED_SUCCESS;
- for (x= 0; x < memcached_server_count(ptr); x++)
+ for (
uint32_t
x= 0; x < memcached_server_count(ptr); x++)
{
memcached_return_t rrc;
{
memcached_return_t rrc;
- memcached_server_
instance_st *
instance=
+ memcached_server_
write_instance_st
instance=
memcached_server_instance_fetch(ptr, x);
memcached_server_instance_fetch(ptr, x);
- rrc= memcached_do(instance, request.bytes, sizeof(request.bytes), 1);
+ if (instance->major_version != UINT8_MAX)
+ continue;
+
+ rrc= memcached_do(instance, request.bytes, sizeof(request.bytes), true);
if (rrc != MEMCACHED_SUCCESS)
{
memcached_io_reset(instance);
if (rrc != MEMCACHED_SUCCESS)
{
memcached_io_reset(instance);
@@
-93,11
+130,14
@@
static inline memcached_return_t memcached_version_binary(memcached_st *ptr)
}
}
}
}
- for (x= 0; x < memcached_server_count(ptr); x++)
+ for (
uint32_t
x= 0; x < memcached_server_count(ptr); x++)
{
{
- memcached_server_
instance_st *
instance=
+ memcached_server_
write_instance_st
instance=
memcached_server_instance_fetch(ptr, x);
memcached_server_instance_fetch(ptr, x);
+ if (instance->major_version != UINT8_MAX)
+ continue;
+
if (memcached_server_response_count(instance) > 0)
{
memcached_return_t rrc;
if (memcached_server_response_count(instance) > 0)
{
memcached_return_t rrc;
@@
-113,8
+153,29
@@
static inline memcached_return_t memcached_version_binary(memcached_st *ptr)
}
instance->major_version= (uint8_t)strtol(buffer, &p, 10);
}
instance->major_version= (uint8_t)strtol(buffer, &p, 10);
+ if (errno == ERANGE)
+ {
+ instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
+ rc= MEMCACHED_SOME_ERRORS;
+ continue;
+ }
+
instance->minor_version= (uint8_t)strtol(p + 1, &p, 10);
instance->minor_version= (uint8_t)strtol(p + 1, &p, 10);
+ if (errno == ERANGE)
+ {
+ instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
+ rc= MEMCACHED_SOME_ERRORS;
+ continue;
+ }
+
instance->micro_version= (uint8_t)strtol(p + 1, NULL, 10);
instance->micro_version= (uint8_t)strtol(p + 1, NULL, 10);
+ if (errno == ERANGE)
+ {
+ instance->major_version= instance->minor_version= instance->micro_version= UINT8_MAX;
+ rc= MEMCACHED_SOME_ERRORS;
+ continue;
+ }
+
}
}
}
}