1 #ifndef __SOCKET_FDSET_H__
2 #define __SOCKET_FDSET_H__
14 #include "pandabase.h"
15 #include "numeric_types.h"
16 #include "time_base.h"
17 #include "socket_ip.h"
22 inline void setForSocket(
const Socket_IP &incon);
24 inline int WaitForRead(
bool zeroFds, PN_uint32 sleep_time = 0xffffffff);
25 inline int WaitForWrite(
bool zeroFds, PN_uint32 sleep_time = 0xffffffff);
26 inline int WaitForError(
bool zeroFds, PN_uint32 sleep_time = 0xffffffff);
28 inline int WaitForRead(
bool zeroFds,
const Time_Span & timeout);
32 inline void setForSocketNative(
const SOCKET inid);
33 inline bool isSetForNative(
const SOCKET inid)
const;
40 mutable fd_set _the_set;
57 inline void Socket_fdset::setForSocketNative(SOCKET inid)
61 assert(inid < FD_SETSIZE);
64 FD_SET(inid, &_the_set);
75 inline bool Socket_fdset::isSetForNative(SOCKET inid)
const
79 assert(inid < FD_SETSIZE);
82 return (FD_ISSET(inid, &_the_set) != 0);
98 inline int Socket_fdset::WaitForRead(
bool zeroFds, PN_uint32 sleep_time)
101 if (sleep_time == 0xffffffff)
103 retVal = DO_SELECT(_maxid + 1, &_the_set, NULL, NULL, NULL);
107 timeval timeoutValue;
108 timeoutValue.tv_sec = sleep_time / 1000;
109 timeoutValue.tv_usec = (sleep_time % 1000) * 1000;
111 retVal = DO_SELECT(_maxid + 1, &_the_set, NULL, NULL, &timeoutValue);
123 inline int Socket_fdset::WaitForRead(
bool zeroFds,
const Time_Span & timeout)
125 timeval localtv = timeout.GetTval();
127 int retVal = DO_SELECT(_maxid + 1, &_the_set, NULL, NULL, &localtv);
148 inline void Socket_fdset::setForSocket(
const Socket_IP &incon)
162 if (sleep_time == 0xffffffff)
164 retVal = DO_SELECT(_maxid + 1, NULL, &_the_set, NULL, NULL);
168 timeval timeoutValue;
169 timeoutValue.tv_sec = sleep_time / 1000;
170 timeoutValue.tv_usec = (sleep_time % 1000) * 1000;
172 retVal = DO_SELECT(_maxid + 1, NULL, &_the_set, NULL, &timeoutValue);
188 if (sleep_time == 0xffffffff)
190 retVal = DO_SELECT(_maxid + 1, NULL, NULL, &_the_set, NULL);
194 timeval timeoutValue;
195 timeoutValue.tv_sec = sleep_time / 1000;
196 timeoutValue.tv_usec = (sleep_time % 1000) * 1000;
198 retVal = DO_SELECT(_maxid + 1, NULL, NULL, &_the_set, &timeoutValue);
207 #endif //__SOCKET_FDSET_H__
Base functionality for a INET domain Socket this call should be the starting point for all other unix...
Socket_fdset()
The constructor.
bool IsSetFor(const Socket_IP &incon) const
check to see if a socket object has been marked for reading
int WaitForError(bool zeroFds, PN_uint32 sleep_time=0xffffffff)
This is the function that will wait till one of the sockets is in error state.
void clear()
Marks the content as empty.
SOCKET GetSocket()
Gets the base socket type.
int WaitForWrite(bool zeroFds, PN_uint32 sleep_time=0xffffffff)
This is the function that will wait till one of the sockets is ready for writing. ...