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 memcached_return_t rc
;
18 if (ptr
->flags
.binary_protocol
)
19 rc
= memcached_version_binary(ptr
);
21 rc
= memcached_version_textual(ptr
);
26 static inline memcached_return_t
memcached_version_textual(memcached_st
*ptr
)
29 memcached_return_t rc
;
30 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
32 const char *command
= "version\r\n";
34 send_length
= sizeof("version\r\n") -1;
36 rc
= MEMCACHED_SUCCESS
;
37 for (uint32_t x
= 0; x
< memcached_server_count(ptr
); x
++)
39 memcached_return_t rrc
;
40 memcached_server_write_instance_st instance
=
41 memcached_server_instance_fetch(ptr
, x
);
43 // Optimization, we only fetch version once.
44 if (instance
->major_version
!= UINT8_MAX
)
47 rrc
= memcached_do(instance
, command
, send_length
, true);
48 if (rrc
!= MEMCACHED_SUCCESS
)
50 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= UINT8_MAX
;
51 rc
= MEMCACHED_SOME_ERRORS
;
55 rrc
= memcached_response(instance
, buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
56 if (rrc
!= MEMCACHED_SUCCESS
)
58 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= UINT8_MAX
;
59 rc
= MEMCACHED_SOME_ERRORS
;
63 /* Find the space, and then move one past it to copy version */
64 response_ptr
= index(buffer
, ' ');
67 instance
->major_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
70 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= UINT8_MAX
;
71 rc
= MEMCACHED_SOME_ERRORS
;
75 response_ptr
= index(response_ptr
, '.');
78 instance
->minor_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
81 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= UINT8_MAX
;
82 rc
= MEMCACHED_SOME_ERRORS
;
86 response_ptr
= index(response_ptr
, '.');
88 instance
->micro_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
91 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= UINT8_MAX
;
92 rc
= MEMCACHED_SOME_ERRORS
;
100 static inline memcached_return_t
memcached_version_binary(memcached_st
*ptr
)
102 memcached_return_t rc
;
103 protocol_binary_request_version request
= { .bytes
= {0}};
104 request
.message
.header
.request
.magic
= PROTOCOL_BINARY_REQ
;
105 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_VERSION
;
106 request
.message
.header
.request
.datatype
= PROTOCOL_BINARY_RAW_BYTES
;
108 rc
= MEMCACHED_SUCCESS
;
109 for (uint32_t x
= 0; x
< memcached_server_count(ptr
); x
++)
111 memcached_return_t rrc
;
113 memcached_server_write_instance_st instance
=
114 memcached_server_instance_fetch(ptr
, x
);
116 if (instance
->major_version
!= UINT8_MAX
)
119 rrc
= memcached_do(instance
, request
.bytes
, sizeof(request
.bytes
), true);
120 if (rrc
!= MEMCACHED_SUCCESS
)
122 memcached_io_reset(instance
);
123 rc
= MEMCACHED_SOME_ERRORS
;
128 for (uint32_t x
= 0; x
< memcached_server_count(ptr
); x
++)
130 memcached_server_write_instance_st instance
=
131 memcached_server_instance_fetch(ptr
, x
);
133 if (instance
->major_version
!= UINT8_MAX
)
136 if (memcached_server_response_count(instance
) > 0)
138 memcached_return_t rrc
;
142 rrc
= memcached_response(instance
, buffer
, sizeof(buffer
), NULL
);
143 if (rrc
!= MEMCACHED_SUCCESS
)
145 memcached_io_reset(instance
);
146 rc
= MEMCACHED_SOME_ERRORS
;
150 instance
->major_version
= (uint8_t)strtol(buffer
, &p
, 10);
153 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= UINT8_MAX
;
154 rc
= MEMCACHED_SOME_ERRORS
;
158 instance
->minor_version
= (uint8_t)strtol(p
+ 1, &p
, 10);
161 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= UINT8_MAX
;
162 rc
= MEMCACHED_SOME_ERRORS
;
166 instance
->micro_version
= (uint8_t)strtol(p
+ 1, NULL
, 10);
169 instance
->major_version
= instance
->minor_version
= instance
->micro_version
= UINT8_MAX
;
170 rc
= MEMCACHED_SOME_ERRORS
;