version 1.9, 2002/05/20 18:24:09
|
version 1.15, 2002/05/29 23:26:34
|
|
|
| |
Monitor::~Monitor() | Monitor::~Monitor() |
{ | { |
printf("deregistering with module controller\n"); |
Tracer::trace(TRC_HTTP, Tracer::LEVEL4, |
|
"deregistering with module controller"); |
| |
if(_module_handle != NULL) | if(_module_handle != NULL) |
{ | { |
_controller->deregister_module(PEGASUS_MODULENAME_MONITOR); | _controller->deregister_module(PEGASUS_MODULENAME_MONITOR); |
_controller = 0; | _controller = 0; |
|
delete _module_handle; |
} | } |
printf("deleting rep\n"); |
Tracer::trace(TRC_HTTP, Tracer::LEVEL4, "deleting rep"); |
| |
delete _rep; | delete _rep; |
printf("uninitializing interface \n"); |
Tracer::trace(TRC_HTTP, Tracer::LEVEL4, "uninitializing interface"); |
Socket::uninitializeInterface(); | Socket::uninitializeInterface(); |
printf("returning from monitor destructor\n"); |
Tracer::trace(TRC_HTTP, Tracer::LEVEL4, |
|
"returning from monitor destructor"); |
} | } |
| |
| |
|
|
| |
Boolean Monitor::run(Uint32 milliseconds) | Boolean Monitor::run(Uint32 milliseconds) |
{ | { |
|
|
|
|
// register the monitor as a module to gain access to the cimserver's thread pool | // register the monitor as a module to gain access to the cimserver's thread pool |
// <<< Wed May 15 09:52:16 2002 mdd >>> | // <<< Wed May 15 09:52:16 2002 mdd >>> |
while(_module_handle == NULL) | while(_module_handle == NULL) |
{ | { |
|
|
try | try |
{ | { |
|
|
_controller = &(ModuleController::register_module(PEGASUS_QUEUENAME_CONTROLSERVICE, | _controller = &(ModuleController::register_module(PEGASUS_QUEUENAME_CONTROLSERVICE, |
PEGASUS_MODULENAME_MONITOR, | PEGASUS_MODULENAME_MONITOR, |
(void *)this, | (void *)this, |
|
|
0, | 0, |
0, | 0, |
&_module_handle)); | &_module_handle)); |
break; |
|
| |
} | } |
catch( ... ) |
catch(IncompatibleTypes &) |
|
{ |
|
ModuleController* controlService = |
|
new ModuleController(PEGASUS_QUEUENAME_CONTROLSERVICE); |
|
} |
|
catch( AlreadyExists & ) |
{ | { |
; |
break; |
} | } |
} | } |
| |
|
|
#ifdef PEGASUS_OS_TYPE_WINDOWS | #ifdef PEGASUS_OS_TYPE_WINDOWS |
| |
// Windows select() has a strange little bug. It returns immediately if | // Windows select() has a strange little bug. It returns immediately if |
|
|
| |
int count = 0; | int count = 0; |
| |
if (count == 0) |
|
{ |
|
memcpy(&_rep->active_rd_fd_set, &_rep->rd_fd_set, sizeof(fd_set)); | memcpy(&_rep->active_rd_fd_set, &_rep->rd_fd_set, sizeof(fd_set)); |
memcpy(&_rep->active_wr_fd_set, &_rep->wr_fd_set, sizeof(fd_set)); | memcpy(&_rep->active_wr_fd_set, &_rep->wr_fd_set, sizeof(fd_set)); |
memcpy(&_rep->active_ex_fd_set, &_rep->ex_fd_set, sizeof(fd_set)); | memcpy(&_rep->active_ex_fd_set, &_rep->ex_fd_set, sizeof(fd_set)); |
|
|
&_rep->active_wr_fd_set, | &_rep->active_wr_fd_set, |
&_rep->active_ex_fd_set, | &_rep->active_ex_fd_set, |
&tv); | &tv); |
|
|
if (count == 0) | if (count == 0) |
{ | { |
pegasus_sleep(milliseconds); |
|
|
|
return false; | return false; |
} | } |
| |
|
|
else if (count == -1) | else if (count == -1) |
#endif | #endif |
{ | { |
count = 0; |
|
pegasus_sleep(milliseconds); |
|
|
|
return false; | return false; |
} | } |
} |
|
| |
for (Uint32 i = 0, n = _entries.size(); i < n; i++) |
Boolean handled_events = false; |
|
for (Uint32 i = 0, n = _entries.size(); i < _entries.size(); i++) |
{ | { |
Sint32 socket = _entries[i].socket; | Sint32 socket = _entries[i].socket; |
Uint32 events = 0; | Uint32 events = 0; |
|
|
{ | { |
| |
MessageQueue *q = MessageQueue::lookup(_entries[i].queueId); | MessageQueue *q = MessageQueue::lookup(_entries[i].queueId); |
if(q && static_cast<HTTPConnection *>(q)->is_dying()) |
if(q && static_cast<HTTPConnection *>(q)->is_dying() && |
|
(0 == static_cast<HTTPConnection *>(q)->refcount.value())) |
{ | { |
static_cast<HTTPConnection *>(q)->lock_connection(); | static_cast<HTTPConnection *>(q)->lock_connection(); |
static_cast<HTTPConnection *>(q)->unlock_connection(); | static_cast<HTTPConnection *>(q)->unlock_connection(); |
|
|
Message* message= new CloseConnectionMessage(static_cast<HTTPConnection *>(q)->getSocket()); | Message* message= new CloseConnectionMessage(static_cast<HTTPConnection *>(q)->getSocket()); |
message->dest = o.getQueueId(); | message->dest = o.getQueueId(); |
o.enqueue(message); | o.enqueue(message); |
i = 0; |
i--; |
n = _entries.size(); | n = _entries.size(); |
continue; |
|
} | } |
} | } |
} | } |
|
|
| |
if(_entries[i]._type == Monitor::CONNECTION) | if(_entries[i]._type == Monitor::CONNECTION) |
{ | { |
|
if( static_cast<HTTPConnection *>(queue)->refcount.value() == 0 ) |
|
{ |
|
|
|
static_cast<HTTPConnection *>(queue)->refcount++; |
if( false == static_cast<HTTPConnection *>(queue)->is_dying()) | if( false == static_cast<HTTPConnection *>(queue)->is_dying()) |
_controller->async_thread_exec(*_module_handle, _dispatch, (void *)queue); | _controller->async_thread_exec(*_module_handle, _dispatch, (void *)queue); |
|
else |
|
static_cast<HTTPConnection *>(queue)->refcount--; |
|
} |
} | } |
else | else |
{ | { |
|
|
queue->enqueue(message); | queue->enqueue(message); |
} | } |
count--; | count--; |
return true; |
pegasus_yield(); |
} | } |
|
handled_events = true; |
} | } |
pegasus_sleep(milliseconds); |
|
| |
return false; |
return(handled_events); |
} | } |
| |
Boolean Monitor::solicitSocketMessages( | Boolean Monitor::solicitSocketMessages( |
|
|
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: |
|
|
_MonitorEntry entry(socket, queueId, type); | _MonitorEntry entry(socket, queueId, type); |
entry.dying = 0; |
|
|
|
_entries.append(entry); | _entries.append(entry); |
| |
// Success! | // Success! |
ModuleController* controlService = |
|
new ModuleController(PEGASUS_QUEUENAME_CONTROLSERVICE); |
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; | return true; |
} | } |
|
|
FD_CLR(socket, &_rep->wr_fd_set); | FD_CLR(socket, &_rep->wr_fd_set); |
FD_CLR(socket, &_rep->ex_fd_set); | FD_CLR(socket, &_rep->ex_fd_set); |
_entries.remove(i); | _entries.remove(i); |
|
// ATTN-RK-P3-20020521: Need "Socket::close(socket);" here? |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; | return true; |
} | } |
|
|
{ | { |
HTTPConnection *dst = reinterpret_cast<HTTPConnection *>(parm); | HTTPConnection *dst = reinterpret_cast<HTTPConnection *>(parm); |
if( true == dst->is_dying()) | if( true == dst->is_dying()) |
|
{ |
|
dst->refcount--; |
return 0; | return 0; |
dst->lock_connection(); |
} |
if( false == dst->is_dying()) | if( false == dst->is_dying()) |
dst->run(1); |
{ |
dst->unlock_connection(); |
if(false == dst->run(1)) |
|
pegasus_sleep(1); |
| |
|
} |
|
dst->refcount--; |
return 0; | return 0; |
} | } |
| |