1 | /* |
1 | /* |
2 | iom.h -- generic I/O multiplexor |
2 | iom.h -- generic I/O multiplexer |
3 | Copyright (C) 2003, 2004 Marc Lehmann <pcg@goof.com> |
3 | Copyright (C) 2003, 2004 Marc Lehmann <pcg@goof.com> |
4 | |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
… | |
… | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
13 | GNU General Public License for more details. |
14 | |
14 | |
15 | You should have received a copy of the GNU General Public License |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | */ |
18 | */ |
19 | |
19 | |
20 | #ifndef IOM_H__ |
20 | #ifndef IOM_H__ |
21 | #define IOM_H__ |
21 | #define IOM_H__ |
22 | |
22 | |
… | |
… | |
64 | struct sig_watcher; |
64 | struct sig_watcher; |
65 | #endif |
65 | #endif |
66 | |
66 | |
67 | template<class watcher> |
67 | template<class watcher> |
68 | struct io_manager_vec : vector<watcher *> { |
68 | struct io_manager_vec : vector<watcher *> { |
69 | #if IOM_CHECK |
|
|
70 | bool activity; |
|
|
71 | #endif |
|
|
72 | |
|
|
73 | void erase_unordered (unsigned int pos) |
69 | void erase_unordered (unsigned int pos) |
74 | { |
70 | { |
75 | watcher *w = (*this)[this->size () - 1]; |
71 | watcher *w = (*this)[this->size () - 1]; |
76 | this->pop_back (); |
72 | this->pop_back (); |
77 | |
73 | |
78 | if (this->size ()) |
74 | if (!this->empty ()) |
79 | if ((*this)[pos] = w) |
75 | if (((*this)[pos] = w)) // '=' is correct! |
80 | w->active = pos + 1; |
76 | w->active = pos + 1; |
81 | } |
77 | } |
82 | }; |
78 | }; |
83 | |
79 | |
84 | // only used as a namespace, and for initialisation purposes |
80 | // only used as a namespace, and for initialisation purposes |
… | |
… | |
88 | |
84 | |
89 | template<class watcher> |
85 | template<class watcher> |
90 | static void unreg (watcher &w, io_manager_vec<watcher> &queue); |
86 | static void unreg (watcher &w, io_manager_vec<watcher> &queue); |
91 | |
87 | |
92 | public: |
88 | public: |
|
|
89 | #if IOM_TIME |
|
|
90 | // fetch time only |
|
|
91 | static tstamp now (); |
|
|
92 | |
|
|
93 | // set NOW |
|
|
94 | static void set_now (); |
|
|
95 | #endif |
|
|
96 | |
93 | // register a watcher |
97 | // register a watcher |
94 | #if IOM_IO |
98 | #if IOM_IO |
95 | static void reg (io_watcher &w); static void unreg (io_watcher &w); |
99 | static void reg (io_watcher &w); static void unreg (io_watcher &w); |
96 | #endif |
100 | #endif |
97 | #if IOM_TIME |
101 | #if IOM_TIME |