fdm: verify FDs are non-blocking (debug builds only)

This commit is contained in:
Daniel Eklöf 2020-01-10 19:22:10 +01:00
parent 70f0f02016
commit 698d5fdf06
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

10
fdm.c
View file

@ -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;
}
}