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/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;
 }