10 #include <sys/timeb.h> 14 # include <winsock2.h> 15 static inline int poll(
struct pollfd *pfd,
int nfds,
int timeout)
17 return WSAPoll(pfd, nfds, timeout);
21 # if defined(_MSC_VER) 23 # define ftime _ftime_s 26 # include <sys/time.h> 58 if (it->getSource() == source)
71 if (it->getSource() == source)
73 it->getMask() = eventMask;
86 const unsigned POLLIN_REQ = POLLIN;
87 const unsigned POLLIN_CHK = (POLLIN | POLLHUP | POLLERR);
88 const unsigned POLLOUT_REQ = POLLOUT;
89 const unsigned POLLOUT_CHK = (POLLOUT | POLLERR);
90 const unsigned POLLEX_CHK = (POLLPRI | POLLNVAL);
96 int timeout_ms =
static_cast<int>(floor(timeout * 1000.));
102 const unsigned source_cnt =
_sources.size();
103 pollfd fds[source_cnt];
106 SourceList::iterator it;
109 sources[i] = it->getSource();
110 fds[i].fd = sources[i]->
getfd();
113 if (it->getMask() &
ReadableEvent) fds[i].events |= POLLIN_REQ;
114 if (it->getMask() &
WritableEvent) fds[i].events |= POLLOUT_REQ;
118 int nEvents = poll(fds, source_cnt, (timeout_ms < 0) ? -1 : timeout_ms);
123 XmlRpcUtil::error(
"Error in XmlRpcDispatch::work: error in poll (%d).", nEvents);
129 for (i=0; i < source_cnt; ++i)
132 pollfd & pfd = fds[i];
133 unsigned newMask = (unsigned) -1;
135 bool readable = (pfd.events & POLLIN_REQ) == POLLIN_REQ;
136 bool writable = (pfd.events & POLLOUT_REQ) == POLLOUT_REQ;
137 if (readable && (pfd.revents & POLLIN_CHK))
139 if (writable && (pfd.revents & POLLOUT_CHK))
141 if (pfd.revents & POLLEX_CHK)
147 SourceList::iterator thisIt;
150 if(thisIt->getSource() == src)
155 XmlRpcUtil::error(
"Error in XmlRpcDispatch::work: couldn't find source iterator");
163 }
else if (newMask != (
unsigned) -1) {
164 thisIt->getMask() = newMask;
173 for (SourceList::iterator it=closeList.begin(); it!=closeList.end(); ++it) {
208 for (SourceList::iterator it=closeList.begin(); it!=closeList.end(); ++it)
209 it->getSource()->close();
221 return ((
double) tbuff.time + ((
double)tbuff.millitm / 1000.0) +
222 ((
double) tbuff.timezone * 60));
227 return ((
double)sec + (
double)nsec / 1e9);
bool getKeepOpen() const
Return whether the file descriptor should be kept open if it is no longer monitored.
connected/data can be written without blocking
ROSTIME_DECL void ros_steadytime(uint32_t &sec, uint32_t &nsec)
void removeSource(XmlRpcSource *source)
static void error(const char *fmt,...)
Dump error messages somewhere.
void clear()
Clear all sources from the monitored sources list. Sources are closed.
int getfd() const
Return the file descriptor being monitored.
virtual void close()
Close the owned fd. If deleteOnClose was specified at construction, the object is deleted...
XmlRpcDispatch()
Constructor.
An RPC source represents a file descriptor to monitor.
void setSourceEvents(XmlRpcSource *source, unsigned eventMask)
Modify the types of events to watch for on this source.
void addSource(XmlRpcSource *source, unsigned eventMask)
std::list< MonitoredSource > SourceList
void exit()
Exit from work routine.
virtual unsigned handleEvent(unsigned eventType)=0
Return true to continue monitoring this source.