aboutsummaryrefslogtreecommitdiff
path: root/fdm.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-01-10 18:22:10 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-01-10 18:22:10 +0000
commit698d5fdf06b79b66633629c7a387fa26ff352eca (patch)
treee63f4de5e1c4a8c1227965a33d04fa3c54908968 /fdm.c
parentfcft: bump (diff)
fdm: verify FDs are non-blocking (debug builds only)
Diffstat (limited to 'fdm.c')
-rw-r--r--fdm.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/fdm.c b/fdm.c
index c560d9d6..9ce10cf2 100644
--- a/fdm.c
+++ b/fdm.c
@@ -5,6 +5,8 @@
#include <unistd.h>
#include <errno.h>
#include <assert.h>
+#include <fcntl.h>
+
#include <sys/epoll.h>
#include <tllist.h>
@@ -95,9 +97,17 @@ bool
fdm_add(struct fdm *fdm, int fd, int events, fdm_handler_t handler, void *data)
{
#if defined(_DEBUG)
+ int flags = fcntl(fd, F_GETFL);
+ if (!(flags & O_NONBLOCK)) {
+ LOG_ERR("FD=%d is in blocking mode", fd);
+ assert(false);
+ return false;
+ }
+
tll_foreach(fdm->fds, it) {
if (it->item->fd == fd) {
LOG_ERR("FD=%d already registered", fd);
+ assert(false);
return false;
}
}