summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiri Pirko <jiri@resnulli.us>2013-03-29 17:02:38 +0100
committerJiri Pirko <jiri@resnulli.us>2013-03-29 17:05:32 +0100
commitca3dae8b39c6fdd6fced4fb3f828342e781fcdcf (patch)
tree9374f9a40d28bb565b1e2fc29d84e7485d028ae4
parent94ac6837a35b2a4aaf30f01fb919fc90ee88ac1e (diff)
downloadlibndp-ca3dae8b39c6fdd6fced4fb3f828342e781fcdcf.tar.gz
libndp: remove unnecessary evenfd struct and handle all by single event fd
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
-rw-r--r--include/ndp.h11
-rw-r--r--libndp/libndp.c45
-rw-r--r--utils/ndptool.c26
3 files changed, 18 insertions, 64 deletions
diff --git a/include/ndp.h b/include/ndp.h
index f46fe77..de1ea58 100644
--- a/include/ndp.h
+++ b/include/ndp.h
@@ -127,15 +127,8 @@ void ndp_msgrcv_handler_unregister(struct ndp *ndp, ndp_msgrcv_handler_func_t fu
enum ndp_msg_type msg_type, uint32_t ifindex,
void *priv);
-struct ndp_eventfd;
-
-struct ndp_eventfd *ndp_get_next_eventfd(struct ndp *ndp,
- struct ndp_eventfd *eventfd);
-#define ndp_for_each_event_fd(eventfd, ndp) \
- for (eventfd = ndp_get_next_eventfd(ndp, NULL); eventfd; \
- eventfd = ndp_get_next_eventfd(ndp, eventfd))
-int ndp_get_eventfd_fd(struct ndp *ndp, struct ndp_eventfd *eventfd);
-int ndp_call_eventfd_handler(struct ndp *ndp, struct ndp_eventfd *eventfd);
+int ndp_get_eventfd(struct ndp *ndp);
+int ndp_call_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 ad58d0b..159986a 100644
--- a/libndp/libndp.c
+++ b/libndp/libndp.c
@@ -1350,67 +1350,32 @@ void ndp_msgrcv_handler_unregister(struct ndp *ndp, ndp_msgrcv_handler_func_t fu
* @short_description: event filedescriptor related stuff
*/
-struct ndp_eventfd {
- int (*get_fd)(struct ndp *ndp);
- int (*event_handler)(struct ndp *ndp);
-};
-
-static int ndp_sock_fd(struct ndp *ndp)
-{
- return ndp->sock;
-}
-
-static struct ndp_eventfd ndp_eventfd = {
- .get_fd = ndp_sock_fd,
- .event_handler = ndp_sock_recv,
-};
-
/**
- * ndp_get_next_eventfd:
+ * ndp_get_eventfd:
* @ndp: libndp library context
- * @eventfd: eventfd structure
- *
- * Get next eventfd in list.
- *
- * Returns: eventfd next to @eventfd passed.
- **/
-NDP_EXPORT
-struct ndp_eventfd *ndp_get_next_eventfd(struct ndp *ndp,
- struct ndp_eventfd *eventfd)
-{
- if (eventfd)
- return NULL;
- return &ndp_eventfd;
-}
-
-/**
- * ndp_get_eventfd_fd:
- * @ndp: libndp library context
- * @eventfd: eventfd structure
*
* Get eventfd filedesctiptor.
*
* Returns: fd.
**/
NDP_EXPORT
-int ndp_get_eventfd_fd(struct ndp *ndp, struct ndp_eventfd *eventfd)
+int ndp_get_eventfd(struct ndp *ndp)
{
- return eventfd->get_fd(ndp);
+ return ndp->sock;
}
/**
* ndp_call_eventfd_handler:
* @ndp: libndp library context
- * @eventfd: eventfd structure
*
* Call eventfd handler.
*
* Returns: zero on success or negative number in case of an error.
**/
NDP_EXPORT
-int ndp_call_eventfd_handler(struct ndp *ndp, struct ndp_eventfd *eventfd)
+int ndp_call_eventfd_handler(struct ndp *ndp)
{
- return eventfd->event_handler(ndp);
+ return ndp_sock_recv(ndp);
}
diff --git a/utils/ndptool.c b/utils/ndptool.c
index 904a627..dddb402 100644
--- a/utils/ndptool.c
+++ b/utils/ndptool.c
@@ -57,9 +57,9 @@ static int run_main_loop(struct ndp *ndp)
fd_set rfds_tmp;
int fdmax;
int ret;
- struct ndp_eventfd *eventfd;
sigset_t mask;
int sfd;
+ int ndp_fd;
int err = 0;
sigemptyset(&mask);
@@ -82,13 +82,10 @@ static int run_main_loop(struct ndp *ndp)
FD_SET(sfd, &rfds);
fdmax = sfd;
- ndp_for_each_event_fd(eventfd, ndp) {
- int fd = ndp_get_eventfd_fd(ndp, eventfd);
-
- FD_SET(fd, &rfds);
- if (fd > fdmax)
- fdmax = fd;
- }
+ ndp_fd = ndp_get_eventfd(ndp);
+ FD_SET(ndp_fd, &rfds);
+ if (ndp_fd > fdmax)
+ fdmax = ndp_fd;
fdmax++;
for (;;) {
@@ -121,13 +118,12 @@ static int run_main_loop(struct ndp *ndp)
}
}
- ndp_for_each_event_fd(eventfd, ndp) {
- if (FD_ISSET(ndp_get_eventfd_fd(ndp, eventfd), &rfds_tmp))
- err = ndp_call_eventfd_handler(ndp, eventfd);
- if (err) {
- pr_err("ndp eventfd handler call failed\n");
- return err;
- }
+ if (FD_ISSET(ndp_fd, &rfds_tmp)) {
+ err = ndp_call_eventfd_handler(ndp);
+ if (err) {
+ pr_err("ndp eventfd handler call failed\n");
+ return err;
+ }
}
}
out: