Skip to content
Browse files

Fixed purging during disconnect

Change-Id: I8e0b0551452901e4335c8ad92babde131fb8fab8
Reviewed-on: http://review.couchbase.org/25147
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information...
1 parent d3eefe0 commit 32a62bc722ea9c70482f5472dd067badb7302b9b @trondn trondn committed Mar 13, 2013
Showing with 19 additions and 6 deletions.
  1. +1 −1 src/event.c
  2. +2 −1 src/internal.h
  3. +16 −4 src/server.c
View
2 src/event.c
@@ -142,7 +142,7 @@ static int parse_single(lcb_server_t *c, hrtime_t stop)
break;
case PROTOCOL_BINARY_RES: {
int was_connected = c->connected;
- if (lcb_server_purge_implicit_responses(c, header.response.opaque, stop) != 0) {
+ if (lcb_server_purge_implicit_responses(c, header.response.opaque, stop, 0) != 0) {
if (packet != c->input.read_head) {
free(packet);
}
View
3 src/internal.h
@@ -369,7 +369,8 @@ extern "C" {
const char *reason);
int lcb_server_purge_implicit_responses(lcb_server_t *c,
lcb_uint32_t seqno,
- hrtime_t delta);
+ hrtime_t delta,
+ int all);
void lcb_server_destroy(lcb_server_t *server);
void lcb_server_connected(lcb_server_t *server);
View
20 src/server.c
@@ -425,7 +425,8 @@ void lcb_server_destroy(lcb_server_t *server)
if (server->cmd_log.nbytes) {
lcb_server_purge_implicit_responses(server,
server->instance->seqno,
- gethrtime());
+ gethrtime(),
+ 1);
}
if (server->sasl_conn != NULL) {
@@ -798,11 +799,17 @@ void lcb_server_send_packets(lcb_server_t *server)
*/
int lcb_server_purge_implicit_responses(lcb_server_t *c,
lcb_uint32_t seqno,
- hrtime_t end)
+ hrtime_t end,
+ int all)
{
protocol_binary_request_header req;
lcb_size_t nr = ringbuffer_peek(&c->cmd_log, req.bytes, sizeof(req));
- /* There should at _LEAST_ be _ONE_ message in here! */
+ /* There should at _LEAST_ be _ONE_ message in here if we're not
+ * trying to purge _ALL_ of the messages in the queue
+ */
+ if (all && nr == 0) {
+ return 0;
+ }
assert(nr == sizeof(req));
while (req.request.opaque < seqno) {
struct lcb_command_data_st ct;
@@ -870,7 +877,12 @@ int lcb_server_purge_implicit_responses(lcb_server_t *c,
}
ringbuffer_consumed(&c->cmd_log, packetsize);
nr = ringbuffer_peek(&c->cmd_log, req.bytes, sizeof(req));
- /* The current message should also be there... */
+ /* The current message should also be there (unless we tried to
+ * purge _all_ of them
+ */
+ if (all && nr == 0) {
+ return 0;
+ }
assert(nr == sizeof(req));
}

0 comments on commit 32a62bc

Please sign in to comment.
Something went wrong with that request. Please try again.