… | |
… | |
39 | |
39 | |
40 | time_watcher::~time_watcher () |
40 | time_watcher::~time_watcher () |
41 | { |
41 | { |
42 | if (iom_valid) |
42 | if (iom_valid) |
43 | iom.unreg (this); |
43 | iom.unreg (this); |
|
|
44 | |
|
|
45 | at = TSTAMP_CANCEL; |
44 | } |
46 | } |
45 | |
47 | |
46 | io_watcher::~io_watcher () |
48 | io_watcher::~io_watcher () |
47 | { |
49 | { |
48 | if (iom_valid) |
50 | if (iom_valid) |
… | |
… | |
100 | break; |
102 | break; |
101 | |
103 | |
102 | // call it |
104 | // call it |
103 | w->call (*w); |
105 | w->call (*w); |
104 | |
106 | |
105 | // re-add it if necessary |
|
|
106 | if (w->at >= 0) |
107 | if (w->at < 0) |
107 | reg (w); |
108 | unreg (w); |
108 | } |
109 | } |
109 | |
110 | |
110 | struct timeval to; |
111 | struct timeval to; |
111 | double diff = w->at - NOW; |
112 | double diff = w->at - NOW; |
112 | to.tv_sec = (int)diff; |
113 | to.tv_sec = (int)diff; |
… | |
… | |
118 | FD_ZERO (&wfd); |
119 | FD_ZERO (&wfd); |
119 | |
120 | |
120 | int fds = 0; |
121 | int fds = 0; |
121 | |
122 | |
122 | for (io_watcher **w = iow.begin (); w < iow.end (); ++w) |
123 | for (io_watcher **w = iow.begin (); w < iow.end (); ++w) |
123 | { |
124 | { |
124 | if ((*w)->events & EVENT_READ ) FD_SET ((*w)->fd, &rfd); |
125 | if ((*w)->events & EVENT_READ ) FD_SET ((*w)->fd, &rfd); |
125 | if ((*w)->events & EVENT_WRITE) FD_SET ((*w)->fd, &wfd); |
126 | if ((*w)->events & EVENT_WRITE) FD_SET ((*w)->fd, &wfd); |
126 | |
127 | |
127 | if ((*w)->fd > fds) fds = (*w)->fd; |
128 | if ((*w)->fd > fds) fds = (*w)->fd; |
128 | } |
129 | } |
129 | |
130 | |
130 | fds = select (fds + 1, &rfd, &wfd, 0, &to); |
131 | fds = select (fds + 1, &rfd, &wfd, 0, &to); |
131 | |
132 | |
132 | set_now (); |
133 | set_now (); |
133 | |
134 | |
134 | if (fds > 0) |
135 | if (fds > 0) |
135 | for (io_watcher **w = iow.begin (); w < iow.end (); w++) |
136 | for (io_watcher **w = iow.begin (); w < iow.end (); ++w) |
136 | { |
137 | { |
137 | short revents = (*w)->events; |
138 | short revents = (*w)->events; |
138 | |
139 | |
139 | if (!FD_ISSET ((*w)->fd, &rfd)) revents &= ~EVENT_READ; |
140 | if (!FD_ISSET ((*w)->fd, &rfd)) revents &= ~EVENT_READ; |
140 | if (!FD_ISSET ((*w)->fd, &wfd)) revents &= ~EVENT_WRITE; |
141 | if (!FD_ISSET ((*w)->fd, &wfd)) revents &= ~EVENT_WRITE; |