22 #include "wvqtstreamclone.moc"
26 #define NUM_SLOTS 41 // must be prime
30 pending_callback(false), first_time(true), select_in_progress(false),
32 notify_readable(NUM_SLOTS),
33 notify_writable(NUM_SLOTS),
34 notify_exception(NUM_SLOTS)
38 notify_readable.setAutoDelete(
true);
39 notify_writable.setAutoDelete(
true);
40 notify_exception.setAutoDelete(
true);
45 WvQtStreamClone::~WvQtStreamClone()
50 void WvQtStreamClone::pre_poll()
53 _build_selectinfo(si, msec_timeout,
54 false,
false,
false,
true);
60 if (si.msec_timeout >= 0)
61 select_timer.start(si.msec_timeout,
true );
65 for (
int fd = 0; fd <= si.max_fd; ++fd)
67 if (FD_ISSET(fd, &si.read))
69 QSocketNotifier *n = notify_readable.find(fd);
72 n =
new QSocketNotifier(fd, QSocketNotifier::Read);
73 notify_readable.insert(fd, n);
74 QObject::connect(n, SIGNAL(activated(
int)),
75 this, SLOT(fd_readable(
int)));
78 notify_readable.remove(fd);
80 if (FD_ISSET(fd, &si.write))
82 QSocketNotifier *n = notify_writable.find(fd);
85 n =
new QSocketNotifier(fd, QSocketNotifier::Write);
86 notify_writable.insert(fd, n);
87 QObject::connect(n, SIGNAL(activated(
int)),
88 this, SLOT(fd_writable(
int)));
91 notify_writable.remove(fd);
93 if (FD_ISSET(fd, &si.except))
95 QSocketNotifier *n = notify_exception.find(fd);
98 n =
new QSocketNotifier(fd, QSocketNotifier::Exception);
99 notify_exception.insert(fd, n);
100 QObject::connect(n, SIGNAL(activated(
int)),
101 this, SLOT(fd_exception(
int)));
104 notify_exception.remove(fd);
108 for (
int fd = si.max_fd + 1; fd <= last_max_fd; ++fd)
110 notify_readable.remove(fd);
111 notify_writable.remove(fd);
112 notify_exception.remove(fd);
114 last_max_fd = si.max_fd;
123 void WvQtStreamClone::post_poll()
126 bool sure = _process_selectinfo(si,
true);
127 if (sure || pending_callback)
129 pending_callback =
false;
131 if (globalstream) globalstream->
callback();
136 void WvQtStreamClone::set_timeout(
int msec_timeout)
138 this->msec_timeout = msec_timeout;
142 void WvQtStreamClone::qt_begin_event_loop_hook()
145 if (select_in_progress)
return;
154 select_in_progress =
true;
158 void WvQtStreamClone::qt_detach()
163 select_in_progress =
false;
170 notify_readable.clear();
171 notify_writable.clear();
172 notify_exception.clear();
173 QObject::disconnect(qApp, SIGNAL(guiThreadAwake()),
174 this, SLOT(qt_begin_event_loop_hook()));
175 QObject::disconnect(& select_timer, SIGNAL(timeout()),
176 this, SLOT(select_timer_expired()));
180 void WvQtStreamClone::qt_attach()
183 QObject::connect(qApp, SIGNAL(guiThreadAwake()),
184 this, SLOT(qt_begin_event_loop_hook()));
185 QObject::connect(& select_timer, SIGNAL(timeout()),
186 this, SLOT(select_timer_expired()));
190 void WvQtStreamClone::select_timer_expired()
192 select_in_progress =
false;
196 void WvQtStreamClone::fd_readable(
int fd)
198 FD_SET(fd, &si.read);
199 pending_callback =
true;
200 select_in_progress =
false;
204 void WvQtStreamClone::fd_writable(
int fd)
206 FD_SET(fd, &si.write);
207 pending_callback =
true;
208 select_in_progress =
false;
212 void WvQtStreamClone::fd_exception(
int fd)
214 FD_SET(fd, &si.except);
215 pending_callback =
true;
216 select_in_progress =
false;
219 void WvQtStreamClone::execute()
229 if (newclone != NULL)
230 my_type =
WvString(
"WvQtStreamClone:%s", newclone->wstype());
232 my_type =
"WvQtStreamClone:(none)";