diff options
author | Simon Rettberg | 2015-02-25 17:50:33 +0100 |
---|---|---|
committer | Simon Rettberg | 2015-02-25 17:50:33 +0100 |
commit | dd1b647b0b8193a58c047daee6079417b07a5ac5 (patch) | |
tree | f943759257defe1f57bf1921b84a483e3be8494b | |
parent | Hack in support for numeric account names (diff) | |
download | ldadp-dd1b647b0b8193a58c047daee6079417b07a5ac5.tar.gz ldadp-dd1b647b0b8193a58c047daee6079417b07a5ac5.tar.xz ldadp-dd1b647b0b8193a58c047daee6079417b07a5ac5.zip |
Fix epoll based detection of closed connections
-rw-r--r-- | client.c | 9 | ||||
-rw-r--r-- | epoll.c | 3 | ||||
-rw-r--r-- | ldadp.c | 2 |
3 files changed, 9 insertions, 5 deletions
@@ -31,7 +31,7 @@ void client_callback(void *data, int haveIn, int haveOut, int doCleanup) { epoll_client_t *client = (epoll_client_t*)data; if (doCleanup || client->kill) { - printf("Client gone.\n"); + printf("Client gone (1).\n"); client_free(client); return; } @@ -39,7 +39,10 @@ void client_callback(void *data, int haveIn, int haveOut, int doCleanup) // Plain connection if (haveIn) client_haveIn(client); if (haveOut) client_haveOut(client); - if (client->kill) client_free(client); + if (client->kill) { + printf("Client gone (2).\n"); + client_free(client); + } return; } // SSL connection @@ -56,7 +59,7 @@ void client_callback(void *data, int haveIn, int haveOut, int doCleanup) client_haveIn(client); client_haveOut(client); if (client->kill) { - printf("Client killed.\n"); + printf("Client gone (3).\n"); client_free(client); } } @@ -20,7 +20,7 @@ int ePoll_wait(const int timeoutMs) if (num < 0) return -1; for (int i = 0; i < num; ++i) { epoll_item_t *data = (epoll_item_t *)events[i].data.ptr; - (*data->callback)(data, events[i].events & EPOLLIN, events[i].events & EPOLLOUT, events[i].events & (EPOLLERR | EPOLLHUP)); + (*data->callback)(data, events[i].events & EPOLLIN, events[i].events & EPOLLOUT, events[i].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)); } return 0; } @@ -31,6 +31,7 @@ int ePoll_wait(const int timeoutMs) int ePoll_add(uint32_t flags, epoll_item_t* callback) { struct epoll_event event; + memset(&event, 0, sizeof event); event.data.ptr = (void*)callback; event.events = flags; return epoll_ctl(efd, EPOLL_CTL_ADD, callback->fd, &event); @@ -101,7 +101,7 @@ static void listen_callback(void *data, int haveIn, int haveOut, int doCleanup) free(client); return; } - ePoll_add(EPOLLIN | EPOLLOUT | EPOLLET, (epoll_item_t*)client); + ePoll_add(EPOLLIN | EPOLLOUT | EPOLLET | EPOLLRDHUP, (epoll_item_t*)client); } static int loadConfig_handler(void *stuff, const char *section, const char *key, const char *value) |