3 const char * memcached_lib_version(void)
5 return LIBMEMCACHED_VERSION_STRING
;
8 static inline memcached_return_t
memcached_version_binary(memcached_st
*ptr
);
9 static inline memcached_return_t
memcached_version_textual(memcached_st
*ptr
);
11 memcached_return_t
memcached_version(memcached_st
*ptr
)
13 if (ptr
->flags
.use_udp
)
14 return MEMCACHED_NOT_SUPPORTED
;
16 bool was_blocking
= ptr
->flags
.no_block
;
17 memcached_return_t rc
;
19 ptr
->flags
.no_block
= false;
21 if (ptr
->flags
.binary_protocol
)
22 rc
= memcached_version_binary(ptr
);
24 rc
= memcached_version_textual(ptr
);
26 ptr
->flags
.no_block
= was_blocking
;
31 static inline memcached_return_t
memcached_version_textual(memcached_st
*ptr
)
34 memcached_return_t rc
;
35 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
37 const char *command
= "version\r\n";
39 send_length
= strlen(command
);
41 rc
= MEMCACHED_SUCCESS
;
42 for (uint32_t x
= 0; x
< memcached_server_count(ptr
); x
++)
44 memcached_return_t rrc
;
45 memcached_server_write_instance_st instance
=
46 memcached_server_instance_fetch(ptr
, x
);
48 rrc
= memcached_do(instance
, command
, send_length
, true);
49 if (rrc
!= MEMCACHED_SUCCESS
)
51 rc
= MEMCACHED_SOME_ERRORS
;
55 rrc
= memcached_response(instance
, buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
56 if (rrc
!= MEMCACHED_SUCCESS
)
58 rc
= MEMCACHED_SOME_ERRORS
;
62 /* Find the space, and then move one past it to copy version */
63 response_ptr
= index(buffer
, ' ');
66 instance
->major_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
67 response_ptr
= index(response_ptr
, '.');
69 instance
->minor_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
70 response_ptr
= index(response_ptr
, '.');
72 instance
->micro_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
78 static inline memcached_return_t
memcached_version_binary(memcached_st
*ptr
)
80 memcached_return_t rc
;
81 protocol_binary_request_version request
= { .bytes
= {0}};
82 request
.message
.header
.request
.magic
= PROTOCOL_BINARY_REQ
;
83 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_VERSION
;
84 request
.message
.header
.request
.datatype
= PROTOCOL_BINARY_RAW_BYTES
;
86 rc
= MEMCACHED_SUCCESS
;
87 for (uint32_t x
= 0; x
< memcached_server_count(ptr
); x
++)
89 memcached_return_t rrc
;
91 memcached_server_write_instance_st instance
=
92 memcached_server_instance_fetch(ptr
, x
);
94 rrc
= memcached_do(instance
, request
.bytes
, sizeof(request
.bytes
), true);
95 if (rrc
!= MEMCACHED_SUCCESS
)
97 memcached_io_reset(instance
);
98 rc
= MEMCACHED_SOME_ERRORS
;
103 for (uint32_t x
= 0; x
< memcached_server_count(ptr
); x
++)
105 memcached_server_write_instance_st instance
=
106 memcached_server_instance_fetch(ptr
, x
);
108 if (memcached_server_response_count(instance
) > 0)
110 memcached_return_t rrc
;
114 rrc
= memcached_response(instance
, buffer
, sizeof(buffer
), NULL
);
115 if (rrc
!= MEMCACHED_SUCCESS
)
117 memcached_io_reset(instance
);
118 rc
= MEMCACHED_SOME_ERRORS
;
122 instance
->major_version
= (uint8_t)strtol(buffer
, &p
, 10);
123 instance
->minor_version
= (uint8_t)strtol(p
+ 1, &p
, 10);
124 instance
->micro_version
= (uint8_t)strtol(p
+ 1, NULL
, 10);