Skip to content

Commit 36dc682

Browse files
committed
Merge pull request #30 from maralla/writable-finish
reregister client to be writable if commands not finished
2 parents dbd2448 + 5c7c604 commit 36dc682

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/client.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ int client_read(struct connection *client, int read_socket)
2727
int status = CORVUS_OK, limit = 16;
2828

2929
if (!STAILQ_EMPTY(&client->info->cmd_queue)
30-
&& STAILQ_FIRST(&client->info->cmd_queue)->parse_done) {
31-
buf = conn_get_buf(client);
32-
return client_trigger_event(client, buf);
30+
&& STAILQ_FIRST(&client->info->cmd_queue)->parse_done)
31+
{
32+
event_reregister(&client->ctx->loop, client, E_WRITABLE);
33+
return CORVUS_OK;
3334
}
3435

3536
do {
@@ -80,6 +81,7 @@ void client_make_iov(struct conn_info *info)
8081

8182
int client_write(struct connection *client)
8283
{
84+
struct context *ctx = client->ctx;
8385
struct conn_info *info = client->info;
8486

8587
if (!STAILQ_EMPTY(&info->cmd_queue)) {
@@ -101,8 +103,16 @@ int client_write(struct connection *client)
101103

102104
if (info->iov.cursor >= info->iov.len) {
103105
cmd_iov_reset(&info->iov);
104-
}
105-
if (conn_register(client) == CORVUS_ERR) {
106+
if (event_reregister(&ctx->loop, client, E_READABLE) == CORVUS_ERR) {
107+
LOG(ERROR, "client_write: fail to reregister client %d", client->fd);
108+
return CORVUS_ERR;
109+
}
110+
if (client_trigger_event(client, conn_get_buf(client)) == CORVUS_ERR) {
111+
LOG(ERROR, "client_write: fail to trigger event %d %d",
112+
client->fd, client->ev->fd);
113+
return CORVUS_ERR;
114+
}
115+
} else if (event_reregister(&ctx->loop, client, E_WRITABLE) == CORVUS_ERR) {
106116
LOG(ERROR, "client_write: fail to reregister client %d", client->fd);
107117
return CORVUS_ERR;
108118
}

src/command.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,11 @@ void cmd_mark(struct command *cmd, int fail)
755755
}
756756
}
757757

758-
if (root != NULL) {
759-
if (conn_register(root->client) == CORVUS_ERR) {
760-
LOG(ERROR, "fail to reregister client %d", root->client->fd);
761-
client_eof(root->client);
762-
}
758+
if (root != NULL && event_reregister(&cmd->ctx->loop,
759+
root->client, E_WRITABLE) == CORVUS_ERR)
760+
{
761+
LOG(ERROR, "fail to reregister client %d", root->client->fd);
762+
client_eof(root->client);
763763
}
764764
}
765765

0 commit comments

Comments
 (0)