summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2009-05-23 06:07:04 +0000
committerHarald Welte <laforge@gnumonks.org>2009-05-23 06:07:04 +0000
commit04d3c9224fa7f1ea78484fc5b56ae6908241213d (patch)
tree8a16630003f3f79869425d2c751d08293cc939ec /src
parent7d14476a6e24535ad43b8304b2dc43dd5a7f67d6 (diff)
An application that has own events and file descriptors, must poll
select function ob libbsc. A "polling" flag is used to enable polling. In this case select() will not sleep until file descriptor events occurr or nearest timer expires. Also a return value will indicate if there was an event that has been handled. If there was an event, the application decides to poll again and don't wait. In case for bsc_hack, the polling flag is not set. select will sleep as usual. (Andreas Eversberg)
Diffstat (limited to 'src')
-rw-r--r--src/bs11_config.c2
-rw-r--r--src/bsc_hack.c2
-rw-r--r--src/ipaccess-config.c2
-rw-r--r--src/ipaccess-find.c2
-rw-r--r--src/select.c20
5 files changed, 16 insertions, 12 deletions
diff --git a/src/bs11_config.c b/src/bs11_config.c
index 3da0c528d..57ed9023e 100644
--- a/src/bs11_config.c
+++ b/src/bs11_config.c
@@ -790,7 +790,7 @@ int main(int argc, char **argv)
status_timer.cb = status_timer_cb;
while (1) {
- bsc_select_main();
+ bsc_select_main(0);
}
abis_nm_bs11_factory_logon(g_bts, 0);
diff --git a/src/bsc_hack.c b/src/bsc_hack.c
index cd3ca4144..797c62783 100644
--- a/src/bsc_hack.c
+++ b/src/bsc_hack.c
@@ -1123,6 +1123,6 @@ int main(int argc, char **argv)
signal(SIGABRT, &signal_handler);
while (1) {
- bsc_select_main();
+ bsc_select_main(0);
}
}
diff --git a/src/ipaccess-config.c b/src/ipaccess-config.c
index 964d6186c..b74e46e89 100644
--- a/src/ipaccess-config.c
+++ b/src/ipaccess-config.c
@@ -188,7 +188,7 @@ int main(int argc, char **argv)
}
while (1) {
- rc = bsc_select_main();
+ rc = bsc_select_main(0);
if (rc < 0)
exit(3);
}
diff --git a/src/ipaccess-find.c b/src/ipaccess-find.c
index 32f42e904..b3e9814a9 100644
--- a/src/ipaccess-find.c
+++ b/src/ipaccess-find.c
@@ -170,7 +170,7 @@ int main(int argc, char **argv)
printf("Trying to find ip.access BTS by broadcast UDP...\n");
while (1) {
- rc = bsc_select_main();
+ rc = bsc_select_main(0);
if (rc < 0)
exit(3);
}
diff --git a/src/select.c b/src/select.c
index 157e23500..11b7e6b49 100644
--- a/src/select.c
+++ b/src/select.c
@@ -53,11 +53,12 @@ void bsc_unregister_fd(struct bsc_fd *fd)
llist_del(&fd->list);
}
-int bsc_select_main()
+int bsc_select_main(int polling)
{
struct bsc_fd *ufd, *tmp;
fd_set readset, writeset, exceptset;
- int i;
+ int work = 0, rc;
+ struct timeval no_time = {0, 0};
FD_ZERO(&readset);
FD_ZERO(&writeset);
@@ -75,10 +76,11 @@ int bsc_select_main()
FD_SET(ufd->fd, &exceptset);
}
- bsc_prepare_timers();
- i = select(maxfd+1, &readset, &writeset, &exceptset, bsc_nearest_timer());
- if (i < 0)
- return i;
+ if (!polling)
+ bsc_prepare_timers();
+ rc = select(maxfd+1, &readset, &writeset, &exceptset, polling ? &no_time : bsc_nearest_timer());
+ if (rc < 0)
+ return 0;
/* fire timers */
bsc_update_timers();
@@ -96,8 +98,10 @@ int bsc_select_main()
if (FD_ISSET(ufd->fd, &exceptset))
flags |= BSC_FD_EXCEPT;
- if (flags)
+ if (flags) {
+ work = 1;
ufd->cb(ufd, flags);
+ }
}
- return i;
+ return work;
}