summaryrefslogtreecommitdiffstats
path: root/discover
diff options
context:
space:
mode:
Diffstat (limited to 'discover')
-rw-r--r--discover/discover-server.c2
-rw-r--r--discover/pb-discover.c3
-rw-r--r--discover/udev.c2
-rw-r--r--discover/waiter.c83
-rw-r--r--discover/waiter.h23
5 files changed, 4 insertions, 109 deletions
diff --git a/discover/discover-server.c b/discover/discover-server.c
index b2025cc..1fab303 100644
--- a/discover/discover-server.c
+++ b/discover/discover-server.c
@@ -11,12 +11,12 @@
#include <asm/byteorder.h>
#include <talloc/talloc.h>
+#include <waiter/waiter.h>
#include "pb-protocol/pb-protocol.h"
#include "list/list.h"
#include "log.h"
-#include "waiter.h"
#include "device-handler.h"
#include "discover-server.h"
diff --git a/discover/pb-discover.c b/discover/pb-discover.c
index 56602d9..d11ab64 100644
--- a/discover/pb-discover.c
+++ b/discover/pb-discover.c
@@ -2,10 +2,11 @@
#include <stdlib.h>
#include <signal.h>
+#include <waiter/waiter.h>
+
#include "udev.h"
#include "discover-server.h"
#include "device-handler.h"
-#include "waiter.h"
#include "log.h"
static int running;
diff --git a/discover/udev.c b/discover/udev.c
index 6747e78..66d9544 100644
--- a/discover/udev.c
+++ b/discover/udev.c
@@ -10,10 +10,10 @@
#include <sys/un.h>
#include <talloc/talloc.h>
+#include <waiter/waiter.h>
#include "udev.h"
#include "log.h"
-#include "waiter.h"
#include "pb-discover.h"
#include "device-handler.h"
diff --git a/discover/waiter.c b/discover/waiter.c
deleted file mode 100644
index 21dd4a5..0000000
--- a/discover/waiter.c
+++ /dev/null
@@ -1,83 +0,0 @@
-
-#include <poll.h>
-#include <string.h>
-#include <assert.h>
-
-#include <talloc/talloc.h>
-
-#include "waiter.h"
-
-struct waiter {
- int fd;
- int events;
- waiter_cb callback;
- void *arg;
-};
-
-static struct waiter *waiters;
-static int n_waiters;
-
-struct waiter *waiter_register(int fd, int events,
- waiter_cb callback, void *arg)
-{
- struct waiter *waiter;
-
- n_waiters++;
-
- waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters);
- waiter = &waiters[n_waiters - 1];
-
- waiter->fd = fd;
- waiter->events = events;
- waiter->callback = callback;
- waiter->arg = arg;
-
- return 0;
-}
-
-void waiter_remove(struct waiter *waiter)
-{
- int i;
-
- i = waiter - waiters;
- assert(i >= 0 && i < n_waiters);
-
- n_waiters--;
- memmove(&waiters[i], &waiters[i+1], n_waiters - i);
-
- waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters);
-}
-
-int waiter_poll(void)
-{
- static struct pollfd *pollfds;
- static int n_pollfds;
- int i, rc;
-
- if (n_waiters > n_pollfds) {
- pollfds = talloc_realloc(NULL, pollfds,
- struct pollfd, n_waiters);
- }
-
- for (i = 0; i < n_waiters; i++) {
- pollfds[i].fd = waiters[i].fd;
- pollfds[i].events = waiters[i].events;
- pollfds[i].revents = 0;
- }
-
- rc = poll(pollfds, n_waiters, -1);
-
- if (rc <= 0)
- return rc;
-
- for (i = 0; i < n_waiters; i++) {
- if (pollfds[i].revents) {
- rc = waiters[i].callback(waiters[i].arg);
-
- if (rc)
- waiter_remove(&waiters[i]);
- }
- }
-
- return 0;
-}
diff --git a/discover/waiter.h b/discover/waiter.h
deleted file mode 100644
index ff8a5ff..0000000
--- a/discover/waiter.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef _WAITER_H
-#define _WAITER_H
-
-#include <poll.h>
-
-struct waiter;
-
-enum events {
- WAIT_IN = POLLIN,
- WAIT_OUT = POLLOUT,
-};
-
-typedef int (*waiter_cb)(void *);
-
-struct waiter *waiter_register(int fd, int events,
- waiter_cb callback, void *arg);
-
-void waiter_remove(struct waiter *waiter);
-
-int waiter_poll(void);
-#endif /* _WAITER_H */
-
-
OpenPOWER on IntegriCloud