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)

diff --git a/include/openbsc/select.h b/include/openbsc/select.h
index b677162..c2af1d7 100644
--- a/include/openbsc/select.h
+++ b/include/openbsc/select.h
@@ -18,5 +18,5 @@
 
 int bsc_register_fd(struct bsc_fd *fd);
 void bsc_unregister_fd(struct bsc_fd *fd);
-int bsc_select_main(void);
+int bsc_select_main(int polling);
 #endif /* _BSC_SELECT_H */
diff --git a/src/bs11_config.c b/src/bs11_config.c
index 3da0c52..57ed902 100644
--- a/src/bs11_config.c
+++ b/src/bs11_config.c
@@ -790,7 +790,7 @@
 	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 cd3ca41..797c627 100644
--- a/src/bsc_hack.c
+++ b/src/bsc_hack.c
@@ -1123,6 +1123,6 @@
 	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 964d618..b74e46e 100644
--- a/src/ipaccess-config.c
+++ b/src/ipaccess-config.c
@@ -188,7 +188,7 @@
 	}
 	
 	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 32f42e9..b3e9814 100644
--- a/src/ipaccess-find.c
+++ b/src/ipaccess-find.c
@@ -170,7 +170,7 @@
 	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 157e235..11b7e6b 100644
--- a/src/select.c
+++ b/src/select.c
@@ -53,11 +53,12 @@
 	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 @@
 			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 @@
 		if (FD_ISSET(ufd->fd, &exceptset))
 			flags |= BSC_FD_EXCEPT;
 
-		if (flags)
+		if (flags) {
+			work = 1;
 			ufd->cb(ufd, flags);
+		}
 	}
-	return i;
+	return work;
 }
diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c
index 339404e..26fcbc9 100644
--- a/tests/timer/timer_test.c
+++ b/tests/timer/timer_test.c
@@ -65,6 +65,6 @@
     bsc_schedule_timer(&timer_three, 4, 0);
 
     while (1) {
-        bsc_select_main();
+        bsc_select_main(0);
     }
 }