Browse Source

Rearm the epoll client fd only when it's still valid after processing its message

master
Con Kolivas 9 years ago
parent
commit
7357525712
  1. 22
      src/connector.c

22
src/connector.c

@ -570,25 +570,19 @@ static void client_event_processor(ckpool_t *ckp, struct epoll_event *event)
client = ref_client_by_id(cdata, id);
if (unlikely(!client)) {
LOGNOTICE("Failed to find client by id %"PRId64" in receiver!", id);
LOGWARNING("Failed to find client by id %"PRId64" in receiver!", id);
goto outnoclient;
}
if (unlikely(client->invalid))
goto out;
/* We can have both messages and read hang ups so process the
* message first. */
* message first. */
if (likely(events & EPOLLIN)) {
/* Rearm the client for epoll events if we have successfully
* parsed a message from it */
if (parse_client_msg(ckp, cdata, client)) {
event->data.u64 = id;
event->events = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT;
epoll_ctl(cdata->epfd, EPOLL_CTL_MOD, client->fd, event);
} else
if (unlikely(!parse_client_msg(ckp, cdata, client))) {
invalidate_client(ckp, cdata, client);
goto out;
}
}
if (unlikely(client->invalid))
goto out;
if (unlikely(events & EPOLLERR)) {
socklen_t errlen = sizeof(int);
int error = 0;
@ -614,6 +608,12 @@ static void client_event_processor(ckpool_t *ckp, struct epoll_event *event)
invalidate_client(cdata->pi->ckp, cdata, client);
}
out:
if (likely(!client->invalid)) {
/* Rearm the fd in the epoll list if it's still active */
event->data.u64 = id;
event->events = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT;
epoll_ctl(cdata->epfd, EPOLL_CTL_MOD, client->fd, event);
}
dec_instance_ref(cdata, client);
outnoclient:
free(event);

Loading…
Cancel
Save