From 697573cbaf40b3bd265bd88b1383bbc779306e11 Mon Sep 17 00:00:00 2001 From: Fred Nicolson Date: Mon, 19 Nov 2018 16:02:07 +0000 Subject: [PATCH] Don't throw an exception if epoll_wait is interrupted --- include/frnetlib/SocketSelector.h | 3 ++- src/SocketSelector.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/frnetlib/SocketSelector.h b/include/frnetlib/SocketSelector.h index 99e1e88..b39e012 100644 --- a/include/frnetlib/SocketSelector.h +++ b/include/frnetlib/SocketSelector.h @@ -39,7 +39,8 @@ namespace fr * * @throws An std::exception on failure * @param timeout The maximum time in milliseconds to wait for. Default/-1 for no timeout. - * @return A list of sockets which either are ready, or have disconnected. + * @return A list of sockets which either are ready, or have disconnected. This can be empty + * if there is a timeout, or the wait is interrupted. */ std::vector, void*>> wait(std::chrono::milliseconds timeout = std::chrono::milliseconds(-1)); diff --git a/src/SocketSelector.cpp b/src/SocketSelector.cpp index 7a4f4fc..5e6f2c6 100644 --- a/src/SocketSelector.cpp +++ b/src/SocketSelector.cpp @@ -57,6 +57,10 @@ namespace fr int event_count = epoll_wait(epoll_fd, events, 100, timeout.count()); if(event_count < 0) { + if(errno == EINTR) + { + return {}; + } throw std::runtime_error("epoll_wait returned: " + std::to_string(errno)); }