Skip to content

Commit

Permalink
Merge pull request #30 from maralla/writable-finish
Browse files Browse the repository at this point in the history
reregister client to be writable if commands not finished
  • Loading branch information
maralla committed Mar 14, 2016
2 parents dbd2448 + 5c7c604 commit 36dc682
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
20 changes: 15 additions & 5 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 36dc682

Please sign in to comment.