362c1f4c3b5ce9e3fce11167a51fbe4cdb2174de
Stefan Schuermans implemented base class for...

Stefan Schuermans authored 13 years ago

1) /* Blinker
Stefan Schuermans update copyright header

Stefan Schuermans authored 5 years ago

2)    Copyright 2011-2019 Stefan Schuermans <stefan@blinkenarea.org>
Stefan Schuermans implemented base class for...

Stefan Schuermans authored 13 years ago

3)    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4)    a blinkenarea.org project */
5) 
6) #include <set>
7) #include <sys/select.h>
8) 
9) #include "Io.h"
10) #include "Time.h"
11) 
12) namespace Blinker {
13) 
14) /**
15)  * @brief wait for I/O events
16)  * @param[in] read I/O objects to check for readability
17)  * @param[out] read I/O objects that are readable
18)  * @param[in] write I/O objects to check for writability
19)  * @param[out] write I/O objects that are writable
20)  * @param[in] timeout maximum time to wait
21)  */
22) void Io::wait(Set &read, Set &write, const Time &timeout)
23) {
Stefan Schuermans fix maximum timeout in Io::...

Stefan Schuermans authored 6 years ago

24)   static const Time maxTimeout(1); // maximum timeout for I/O wait
Stefan Schuermans limit maximum timeout for s...

Stefan Schuermans authored 6 years ago

25) 
Stefan Schuermans implemented base class for...

Stefan Schuermans authored 13 years ago

26)   // get maximum file descriptor, read set and write set
27)   int max = 0;
28)   fd_set fd_rd;
29)   FD_ZERO(&fd_rd);
30)   for (Set::const_iterator it = read.begin(); it != read.end(); ++it) {
31)     if ((*it)->m_fd > max)
32)       max = (*it)->m_fd;
33)     FD_SET((*it)->m_fd, &fd_rd);
34)   }
35)   fd_set fd_wr;
36)   FD_ZERO(&fd_wr);
37)   for (Set::const_iterator it = write.begin(); it != write.end(); ++it) {
38)     if ((*it)->m_fd > max)
39)       max = (*it)->m_fd;
40)     FD_SET((*it)->m_fd, &fd_wr);
41)   }
42) 
43)   // get timeout
44)   struct timeval to;
Stefan Schuermans limit maximum timeout for s...

Stefan Schuermans authored 6 years ago

45)   if (timeout < Time::zero) { // don't use negative timeout
Stefan Schuermans do not use negative timeout...

Stefan Schuermans authored 13 years ago

46)     Time::zero.toTimeval(to);
Stefan Schuermans limit maximum timeout for s...

Stefan Schuermans authored 6 years ago

47)   } else if (timeout > maxTimeout) { // stay responsive -> no more than max
48)     maxTimeout.toTimeval(to);
49)   } else {
Stefan Schuermans do not use negative timeout...

Stefan Schuermans authored 13 years ago

50)     timeout.toTimeval(to);
Stefan Schuermans limit maximum timeout for s...

Stefan Schuermans authored 6 years ago

51)   }