mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-12 05:34:01 -04:00
fdm: verify FDs are non-blocking (debug builds only)
This commit is contained in:
parent
70f0f02016
commit
698d5fdf06
1 changed files with 10 additions and 0 deletions
10
fdm.c
10
fdm.c
|
|
@ -5,6 +5,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
|
|
||||||
#include <tllist.h>
|
#include <tllist.h>
|
||||||
|
|
@ -95,9 +97,17 @@ bool
|
||||||
fdm_add(struct fdm *fdm, int fd, int events, fdm_handler_t handler, void *data)
|
fdm_add(struct fdm *fdm, int fd, int events, fdm_handler_t handler, void *data)
|
||||||
{
|
{
|
||||||
#if defined(_DEBUG)
|
#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) {
|
tll_foreach(fdm->fds, it) {
|
||||||
if (it->item->fd == fd) {
|
if (it->item->fd == fd) {
|
||||||
LOG_ERR("FD=%d already registered", fd);
|
LOG_ERR("FD=%d already registered", fd);
|
||||||
|
assert(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue