version 1.54, 2003/10/05 23:25:43
|
version 1.67, 2003/11/04 04:38:21
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%2003//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development |
// The Open Group, Tivoli Systems |
// Company, L. P., IBM Corp., The Open Group, Tivoli Systems. |
|
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.; |
|
// IBM Corp.; EMC Corporation, The Open Group. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
} | } |
} | } |
| |
|
// Fixed in monitor_2 but added because Monitor is still the default monitor. |
|
// When _idleEntries is 0 don't imediatly return, otherwize this loops out of control |
|
// kicking off kill idle thread threads. E.g. There is nothing to select on when the cimserver |
|
// is shutting down. |
|
if( _idleEntries == 0 ) |
|
{ |
|
Thread::sleep( milliseconds ); |
|
_entry_mut.unlock(); |
|
return false; |
|
} |
|
|
_entry_mut.unlock(); | _entry_mut.unlock(); |
int events = select(FD_SETSIZE, &fdread, NULL, NULL, &tv); | int events = select(FD_SETSIZE, &fdread, NULL, NULL, &tv); |
_entry_mut.lock(pegasus_thread_self()); | _entry_mut.lock(pegasus_thread_self()); |
|
|
return true; | return true; |
} | } |
_entries[indx]._status = _MonitorEntry::BUSY; | _entries[indx]._status = _MonitorEntry::BUSY; |
_thread_pool->allocate_and_awaken((void *)q, _dispatch); |
// If allocate_and_awaken failure, retry on next iteration |
|
if (!_thread_pool->allocate_and_awaken((void *)q, _dispatch)) |
|
{ |
|
Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
|
"Monitor::run: Insufficient resources to process request."); |
|
_entries[indx]._status = _MonitorEntry::IDLE; |
|
_entry_mut.unlock(); |
|
return true; |
|
} |
} | } |
else | else |
{ | { |
|
|
////************************* monitor 2 *****************************//// | ////************************* monitor 2 *****************************//// |
| |
| |
|
|
|
|
|
|
m2e_rep::m2e_rep(void) | m2e_rep::m2e_rep(void) |
:Base(), state(IDLE) | :Base(), state(IDLE) |
| |
|
|
| |
monitor_2_entry::~monitor_2_entry(void) | monitor_2_entry::~monitor_2_entry(void) |
{ | { |
|
|
Dec(_rep); | Dec(_rep); |
} | } |
| |
|
|
| |
} | } |
| |
|
//static monitor_2* _m2_instance; |
| |
AsyncDQueue<HTTPConnection2> monitor_2::_connections(true, 0); | AsyncDQueue<HTTPConnection2> monitor_2::_connections(true, 0); |
| |
|
|
monitor_2::monitor_2(void) | monitor_2::monitor_2(void) |
: _session_dispatch(0), _accept_dispatch(0), _listeners(true, 0), | : _session_dispatch(0), _accept_dispatch(0), _listeners(true, 0), |
_ready(true, 0), _die(0), _requestCount(0) | _ready(true, 0), _die(0), _requestCount(0) |
|
|
#ifdef PEGASUS_OS_ZOS | #ifdef PEGASUS_OS_ZOS |
_tickle_addr.sin_addr.s_addr = inet_addr_ebcdic("127.0.0.1"); | _tickle_addr.sin_addr.s_addr = inet_addr_ebcdic("127.0.0.1"); |
#else | #else |
|
#ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM |
|
#pragma convert(37) |
|
#endif |
_tickle_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); | _tickle_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); |
|
#ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM |
|
#pragma convert(0) |
|
#endif |
#endif | #endif |
_tickle_addr.sin_family = PF_INET; | _tickle_addr.sin_family = PF_INET; |
_tickle_addr.sin_port = 0; | _tickle_addr.sin_port = 0; |
|
|
PEGASUS_SOCKLEN_SIZE peer_size = sizeof(peer); | PEGASUS_SOCKLEN_SIZE peer_size = sizeof(peer); |
| |
pegasus_socket accepted = temp.accept((struct sockaddr*)&peer, &peer_size); | pegasus_socket accepted = temp.accept((struct sockaddr*)&peer, &peer_size); |
|
|
monitor_2_entry* _tickle = new monitor_2_entry(accepted, INTERNAL, 0, 0); | monitor_2_entry* _tickle = new monitor_2_entry(accepted, INTERNAL, 0, 0); |
_tickle->set_state(BUSY); | _tickle->set_state(BUSY); |
| |
|
|
| |
monitor_2::~monitor_2(void) | monitor_2::~monitor_2(void) |
{ | { |
|
|
|
stop(); |
|
|
try { | try { |
monitor_2_entry* temp = _listeners.remove_first(); | monitor_2_entry* temp = _listeners.remove_first(); |
while(temp){ | while(temp){ |
|
|
temp = _listeners.remove_first(); | temp = _listeners.remove_first(); |
} | } |
} | } |
|
|
catch(...){ } | catch(...){ } |
|
|
|
|
|
try |
|
{ |
|
HTTPConnection2* temp = _connections.remove_first(); |
|
while(temp) |
|
{ |
|
delete temp; |
|
temp = _connections.remove_first(); |
|
} |
|
} |
|
catch(...) |
|
{ |
|
} |
|
|
|
|
} | } |
| |
| |
|
|
monitor_2_entry* temp; | monitor_2_entry* temp; |
while(_die.value() == 0) { | while(_die.value() == 0) { |
| |
struct timeval tv = {0, 0}; |
struct timeval tv_idle = { 60, 0 }; |
| |
// place all sockets in the select set | // place all sockets in the select set |
FD_ZERO(&rd_fd_set); | FD_ZERO(&rd_fd_set); |
|
|
monitor_2_entry* closed = temp; | monitor_2_entry* closed = temp; |
temp = _listeners.next(closed); | temp = _listeners.next(closed); |
_listeners.remove_no_lock(closed); | _listeners.remove_no_lock(closed); |
|
|
HTTPConnection2 *cn = monitor_2::remove_connection((Sint32)(closed->get_sock())); | HTTPConnection2 *cn = monitor_2::remove_connection((Sint32)(closed->get_sock())); |
delete cn; | delete cn; |
delete closed; | delete closed; |
|
|
// important - the dispatch routine has pointers to all the | // important - the dispatch routine has pointers to all the |
// entries that are readable. These entries can be changed but | // entries that are readable. These entries can be changed but |
// the pointer must not be tampered with. | // the pointer must not be tampered with. |
|
if(_connections.count() ) |
int events = select(FD_SETSIZE, &rd_fd_set, NULL, NULL, NULL); | int events = select(FD_SETSIZE, &rd_fd_set, NULL, NULL, NULL); |
|
else |
|
int events = select(FD_SETSIZE, &rd_fd_set, NULL, NULL, &tv_idle); |
|
|
|
if(_die.value()) |
|
{ |
|
break; |
|
} |
|
|
try { | try { |
_listeners.lock(pegasus_thread_self()); | _listeners.lock(pegasus_thread_self()); |
temp = _listeners.next(0); | temp = _listeners.next(0); |
|
|
return; | return; |
} | } |
// now handle the sockets that are ready to read | // now handle the sockets that are ready to read |
|
if(_ready.count()) |
_dispatch(); | _dispatch(); |
|
else |
|
{ |
|
if(_connections.count() == 0 ) |
|
_idle_dispatch(_idle_parm); |
|
} |
} // while alive | } // while alive |
|
|
} | } |
| |
void* monitor_2::set_session_dispatch(void (*dp)(monitor_2_entry*)) | void* monitor_2::set_session_dispatch(void (*dp)(monitor_2_entry*)) |
|
|
void* old = (void*)_accept_dispatch; | void* old = (void*)_accept_dispatch; |
_accept_dispatch = dp; | _accept_dispatch = dp; |
return old; | return old; |
|
} |
| |
|
void* monitor_2::set_idle_dispatch(void (*dp)(void*)) |
|
{ |
|
void* old = (void*)_idle_dispatch; |
|
_idle_dispatch = dp; |
|
return old; |
} | } |
| |
|
void* monitor_2::set_idle_parm(void* parm) |
|
{ |
|
void* old = _idle_parm; |
|
_idle_parm = parm; |
|
return old; |
|
} |
|
|
|
|
|
|
|
//----------------------------------------------------------------- |
|
// Note on deleting the monitor_2_entry nodes: |
|
// Each case: in the switch statement needs to handle the deletion |
|
// of the monitor_2_entry * node differently. A SESSION dispatch |
|
// routine MUST DELETE the entry during its dispatch handling. |
|
// All other dispatch routines MUST NOT delete the entry during the |
|
// dispatch handling, but must allow monitor_2::_dispatch to delete |
|
// the entry. |
|
// |
|
// The reason is pretty obscure and it is debatable whether or not |
|
// to even bother, but during cimserver shutdown the single monitor_2_entry* |
|
// will leak unless the _session_dispatch routine takes care of deleting it. |
|
// |
|
// The reason is that a shutdown messages completely stops everything and |
|
// the _session_dispatch routine never returns. So monitor_2::_dispatch is |
|
// never able to do its own cleanup. |
|
// |
|
// << Mon Oct 13 09:33:33 2003 mdd >> |
|
//----------------------------------------------------------------- |
| |
// important - the dispatch routine has pointers to all the |
|
// entries that are readable. These entries can be changed but |
|
// the pointer must not be tampered with. |
|
void monitor_2::_dispatch(void) | void monitor_2::_dispatch(void) |
{ | { |
monitor_2_entry* entry; | monitor_2_entry* entry; |
| |
if(_ready.count() == 0 ) |
|
return; |
|
|
|
|
|
try | try |
{ | { |
| |
|
|
entry->get_sock().disableBlocking(); | entry->get_sock().disableBlocking(); |
entry->get_sock().read(&buffer, 2); | entry->get_sock().read(&buffer, 2); |
entry->get_sock().enableBlocking(); | entry->get_sock().enableBlocking(); |
|
delete entry; |
|
|
break; | break; |
case LISTEN: | case LISTEN: |
{ | { |
|
|
static PEGASUS_SOCKLEN_SIZE peer_size = sizeof(peer); | static PEGASUS_SOCKLEN_SIZE peer_size = sizeof(peer); |
entry->get_sock().disableBlocking(); | entry->get_sock().disableBlocking(); |
pegasus_socket connected = entry->get_sock().accept(&peer, &peer_size); | pegasus_socket connected = entry->get_sock().accept(&peer, &peer_size); |
|
#ifdef PEGASUS_OS_TYPE_WINDOWS |
|
if((Sint32)connected == SOCKET_ERROR) |
|
#else |
|
if((Sint32)connected == -1 ) |
|
#endif |
|
{ |
|
delete entry; |
|
break; |
|
} |
|
|
entry->get_sock().enableBlocking(); | entry->get_sock().enableBlocking(); |
monitor_2_entry *temp = add_entry(connected, SESSION, entry->get_accept(), entry->get_dispatch()); | monitor_2_entry *temp = add_entry(connected, SESSION, entry->get_accept(), entry->get_dispatch()); |
if(temp && _accept_dispatch != 0) | if(temp && _accept_dispatch != 0) |
_accept_dispatch(temp); | _accept_dispatch(temp); |
|
delete entry; |
|
|
} | } |
break; | break; |
case SESSION: | case SESSION: |
if(_session_dispatch != 0 ) | if(_session_dispatch != 0 ) |
|
{ |
|
// NOTE: _session_dispatch will delete entry - do not do it here |
_session_dispatch(entry); | _session_dispatch(entry); |
|
} |
|
|
else { | else { |
static char buffer[4096]; | static char buffer[4096]; |
int bytes = entry->get_sock().read(&buffer, 4096); | int bytes = entry->get_sock().read(&buffer, 4096); |
|
delete entry; |
} | } |
| |
break; | break; |
case UNTYPED: | case UNTYPED: |
default: | default: |
|
delete entry; |
break; | break; |
} | } |
_requestCount--; | _requestCount--; |
delete entry; |
|
| |
if(_ready.count() == 0 ) | if(_ready.count() == 0 ) |
break; | break; |
|
|
{ | { |
_die = 1; | _die = 1; |
tickle(); | tickle(); |
|
|
// shut down the listener list, free the list nodes | // shut down the listener list, free the list nodes |
_tickler.get_sock().close(); | _tickler.get_sock().close(); |
_listeners.shutdown_queue(); | _listeners.shutdown_queue(); |
|
|
'0','0' | '0','0' |
}; | }; |
| |
|
_tickler.get_sock().disableBlocking(); |
|
|
_tickler.get_sock().write(&_buffer, 2); | _tickler.get_sock().write(&_buffer, 2); |
|
_tickler.get_sock().enableBlocking(); |
|
|
} | } |
| |
| |