10 #include <sys/timeb.h>
13 # include <winsock2.h>
14 static int poll(
struct pollfd *pfd,
int nfds,
int timeout)
25 for (
int i = 0; i < nfds; ++i)
27 if (pfd[i].events & POLLOUT)
29 FD_SET(pfd[i].fd, &writable);
30 FD_SET(pfd[i].fd, &error);
34 int connectionError = 0;
35 if (writable.fd_count > 0)
37 int result = select(0,
nullptr, &writable, &error,
nullptr);
38 if (SOCKET_ERROR == result)
45 for (
int i = 0; i < nfds; ++i)
47 if ((pfd[i].events & POLLOUT) &&
48 (FD_ISSET(pfd[i].fd, &error)))
56 if (connectionError == nfds)
63 return WSAPoll(pfd, nfds, timeout);
68 # if defined(_MSC_VER)
70 # define ftime _ftime_s
73 # include <sys/poll.h>
74 # include <sys/time.h>
106 if (it->getSource() == source)
119 if (it->getSource() == source)
121 it->getMask() = eventMask;
134 const unsigned POLLIN_REQ = POLLIN;
135 const unsigned POLLIN_CHK = (POLLIN | POLLHUP | POLLERR);
136 const unsigned POLLOUT_REQ = POLLOUT;
137 const unsigned POLLOUT_CHK = (POLLOUT | POLLERR);
138 #if !defined(_WINDOWS)
139 const unsigned POLLEX_REQ = POLLPRI;
140 const unsigned POLLEX_CHK = (POLLPRI | POLLNVAL);
142 const unsigned POLLEX_REQ = POLLRDBAND;
143 const unsigned POLLEX_CHK = (POLLRDBAND | POLLNVAL);
150 int timeout_ms =
static_cast<int>(floor(timeout * 1000.));
156 const unsigned source_cnt =
_sources.size();
157 std::vector<pollfd> fds(source_cnt);
158 std::vector<XmlRpcSource *> sources(source_cnt);
160 SourceList::iterator it;
163 sources[i] = it->getSource();
164 fds[i].fd = sources[i]->getfd();
167 if (it->getMask() &
ReadableEvent) fds[i].events |= POLLIN_REQ;
168 if (it->getMask() &
WritableEvent) fds[i].events |= POLLOUT_REQ;
169 if (it->getMask() &
Exception) fds[i].events |= POLLEX_REQ;
173 int nEvents = poll(&fds[0], source_cnt, (timeout_ms < 0) ? -1 : timeout_ms);
177 #if defined(_WINDOWS)
178 XmlRpcUtil::error(
"Error in XmlRpcDispatch::work: error in poll (%d).", WSAGetLastError());
184 XmlRpcUtil::error(
"Error in XmlRpcDispatch::work: error in poll (%d).", nEvents);
194 for (i=0; i < source_cnt; ++i)
197 pollfd & pfd = fds[i];
198 unsigned newMask = (unsigned) -1;
200 bool readable = (pfd.events & POLLIN_REQ) == POLLIN_REQ;
201 bool writable = (pfd.events & POLLOUT_REQ) == POLLOUT_REQ;
202 bool oob = (pfd.events & POLLEX_REQ) == POLLEX_REQ;
203 if (readable && (pfd.revents & POLLIN_CHK))
205 if (writable && (pfd.revents & POLLOUT_CHK))
207 if (oob && (pfd.revents & POLLEX_CHK))
213 SourceList::iterator thisIt;
216 if(thisIt->getSource() == src)
221 XmlRpcUtil::error(
"Error in XmlRpcDispatch::work: couldn't find source iterator");
229 }
else if (newMask != (
unsigned) -1) {
230 thisIt->getMask() = newMask;
239 for (SourceList::iterator it=closeList.begin(); it!=closeList.end(); ++it) {
274 for (SourceList::iterator it=closeList.begin(); it!=closeList.end(); ++it)
275 it->getSource()->close();
287 return ((
double) tbuff.time + ((
double)tbuff.millitm / 1000.0) +
288 ((
double) tbuff.timezone * 60));
293 return ((
double)sec + (
double)nsec / 1e9);