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)
This commit is contained in:
Harald Welte 2009-05-23 06:07:04 +00:00
parent 7d14476a6e
commit 04d3c9224f
7 changed files with 18 additions and 14 deletions

View File

@ -18,5 +18,5 @@ struct bsc_fd {
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 */

View File

@ -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);

View File

@ -1123,6 +1123,6 @@ int main(int argc, char **argv)
signal(SIGABRT, &signal_handler);
while (1) {
bsc_select_main();
bsc_select_main(0);
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

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

View File

@ -65,6 +65,6 @@ int main(int argc, char** argv)
bsc_schedule_timer(&timer_three, 4, 0);
while (1) {
bsc_select_main();
bsc_select_main(0);
}
}