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_USE_UDP
)
14 return MEMCACHED_NOT_SUPPORTED
;
16 if (ptr
->flags
& MEM_BINARY_PROTOCOL
)
17 return memcached_version_binary(ptr
);
19 return memcached_version_textual(ptr
);
22 static inline memcached_return
memcached_version_textual(memcached_st
*ptr
)
27 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
29 const char *command
= "version\r\n";
31 send_length
= strlen(command
);
33 rc
= MEMCACHED_SUCCESS
;
34 for (x
= 0; x
< ptr
->number_of_hosts
; x
++)
38 rrc
= memcached_do(&ptr
->hosts
[x
], command
, send_length
, 1);
39 if (rrc
!= MEMCACHED_SUCCESS
)
41 rc
= MEMCACHED_SOME_ERRORS
;
45 rrc
= memcached_response(&ptr
->hosts
[x
], buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
46 if (rrc
!= MEMCACHED_SUCCESS
)
48 rc
= MEMCACHED_SOME_ERRORS
;
52 /* Find the space, and then move one past it to copy version */
53 response_ptr
= index(buffer
, ' ');
56 ptr
->hosts
[x
].major_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
57 response_ptr
= index(response_ptr
, '.');
59 ptr
->hosts
[x
].minor_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
60 response_ptr
= index(response_ptr
, '.');
62 ptr
->hosts
[x
].micro_version
= (uint8_t)strtol(response_ptr
, (char **)NULL
, 10);
68 static inline memcached_return
memcached_version_binary(memcached_st
*ptr
)
72 protocol_binary_request_version request
= { .bytes
= {0}};
73 request
.message
.header
.request
.magic
= PROTOCOL_BINARY_REQ
;
74 request
.message
.header
.request
.opcode
= PROTOCOL_BINARY_CMD_VERSION
;
75 request
.message
.header
.request
.datatype
= PROTOCOL_BINARY_RAW_BYTES
;
77 rc
= MEMCACHED_SUCCESS
;
78 for (x
= 0; x
< ptr
->number_of_hosts
; x
++)
82 rrc
= memcached_do(&ptr
->hosts
[x
], request
.bytes
, sizeof(request
.bytes
), 1);
83 if (rrc
!= MEMCACHED_SUCCESS
)
85 memcached_io_reset(&ptr
->hosts
[x
]);
86 rc
= MEMCACHED_SOME_ERRORS
;
91 for (x
= 0; x
< ptr
->number_of_hosts
; x
++)
92 if (memcached_server_response_count(&ptr
->hosts
[x
]) > 0)
98 rrc
= memcached_response(&ptr
->hosts
[x
], buffer
, sizeof(buffer
), NULL
);
99 if (rrc
!= MEMCACHED_SUCCESS
)
101 memcached_io_reset(&ptr
->hosts
[x
]);
102 rc
= MEMCACHED_SOME_ERRORS
;
106 ptr
->hosts
[x
].major_version
= (uint8_t)strtol(buffer
, &p
, 10);
107 ptr
->hosts
[x
].minor_version
= (uint8_t)strtol(p
+ 1, &p
, 10);
108 ptr
->hosts
[x
].micro_version
= (uint8_t)strtol(p
+ 1, NULL
, 10);