diff --git a/src/client.c b/src/client.c index ec29045..7b0f1cb 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)) { @@ -101,8 +103,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; + } + } 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; } 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); } }