3 const char * memcached_lib_version(void)
5 return LIBMEMCACHED_VERSION_STRING
;
8 static inline memcached_return
memcached_version_binary(memcached_st
*ptr
);
9 static inline memcached_return
memcached_version_textual(memcached_st
*ptr
);
11 memcached_return
memcached_version(memcached_st
*ptr
)
13 if (ptr
->flags
& MEM_BINARY_PROTOCOL
)
14 return memcached_version_binary(ptr
);
16 return memcached_version_textual(ptr
);
19 static inline memcached_return
memcached_version_textual(memcached_st
*ptr
)
24 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
26 char *command
= "version\r\n";
28 send_length
= strlen(command
);
30 rc
= MEMCACHED_SUCCESS
;
31 for (x
= 0; x
< ptr
->number_of_hosts
; x
++)
35 rrc
= memcached_do(&ptr
->hosts
[x
], command
, send_length
, 1);
36 if (rrc
!= MEMCACHED_SUCCESS
)
38 rc
= MEMCACHED_SOME_ERRORS
;
42 rrc
= memcached_response(&ptr
->hosts
[x
], buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
43 if (rrc
!= MEMCACHED_SUCCESS
)
45 rc
= MEMCACHED_SOME_ERRORS
;
49 /* Find the space, and then move one past it to copy version */
50 response_ptr
= index(buffer
, ' ');
53 ptr
->hosts
[x
].major_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
54 response_ptr
= index(response_ptr
, '.');
56 ptr
->hosts
[x
].minor_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
57 response_ptr
= index(response_ptr
, '.');
59 ptr
->hosts
[x
].micro_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
65 static inline memcached_return
memcached_version_binary(memcached_st
*ptr
)
69 protocol_binary_request_version request
= { .bytes
= {0}};
70 request
.message
.header
.request
.magic
= PROTOCOL_BINARY_REQ
;
71 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_VERSION
;
72 request
.message
.header
.request
.datatype
= PROTOCOL_BINARY_RAW_BYTES
;
74 rc
= MEMCACHED_SUCCESS
;
75 for (x
= 0; x
< ptr
->number_of_hosts
; x
++)
79 rrc
= memcached_do(&ptr
->hosts
[x
], request
.bytes
, sizeof(request
.bytes
), 1);
80 if (rrc
!= MEMCACHED_SUCCESS
)
82 memcached_io_reset(&ptr
->hosts
[x
]);
83 rc
= MEMCACHED_SOME_ERRORS
;
88 for (x
= 0; x
< ptr
->number_of_hosts
; x
++)
89 if (memcached_server_response_count(&ptr
->hosts
[x
]) > 0)
95 rrc
= memcached_response(&ptr
->hosts
[x
], buffer
, sizeof(buffer
), NULL
);
96 if (rrc
!= MEMCACHED_SUCCESS
)
98 memcached_io_reset(&ptr
->hosts
[x
]);
99 rc
= MEMCACHED_SOME_ERRORS
;
103 ptr
->hosts
[x
].major_version
= (uint8_t)strtol(buffer
, &p
, 10);
104 ptr
->hosts
[x
].minor_version
= (uint8_t)strtol(p
+ 1, &p
, 10);
105 ptr
->hosts
[x
].micro_version
= (uint8_t)strtol(p
+ 1, NULL
, 10);