schedulator: only count bugs that you were the *last* one to resolve, but
[wvapps.git] / evolution / wvglibstreamclone.cc
blobde0fddd53e26516f9e3939bad26ecb02139fa79b
1 #include "wvglibstreamclone.h"
2 #include <sys/poll.h>
4 WvGlibStreamClone *WvGlibStreamClone::singleton;
5 GPollFunc WvGlibStreamClone::oldpoll;
8 WvGlibStreamClone::WvGlibStreamClone(GMainContext *_context, IWvStream *_clone)
9 : WvStreamClone(_clone)
11 context = _context;
12 assert(!singleton);
13 singleton = this;
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);
24 singleton = NULL;
28 gint WvGlibStreamClone::mypoll(GPollFD *ufds, guint nfds, gint timeout)
30 SelectInfo si;
31 bool sure = singleton->_build_selectinfo(si, timeout,
32 false, false, false, true);
33 if (sure)
34 si.msec_timeout = 0;
36 GPollFD *newfds = new GPollFD[nfds + si.max_fd + 1], *fp;
37 int newnfds = nfds;
38 memcpy(newfds, ufds, nfds * sizeof(GPollFD));
39 fp = newfds + nfds;
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)
50 fp->fd = fd;
51 fp->events = readme*(POLLIN|POLLPRI)
52 | writeme*POLLOUT | exceptme*POLLERR;
53 fp->revents = 0;
55 fp++;
56 newnfds++;
60 int retval = oldpoll(newfds, newnfds, si.msec_timeout);
62 FD_ZERO(&si.read);
63 FD_ZERO(&si.write);
64 FD_ZERO(&si.except);
66 if (retval > 0)
68 fp = newfds + nfds;
69 for (int i = nfds; i < newnfds; i++)
71 fp = newfds + i;
72 if (fp->revents)
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);
80 retval--;
85 memcpy(ufds, newfds, nfds * sizeof(GPollFD));
86 delete[] newfds;
88 sure = sure || singleton->_process_selectinfo(si, true);
89 if (sure)
90 singleton->callback();
92 return retval;