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. 20
      src/connector.c

20
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); client = ref_client_by_id(cdata, id);
if (unlikely(!client)) { 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; goto outnoclient;
} }
if (unlikely(client->invalid))
goto out;
/* We can have both messages and read hang ups so process the /* We can have both messages and read hang ups so process the
* message first. */ * message first. */
if (likely(events & EPOLLIN)) { if (likely(events & EPOLLIN)) {
/* Rearm the client for epoll events if we have successfully /* Rearm the client for epoll events if we have successfully
* parsed a message from it */ * parsed a message from it */
if (parse_client_msg(ckp, cdata, client)) { if (unlikely(!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
invalidate_client(ckp, cdata, client); invalidate_client(ckp, cdata, client);
}
if (unlikely(client->invalid))
goto out; goto out;
}
}
if (unlikely(events & EPOLLERR)) { if (unlikely(events & EPOLLERR)) {
socklen_t errlen = sizeof(int); socklen_t errlen = sizeof(int);
int error = 0; 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); invalidate_client(cdata->pi->ckp, cdata, client);
} }
out: 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); dec_instance_ref(cdata, client);
outnoclient: outnoclient:
free(event); free(event);

Loading…
Cancel
Save