1 #include "wvglibstreamclone.h"
4 WvGlibStreamClone
*WvGlibStreamClone::singleton
;
5 GPollFunc
WvGlibStreamClone::oldpoll
;
8 WvGlibStreamClone::WvGlibStreamClone(GMainContext
*_context
, IWvStream
*_clone
)
9 : WvStreamClone(_clone
)
14 oldpoll
= g_main_context_get_poll_func(context
);
15 g_main_context_set_poll_func(context
, mypoll
);
19 WvGlibStreamClone::~WvGlibStreamClone()
21 g_main_context_set_poll_func(context
, oldpoll
);
23 assert(singleton
== this);
28 gint
WvGlibStreamClone::mypoll(GPollFD
*ufds
, guint nfds
, gint timeout
)
31 bool sure
= singleton
->_build_selectinfo(si
, timeout
,
32 false, false, false, true);
36 GPollFD
*newfds
= new GPollFD
[nfds
+ si
.max_fd
+ 1], *fp
;
38 memcpy(newfds
, ufds
, nfds
* sizeof(GPollFD
));
41 // add any wvstream-related file descriptors
42 for (int fd
= 0; fd
<= si
.max_fd
; fd
++)
44 bool readme
= FD_ISSET(fd
, &si
.read
);
45 bool writeme
= FD_ISSET(fd
, &si
.write
);
46 bool exceptme
= FD_ISSET(fd
, &si
.except
);
48 if (readme
|| writeme
|| exceptme
)
51 fp
->events
= readme
*(POLLIN
|POLLPRI
)
52 | writeme
*POLLOUT
| exceptme
*POLLERR
;
60 int retval
= oldpoll(newfds
, newnfds
, si
.msec_timeout
);
69 for (int i
= nfds
; i
< newnfds
; i
++)
74 if (fp
->revents
& (POLLIN
|POLLPRI
))
75 FD_SET(fp
->fd
, &si
.read
);
76 if (fp
->revents
& POLLOUT
)
77 FD_SET(fp
->fd
, &si
.write
);
78 if (fp
->revents
& POLLERR
)
79 FD_SET(fp
->fd
, &si
.except
);
85 memcpy(ufds
, newfds
, nfds
* sizeof(GPollFD
));
88 sure
= sure
|| singleton
->_process_selectinfo(si
, true);
90 singleton
->callback();