From 05fc2b2afc0c2dae9915cc3dce2272a6083dba51 Mon Sep 17 00:00:00 2001 From: maralla Date: Mon, 14 Mar 2016 16:48:06 +0800 Subject: [PATCH 1/2] reregister client to be writable if commands not finished --- src/client.c | 16 ++++++++++++---- src/command.c | 10 +++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/client.c b/src/client.c index ec29045..f7bc332 100644 --- a/src/client.c +++ b/src/client.c @@ -27,9 +27,10 @@ int client_read(struct connection *client, int read_socket) int status = CORVUS_OK, limit = 16; if (!STAILQ_EMPTY(&client->info->cmd_queue) - && STAILQ_FIRST(&client->info->cmd_queue)->parse_done) { - buf = conn_get_buf(client); - return client_trigger_event(client, buf); + && STAILQ_FIRST(&client->info->cmd_queue)->parse_done) + { + event_reregister(&client->ctx->loop, client, E_WRITABLE); + return CORVUS_OK; } do { @@ -80,6 +81,7 @@ void client_make_iov(struct conn_info *info) int client_write(struct connection *client) { + struct context *ctx = client->ctx; struct conn_info *info = client->info; if (!STAILQ_EMPTY(&info->cmd_queue)) { @@ -102,10 +104,16 @@ int client_write(struct connection *client) if (info->iov.cursor >= info->iov.len) { cmd_iov_reset(&info->iov); } - if (conn_register(client) == CORVUS_ERR) { + + if (event_reregister(&ctx->loop, client, E_READABLE) == CORVUS_ERR) { LOG(ERROR, "client_write: fail to reregister client %d", client->fd); return CORVUS_ERR; } + if (client_trigger_event(client, conn_get_buf(client)) == CORVUS_ERR) { + LOG(ERROR, "client_write: fail to trigger event %d %d", + client->fd, client->ev->fd); + return CORVUS_ERR; + } if (client->ctx->state == CTX_BEFORE_QUIT || client->ctx->state == CTX_QUITTING) diff --git a/src/command.c b/src/command.c index 1527241..8c55286 100644 --- a/src/command.c +++ b/src/command.c @@ -755,11 +755,11 @@ void cmd_mark(struct command *cmd, int fail) } } - if (root != NULL) { - if (conn_register(root->client) == CORVUS_ERR) { - LOG(ERROR, "fail to reregister client %d", root->client->fd); - client_eof(root->client); - } + if (root != NULL && event_reregister(&cmd->ctx->loop, + root->client, E_WRITABLE) == CORVUS_ERR) + { + LOG(ERROR, "fail to reregister client %d", root->client->fd); + client_eof(root->client); } } From 5c7c60455050cce212a305a009902510677d3906 Mon Sep 17 00:00:00 2001 From: maralla Date: Mon, 14 Mar 2016 17:00:02 +0800 Subject: [PATCH 2/2] set writable if writing not finished --- src/client.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/client.c b/src/client.c index f7bc332..7b0f1cb 100644 --- a/src/client.c +++ b/src/client.c @@ -103,17 +103,19 @@ int client_write(struct connection *client) if (info->iov.cursor >= info->iov.len) { cmd_iov_reset(&info->iov); - } - - if (event_reregister(&ctx->loop, client, E_READABLE) == CORVUS_ERR) { + if (event_reregister(&ctx->loop, client, E_READABLE) == CORVUS_ERR) { + LOG(ERROR, "client_write: fail to reregister client %d", client->fd); + return CORVUS_ERR; + } + if (client_trigger_event(client, conn_get_buf(client)) == CORVUS_ERR) { + LOG(ERROR, "client_write: fail to trigger event %d %d", + client->fd, client->ev->fd); + return CORVUS_ERR; + } + } else if (event_reregister(&ctx->loop, client, E_WRITABLE) == CORVUS_ERR) { LOG(ERROR, "client_write: fail to reregister client %d", client->fd); return CORVUS_ERR; } - if (client_trigger_event(client, conn_get_buf(client)) == CORVUS_ERR) { - LOG(ERROR, "client_write: fail to trigger event %d %d", - client->fd, client->ev->fd); - return CORVUS_ERR; - } if (client->ctx->state == CTX_BEFORE_QUIT || client->ctx->state == CTX_QUITTING)