From 7357525712afadcfa42567b2dc87c7b16a7a45c5 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 28 Feb 2016 11:34:20 +1100 Subject: [PATCH] Rearm the epoll client fd only when it's still valid after processing its message --- src/connector.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/connector.c b/src/connector.c index 1df23262..a1eb413e 100644 --- a/src/connector.c +++ b/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);