2 #include "ns3/nstime.h"
18 int dce_poll (
struct pollfd *fds, nfds_t nfds,
int timeout)
24 std::map <int, FileUsage*> toUnRef;
26 NS_LOG_FUNCTION (current <<
UtilsGetNodeId () << fds << nfds << timeout);
30 NS_ASSERT (current != 0);
39 endtime = Now () + MilliSeconds (timeout);
42 for (uint32_t i = 0; i < nfds; ++i)
51 for (uint32_t i = 0; i < nfds; ++i)
62 toUnRef[fds[i].fd] = fu;
63 currentTable->
SetEventMask (fds[i].events | POLLERR | POLLHUP);
70 int mask = unixFd->
Poll (currentTable);
72 mask &= (fds[i].events | POLLERR | POLLHUP);
73 fds[i].revents = mask;
83 if (count || timed_out)
93 table->
Wait (Seconds (0));
98 Time diff = endtime - Now ();
99 if (diff.IsStrictlyPositive ())
116 for (std::map <int, FileUsage*>::iterator i = toUnRef.begin ();
117 i != toUnRef.end (); ++i)
119 i->second->DecUsage ();
123 if ((0 == count) && (0 == timeout))
131 int dce_select (
int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
132 struct timeval *timeout)
135 NS_LOG_FUNCTION (current <<
UtilsGetNodeId () << nfds << timeout);
136 NS_ASSERT (current != 0);
137 std::map <int, int> eventByFd;
141 current->
err = EINVAL;
144 if (readfds == 0 && writefds == 0 && exceptfds == 0)
146 current->
err = EINVAL;
151 if (timeout->tv_sec < 0 || timeout->tv_usec < 0)
153 current->
err = EINVAL;
157 for (
int fd = 0; fd < nfds; fd++)
161 if (readfds != 0 && FD_ISSET (fd, readfds))
165 if (writefds != 0 && FD_ISSET (fd, writefds))
169 if (exceptfds != 0 && FD_ISSET (fd, exceptfds))
178 current->
err = EBADF;
181 eventByFd[fd] = event;
184 nfds = eventByFd.size ();
192 struct pollfd pollFd[nfds];
195 for (std::map<int, int>::iterator i = eventByFd.begin (); i != eventByFd.end (); ++i)
197 pollFd[j].events = (*i).second;
198 pollFd[j].fd = (*i).first;
199 pollFd[j++].revents = 0;
206 pollTo = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
209 int pollRet =
dce_poll (pollFd, nfds, pollTo);
227 for (j = 0; j < nfds; j++)
229 if (readfds && ((POLLIN & pollFd[j].revents) || (POLLHUP & pollFd[j].revents)
230 || (POLLERR & pollFd[j].revents)))
232 FD_SET (pollFd[j].fd, readfds);
235 if (writefds && (POLLOUT & pollFd[j].revents))
237 FD_SET (pollFd[j].fd, writefds);
240 if (exceptfds && (POLLPRI & pollFd[j].revents))
242 FD_SET (pollFd[j].fd, exceptfds);