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 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= 0;
52 rc
= MEMCACHED_SOME_ERRORS
;
56 rrc
= memcached_response(instance
, buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
57 if (rrc
!= MEMCACHED_SUCCESS
)
59 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= 0;
60 rc
= MEMCACHED_SOME_ERRORS
;
64 /* Find the space, and then move one past it to copy version */
65 response_ptr
= index(buffer
, ' ');
68 instance
->major_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
71 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= 0;
72 rc
= MEMCACHED_SOME_ERRORS
;
76 response_ptr
= index(response_ptr
, '.');
79 instance
->minor_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
82 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= 0;
83 rc
= MEMCACHED_SOME_ERRORS
;
87 response_ptr
= index(response_ptr
, '.');
89 instance
->micro_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
92 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= 0;
93 rc
= MEMCACHED_SOME_ERRORS
;
101 static inline memcached_return_t
memcached_version_binary(memcached_st
*ptr
)
103 memcached_return_t rc
;
104 protocol_binary_request_version request
= { .bytes
= {0}};
105 request
.message
.header
.request
.magic
= PROTOCOL_BINARY_REQ
;
106 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_VERSION
;
107 request
.message
.header
.request
.datatype
= PROTOCOL_BINARY_RAW_BYTES
;
109 rc
= MEMCACHED_SUCCESS
;
110 for (uint32_t x
= 0; x
< memcached_server_count(ptr
); x
++)
112 memcached_return_t rrc
;
114 memcached_server_write_instance_st instance
=
115 memcached_server_instance_fetch(ptr
, x
);
117 rrc
= memcached_do(instance
, request
.bytes
, sizeof(request
.bytes
), true);
118 if (rrc
!= MEMCACHED_SUCCESS
)
120 memcached_io_reset(instance
);
121 rc
= MEMCACHED_SOME_ERRORS
;
126 for (uint32_t x
= 0; x
< memcached_server_count(ptr
); x
++)
128 memcached_server_write_instance_st instance
=
129 memcached_server_instance_fetch(ptr
, x
);
131 if (memcached_server_response_count(instance
) > 0)
133 memcached_return_t rrc
;
137 rrc
= memcached_response(instance
, buffer
, sizeof(buffer
), NULL
);
138 if (rrc
!= MEMCACHED_SUCCESS
)
140 memcached_io_reset(instance
);
141 rc
= MEMCACHED_SOME_ERRORS
;
145 instance
->major_version
= (uint8_t)strtol(buffer
, &p
, 10);
146 instance
->minor_version
= (uint8_t)strtol(p
+ 1, &p
, 10);
147 instance
->micro_version
= (uint8_t)strtol(p
+ 1, NULL
, 10);