1 #ifndef __SOCKET_FDSET_H__ 2 #define __SOCKET_FDSET_H__ 13 #include "time_base.h" 14 #include "socket_ip.h" 19 inline void setForSocket(
const Socket_IP &incon);
21 inline int WaitForRead(
bool zeroFds, uint32_t sleep_time = 0xffffffff);
22 inline int WaitForWrite(
bool zeroFds, uint32_t sleep_time = 0xffffffff);
23 inline int WaitForError(
bool zeroFds, uint32_t sleep_time = 0xffffffff);
25 inline int WaitForRead(
bool zeroFds,
const Time_Span & timeout);
29 inline void setForSocketNative(
const SOCKET inid);
30 inline bool isSetForNative(
const SOCKET inid)
const;
37 mutable fd_set _the_set;
52 inline void Socket_fdset::setForSocketNative(SOCKET inid)
56 assert(inid < FD_SETSIZE);
59 FD_SET(inid, &_the_set);
68 inline bool Socket_fdset::isSetForNative(SOCKET inid)
const 72 assert(inid < FD_SETSIZE);
75 return (FD_ISSET(inid, &_the_set) != 0);
89 inline int Socket_fdset::WaitForRead(
bool zeroFds, uint32_t sleep_time)
92 if (sleep_time == 0xffffffff) {
93 retVal = DO_SELECT(_maxid + 1, &_the_set,
nullptr,
nullptr,
nullptr);
96 timeoutValue.tv_sec = sleep_time / 1000;
97 timeoutValue.tv_usec = (sleep_time % 1000) * 1000;
99 retVal = DO_SELECT(_maxid + 1, &_the_set,
nullptr,
nullptr, &timeoutValue);
110 inline int Socket_fdset::WaitForRead(
bool zeroFds,
const Time_Span & timeout)
112 timeval localtv = timeout.GetTval();
114 int retVal = DO_SELECT(_maxid + 1, &_the_set,
nullptr,
nullptr, &localtv);
133 inline void Socket_fdset::setForSocket(
const Socket_IP &incon)
145 if (sleep_time == 0xffffffff)
147 retVal = DO_SELECT(_maxid + 1,
nullptr, &_the_set,
nullptr,
nullptr);
151 timeval timeoutValue;
152 timeoutValue.tv_sec = sleep_time / 1000;
153 timeoutValue.tv_usec = (sleep_time % 1000) * 1000;
155 retVal = DO_SELECT(_maxid + 1,
nullptr, &_the_set,
nullptr, &timeoutValue);
170 if (sleep_time == 0xffffffff)
172 retVal = DO_SELECT(_maxid + 1,
nullptr,
nullptr, &_the_set,
nullptr);
176 timeval timeoutValue;
177 timeoutValue.tv_sec = sleep_time / 1000;
178 timeoutValue.tv_usec = (sleep_time % 1000) * 1000;
180 retVal = DO_SELECT(_maxid + 1,
nullptr,
nullptr, &_the_set, &timeoutValue);
189 #endif //__SOCKET_FDSET_H__ int WaitForWrite(bool zeroFds, uint32_t sleep_time=0xffffffff)
This is the function that will wait till one of the sockets is ready for writing.
int WaitForError(bool zeroFds, uint32_t sleep_time=0xffffffff)
This is the function that will wait till one of the sockets is in error state.
Base functionality for a INET domain Socket This call should be the starting point for all other unix...
Socket_fdset()
The constructor.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool IsSetFor(const Socket_IP &incon) const
check to see if a socket object has been marked for reading
void clear()
Marks the content as empty.
SOCKET GetSocket()
Gets the base socket type.