summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiri Pirko <jiri@resnulli.us>2013-06-07 08:37:43 +0200
committerJiri Pirko <jiri@resnulli.us>2013-06-07 08:47:56 +0200
commite9666098cb6b0c9e8fcfaef2f643f1eae4909f89 (patch)
treec454fbd86b9e31bd338df2ad4a38a54c0c62151c
parentca3c399c269e30d4d0ed384d36b4ed1f00e8f4b2 (diff)
downloadlibndp-e9666098cb6b0c9e8fcfaef2f643f1eae4909f89.tar.gz
libndp: add ndp_callall_eventfd_handler()
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
-rw-r--r--include/ndp.h1
-rw-r--r--libndp/libndp.c34
2 files changed, 35 insertions, 0 deletions
diff --git a/include/ndp.h b/include/ndp.h
index d6603f4..423181d 100644
--- a/include/ndp.h
+++ b/include/ndp.h
@@ -167,6 +167,7 @@ void ndp_msgrcv_handler_unregister(struct ndp *ndp, ndp_msgrcv_handler_func_t fu
int ndp_get_eventfd(struct ndp *ndp);
int ndp_call_eventfd_handler(struct ndp *ndp);
+int ndp_callall_eventfd_handler(struct ndp *ndp);
int ndp_open(struct ndp **p_ndp);
void ndp_close(struct ndp *ndp);
diff --git a/libndp/libndp.c b/libndp/libndp.c
index 661c729..1b38907 100644
--- a/libndp/libndp.c
+++ b/libndp/libndp.c
@@ -25,6 +25,7 @@
#include <errno.h>
#include <ctype.h>
#include <sys/socket.h>
+#include <sys/select.h>
#include <netinet/in.h>
#include <netinet/icmp6.h>
#include <arpa/inet.h>
@@ -1697,6 +1698,39 @@ int ndp_call_eventfd_handler(struct ndp *ndp)
return ndp_sock_recv(ndp);
}
+/**
+ * ndp_callall_eventfd_handler:
+ * @ndp: libndp library context
+ *
+ * Call all pending events on eventfd handler.
+ *
+ * Returns: zero on success or negative number in case of an error.
+ **/
+NDP_EXPORT
+int ndp_callall_eventfd_handler(struct ndp *ndp)
+{
+ fd_set rfds;
+ int fdmax;
+ struct timeval tv;
+ int fd = ndp_get_eventfd(ndp);
+ int ret;
+ int err;
+
+ memset(&tv, 0, sizeof(tv));
+ FD_ZERO(&rfds);
+ FD_SET(fd, &rfds);
+ fdmax = fd + 1;
+ while (true) {
+ ret = select(fdmax, &rfds, NULL, NULL, &tv);
+ if (ret == -1)
+ return -errno;
+ if (!FD_ISSET(fd, &rfds))
+ return 0;
+ err = ndp_call_eventfd_handler(ndp);
+ if (err)
+ return err;
+ }
+}
/**
* SECTION: Exported context functions