version 1.1.2.1, 2001/07/26 17:19:09
|
version 1.1.2.2, 2001/07/26 20:34:06
|
|
|
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
// | // |
// Local routines: |
|
// |
|
//////////////////////////////////////////////////////////////////////////////// |
|
|
|
static inline int select_wrapper( |
|
int nfds, |
|
fd_set* rd_fd_set, |
|
fd_set* wr_fd_set, |
|
fd_set* ex_fd_set, |
|
const struct timeval* tv) |
|
{ |
|
return select(FD_SETSIZE, rd_fd_set, wr_fd_set, ex_fd_set, tv); |
|
} |
|
|
|
//////////////////////////////////////////////////////////////////////////////// |
|
// |
|
// Routines for starting and stoping socket interface. | // Routines for starting and stoping socket interface. |
// | // |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
| |
extern Uint32 _socketInterfaceInitCount; | extern Uint32 _socketInterfaceInitCount; |
| |
static void _SocketInterfaceInc() |
static void _OpenSocketInterface() |
{ | { |
if (_socketInterfaceInitCount == 0) | if (_socketInterfaceInitCount == 0) |
{ | { |
|
|
_socketInterfaceInitCount++; | _socketInterfaceInitCount++; |
} | } |
| |
static void _SocketInterfaceDec() |
static void _CloseSocketInterface() |
{ | { |
_socketInterfaceInitCount--; | _socketInterfaceInitCount--; |
| |
|
|
| |
Monitor::Monitor() | Monitor::Monitor() |
{ | { |
_SocketInterfaceInc(); |
_OpenSocketInterface(); |
| |
_rep = new MonitorRep; | _rep = new MonitorRep; |
FD_ZERO(&_rep->rd_fd_set); | FD_ZERO(&_rep->rd_fd_set); |
|
|
FD_ZERO(&_rep->active_ex_fd_set); | FD_ZERO(&_rep->active_ex_fd_set); |
} | } |
| |
MonitorHandler::~MonitorHandler() |
|
{ |
|
_SocketInterfaceDec(); |
|
} |
|
|
|
Monitor::~Monitor() | Monitor::~Monitor() |
{ | { |
delete _rep; |
_CloseSocketInterface(); |
} | } |
| |
Boolean Monitor::select(Uint32 milliseconds) |
Boolean Monitor::run(Uint32 milliseconds) |
{ | { |
// Windows select() has a strange little bug. It returns immediately if | // Windows select() has a strange little bug. It returns immediately if |
// there are no descriptors in the set even if the timeout is non-zero. | // there are no descriptors in the set even if the timeout is non-zero. |
|
|
const Uint32 USEC = (milliseconds % 1000) * 1000; | const Uint32 USEC = (milliseconds % 1000) * 1000; |
struct timeval tv = { SEC, USEC }; | struct timeval tv = { SEC, USEC }; |
| |
count = select_wrapper( |
count = select( |
FD_SETSIZE, | FD_SETSIZE, |
&_rep->active_rd_fd_set, | &_rep->active_rd_fd_set, |
&_rep->active_wr_fd_set, | &_rep->active_wr_fd_set, |
|
|
Uint32 events = 0; | Uint32 events = 0; |
| |
if (FD_ISSET(socket, &_rep->active_rd_fd_set)) | if (FD_ISSET(socket, &_rep->active_rd_fd_set)) |
events |= READ; |
events |= SocketMessage::READ; |
| |
if (FD_ISSET(socket, &_rep->active_wr_fd_set)) | if (FD_ISSET(socket, &_rep->active_wr_fd_set)) |
events |= WRITE; |
events |= SocketMessage::WRITE; |
| |
if (FD_ISSET(socket, &_rep->active_ex_fd_set)) | if (FD_ISSET(socket, &_rep->active_ex_fd_set)) |
events |= EXCEPTION; |
events |= SocketMessage::EXCEPTION; |
| |
if (events) | if (events) |
{ | { |
|
|
if (!queue) | if (!queue) |
unsolicitSocketMessages(_entries[i].queueId); | unsolicitSocketMessages(_entries[i].queueId); |
| |
if (events & WRITE) |
if (events & SocketMessage::WRITE) |
{ | { |
FD_CLR(socket, &_rep->active_wr_fd_set); | FD_CLR(socket, &_rep->active_wr_fd_set); |
} | } |
| |
if (events & EXCEPTION) |
if (events & SocketMessage::EXCEPTION) |
{ | { |
FD_CLR(socket, &_rep->active_ex_fd_set); | FD_CLR(socket, &_rep->active_ex_fd_set); |
} | } |
| |
if (events & READ) |
if (events & SocketMessage::READ) |
{ | { |
FD_CLR(socket, &_rep->active_rd_fd_set); | FD_CLR(socket, &_rep->active_rd_fd_set); |
} | } |
|
|
Boolean Monitor::solicitSocketMessages( | Boolean Monitor::solicitSocketMessages( |
Sint32 socket, | Sint32 socket, |
Uint32 events, | Uint32 events, |
Uint32 queueId); |
Uint32 queueId) |
{ | { |
// See whether a handler is already registered for this one: | // See whether a handler is already registered for this one: |
| |
Uint32 pos = _findEntry(socket); | Uint32 pos = _findEntry(socket); |
| |
if (pos != PEGUSUS_NOT_FOUND) |
if (pos != PEGASUS_NOT_FOUND) |
return false; | return false; |
| |
// Set the events: | // Set the events: |
| |
if (events & READ) |
if (events & SocketMessage::READ) |
FD_SET(socket, &_rep->rd_fd_set); | FD_SET(socket, &_rep->rd_fd_set); |
| |
if (events & WRITE) |
if (events & SocketMessage::WRITE) |
FD_SET(socket, &_rep->wr_fd_set); | FD_SET(socket, &_rep->wr_fd_set); |
| |
if (events & EXCEPTION) |
if (events & SocketMessage::EXCEPTION) |
FD_SET(socket, &_rep->ex_fd_set); | FD_SET(socket, &_rep->ex_fd_set); |
| |
// Add the entry to the list: | // Add the entry to the list: |
|
|
return true; | return true; |
} | } |
| |
Boolean Monitor::unolicitSocketMessages(Sint32 socket) |
Boolean Monitor::unsolicitSocketMessages(Sint32 socket) |
{ | { |
// Look for the given entry and remove it: | // Look for the given entry and remove it: |
| |