Skip to content

Commit 2a67d99

Browse files
committed
Fix libmemcachedprotocol's binary STAT and VERSION handlers.
1 parent 011ea03 commit 2a67d99

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

ChangeLog-1.1.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
**Changes from beta2:**
88

9+
* Fix libmemcachedprotocol's binary `STAT` and `VERSION` handlers.
910
* Fix [gh #105](https://github.com/m6w6/libmemcached/issues/105):
1011
EINTR handled too defensively when polling.
1112

@@ -32,7 +33,7 @@
3233

3334
> released 2020-12-21
3435
35-
**NOTE:**
36+
**NOTE:**
3637
This is a bug fix release, not a feature release. The minor version number
3738
was incremented due to the following changes:
3839

docs/source/ChangeLog-1.1.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ v 1.1.0-beta3
1616
**Changes from beta2:**
1717

1818

19+
* Fix libmemcachedprotocol's binary ``STAT`` and ``VERSION`` handlers.
1920
* Fix `gh #105 <https://github.com/m6w6/libmemcached/issues/105>`_\ :
2021
EINTR handled too defensively when polling.
2122

@@ -51,7 +52,7 @@ v 1.1.0-beta1
5152
released 2020-12-21
5253

5354

54-
**NOTE:**
55+
**NOTE:**\ :raw-html-m2r:`<br>`
5556
This is a bug fix release, not a feature release. The minor version number
5657
was incremented due to the following changes:
5758

src/libmemcachedprotocol/binary_handler.c

+22-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ binary_raw_response_handler(const void *cookie, protocol_binary_request_header *
4444
protocol_binary_response_header *response) {
4545
memcached_protocol_client_st *client = (void *) cookie;
4646

47-
if (client->root->pedantic
47+
if (response && client->root->pedantic
4848
&& !memcached_binary_protocol_pedantic_check_response(request, response)) {
4949
return PROTOCOL_BINARY_RESPONSE_EINVAL;
5050
}
@@ -53,6 +53,10 @@ binary_raw_response_handler(const void *cookie, protocol_binary_request_header *
5353
return PROTOCOL_BINARY_RESPONSE_EINTERNAL;
5454
}
5555

56+
if (!response) {
57+
return PROTOCOL_BINARY_RESPONSE_SUCCESS;
58+
}
59+
5660
size_t len = sizeof(protocol_binary_response_header) + htonl(response->response.bodylen);
5761
size_t offset = 0;
5862
char *ptr = (void *) response;
@@ -917,6 +921,20 @@ stat_command_handler(const void *cookie, protocol_binary_request_header *header,
917921

918922
rval = client->root->callback->interface.v1.stat(cookie, (void *) (header + 1), keylen,
919923
stat_response_handler);
924+
if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) {
925+
/* END message */
926+
protocol_binary_response_no_extras response = {
927+
.message = {
928+
.header.response =
929+
{
930+
.magic = PROTOCOL_BINARY_RES,
931+
.opcode = PROTOCOL_BINARY_CMD_STAT,
932+
.status = htons(PROTOCOL_BINARY_RESPONSE_SUCCESS),
933+
.opaque = header->request.opaque,
934+
},
935+
}};
936+
rval = response_handler(cookie, header, &response);
937+
}
920938
} else {
921939
rval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND;
922940
}
@@ -941,6 +959,9 @@ version_command_handler(const void *cookie, protocol_binary_request_header *head
941959
memcached_protocol_client_st *client = (void *) cookie;
942960
if (client->root->callback->interface.v1.version) {
943961
rval = client->root->callback->interface.v1.version(cookie, version_response_handler);
962+
if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) {
963+
rval = response_handler(cookie, header, NULL);
964+
}
944965
} else {
945966
rval = PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND;
946967
}

0 commit comments

Comments
 (0)