uloop: Add flag to allow callback to be called on error conditions.
authorKarl Vogel <karl.vogel@gmail.com>
Tue, 11 Feb 2014 08:37:08 +0000 (09:37 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 23 Feb 2014 17:18:32 +0000 (18:18 +0100)
In some conditions, an application is interested in errors happening
on a file descriptor and might be able to resolve the issue in the
callback function.

This patch adds a flag to notify the uloop framework that errors
should be passed to the callback function, instead of silently
removing the fd from the polling set.

Signed-off-by: Karl Vogel <karl.vogel@gmail.com>
uloop.c
uloop.h

diff --git a/uloop.c b/uloop.c
index 0566d80e181fe18ec2fd0780bb5f0f9938261d39..d293edb856ea311999d2f8f9157af186cacaa9e0 100644 (file)
--- a/uloop.c
+++ b/uloop.c
@@ -174,7 +174,8 @@ static int uloop_fetch_events(int timeout)
 
                if (events[n].flags & EV_ERROR) {
                        u->error = true;
-                       uloop_fd_delete(u);
+                       if (!(u->flags & ULOOP_ERROR_CB))
+                               uloop_fd_delete(u);
                }
 
                if(events[n].filter == EVFILT_READ)
@@ -268,7 +269,8 @@ static int uloop_fetch_events(int timeout)
 
                if (events[n].events & (EPOLLERR|EPOLLHUP)) {
                        u->error = true;
-                       uloop_fd_delete(u);
+                       if (!(u->flags & ULOOP_ERROR_CB))
+                               uloop_fd_delete(u);
                }
 
                if(!(events[n].events & (EPOLLRDHUP|EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP))) {
diff --git a/uloop.h b/uloop.h
index 98dd8184a4f2fa6e566dd86cfd1b779b2fae7f4d..756451405381015cb02f390ad43298ec02ae1ef8 100644 (file)
--- a/uloop.h
+++ b/uloop.h
@@ -53,6 +53,8 @@ typedef void (*uloop_process_handler)(struct uloop_process *c, int ret);
 #define ULOOP_EDGE_DEFER       (1 << 5)
 #endif
 
+#define ULOOP_ERROR_CB         (1 << 6)
+
 struct uloop_fd
 {
        uloop_fd_handler cb;