version 1.100, 2005/12/02 18:25:52
|
version 1.111, 2006/07/17 14:34:39
|
|
|
//%2005//////////////////////////////////////////////////////////////////////// |
//%2006//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development | // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. | // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. |
|
|
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. | // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; | // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
// EMC Corporation; VERITAS Software Corporation; The Open Group. | // EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; Symantec 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 |
|
|
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
#include "Network.h" |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
|
|
#include <cstring> | #include <cstring> |
#include "Monitor.h" | #include "Monitor.h" |
#include "MessageQueue.h" | #include "MessageQueue.h" |
|
|
#include <Pegasus/Common/Exception.h> | #include <Pegasus/Common/Exception.h> |
#include "ArrayIterator.h" | #include "ArrayIterator.h" |
| |
#ifdef PEGASUS_OS_TYPE_WINDOWS |
|
# if defined(FD_SETSIZE) && FD_SETSIZE != 1024 |
|
# error "FD_SETSIZE was not set to 1024 prior to the last inclusion \ |
|
of <winsock.h>. It may have been indirectly included (e.g., by including \ |
|
<windows.h>). Find inclusion of that header which is visible to this \ |
|
compilation unit and #define FD_SETZIE to 1024 prior to that inclusion; \ |
|
otherwise, less than 64 clients (the default) will be able to connect to the \ |
|
CIMOM. PLEASE DO NOT SUPPRESS THIS WARNING; PLEASE FIX THE PROBLEM." |
|
|
|
# endif |
|
# define FD_SETSIZE 1024 |
|
# include <windows.h> |
|
#else |
|
# include <sys/types.h> |
|
# include <sys/socket.h> |
|
# include <sys/time.h> |
|
# include <netinet/in.h> |
|
# include <netdb.h> |
|
# include <arpa/inet.h> |
|
#endif |
|
|
|
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
|
|
//handle error | //handle error |
MessageLoaderParms parms("Common.Monitor.TICKLE_CREATE", | MessageLoaderParms parms("Common.Monitor.TICKLE_CREATE", |
"Received error number $0 while creating the internal socket.", | "Received error number $0 while creating the internal socket.", |
#if !defined(PEGASUS_OS_TYPE_WINDOWS) |
getSocketError()); |
errno); |
|
#else |
|
WSAGetLastError()); |
|
#endif |
|
throw Exception(parms); | throw Exception(parms); |
} | } |
| |
|
// set TCP_NODELAY |
|
int opt = 1; |
|
setsockopt(_tickle_server_socket, IPPROTO_TCP, TCP_NODELAY, (char*)&opt, sizeof(opt)); |
|
|
// initialize the address | // initialize the address |
memset(&_tickle_server_addr, 0, sizeof(_tickle_server_addr)); | memset(&_tickle_server_addr, 0, sizeof(_tickle_server_addr)); |
#ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM | #ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM |
|
|
_tickle_server_addr.sin_family = PF_INET; | _tickle_server_addr.sin_family = PF_INET; |
_tickle_server_addr.sin_port = 0; | _tickle_server_addr.sin_port = 0; |
| |
PEGASUS_SOCKLEN_T _addr_size = sizeof(_tickle_server_addr); |
SocketLength _addr_size = sizeof(_tickle_server_addr); |
| |
// bind server side to socket | // bind server side to socket |
if((::bind(_tickle_server_socket, | if((::bind(_tickle_server_socket, |
|
|
#else | #else |
MessageLoaderParms parms("Common.Monitor.TICKLE_BIND", | MessageLoaderParms parms("Common.Monitor.TICKLE_BIND", |
"Received error number $0 while binding the internal socket.", | "Received error number $0 while binding the internal socket.", |
#if !defined(PEGASUS_OS_TYPE_WINDOWS) |
getSocketError()); |
errno); |
|
#else |
|
WSAGetLastError()); |
|
#endif |
|
#endif | #endif |
throw Exception(parms); | throw Exception(parms); |
} | } |
|
|
// handle error | // handle error |
MessageLoaderParms parms("Common.Monitor.TICKLE_LISTEN", | MessageLoaderParms parms("Common.Monitor.TICKLE_LISTEN", |
"Received error number $0 while listening to the internal socket.", | "Received error number $0 while listening to the internal socket.", |
#if !defined(PEGASUS_OS_TYPE_WINDOWS) |
getSocketError()); |
errno); |
|
#else |
|
WSAGetLastError()); |
|
#endif |
|
throw Exception(parms); | throw Exception(parms); |
} | } |
| |
|
|
// handle error | // handle error |
MessageLoaderParms parms("Common.Monitor.TICKLE_SOCKNAME", | MessageLoaderParms parms("Common.Monitor.TICKLE_SOCKNAME", |
"Received error number $0 while getting the internal socket name.", | "Received error number $0 while getting the internal socket name.", |
#if !defined(PEGASUS_OS_TYPE_WINDOWS) |
getSocketError()); |
errno); |
|
#else |
|
WSAGetLastError()); |
|
#endif |
|
throw Exception(parms); | throw Exception(parms); |
} | } |
| |
|
|
// handle error | // handle error |
MessageLoaderParms parms("Common.Monitor.TICKLE_CLIENT_CREATE", | MessageLoaderParms parms("Common.Monitor.TICKLE_CLIENT_CREATE", |
"Received error number $0 while creating the internal client socket.", | "Received error number $0 while creating the internal client socket.", |
#if !defined(PEGASUS_OS_TYPE_WINDOWS) |
getSocketError()); |
errno); |
|
#else |
|
WSAGetLastError()); |
|
#endif |
|
throw Exception(parms); | throw Exception(parms); |
} | } |
| |
|
// set TCP_NODELAY |
|
setsockopt(_tickle_client_socket, IPPROTO_TCP, TCP_NODELAY, (char*)&opt, sizeof(opt)); |
|
|
// setup the address of the client | // setup the address of the client |
memset(&_tickle_client_addr, 0, sizeof(_tickle_client_addr)); | memset(&_tickle_client_addr, 0, sizeof(_tickle_client_addr)); |
#ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM | #ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM |
|
|
// handle error | // handle error |
MessageLoaderParms parms("Common.Monitor.TICKLE_CLIENT_BIND", | MessageLoaderParms parms("Common.Monitor.TICKLE_CLIENT_BIND", |
"Received error number $0 while binding the internal client socket.", | "Received error number $0 while binding the internal client socket.", |
#if !defined(PEGASUS_OS_TYPE_WINDOWS) |
getSocketError()); |
errno); |
|
#else |
|
WSAGetLastError()); |
|
#endif |
|
throw Exception(parms); | throw Exception(parms); |
} | } |
| |
|
|
// handle error | // handle error |
MessageLoaderParms parms("Common.Monitor.TICKLE_CLIENT_CONNECT", | MessageLoaderParms parms("Common.Monitor.TICKLE_CLIENT_CONNECT", |
"Received error number $0 while connecting the internal client socket.", | "Received error number $0 while connecting the internal client socket.", |
#if !defined(PEGASUS_OS_TYPE_WINDOWS) |
getSocketError()); |
errno); |
|
#else |
|
WSAGetLastError()); |
|
#endif |
|
throw Exception(parms); | throw Exception(parms); |
} | } |
| |
/* set up the slave connection */ | /* set up the slave connection */ |
memset(&_tickle_peer_addr, 0, sizeof(_tickle_peer_addr)); | memset(&_tickle_peer_addr, 0, sizeof(_tickle_peer_addr)); |
PEGASUS_SOCKLEN_T peer_size = sizeof(_tickle_peer_addr); |
SocketLength peer_size = sizeof(_tickle_peer_addr); |
pegasus_sleep(1); | pegasus_sleep(1); |
| |
// this call may fail, we will try a max of 20 times to establish this peer connection | // this call may fail, we will try a max of 20 times to establish this peer connection |
|
|
// handle error | // handle error |
MessageLoaderParms parms("Common.Monitor.TICKLE_ACCEPT", | MessageLoaderParms parms("Common.Monitor.TICKLE_ACCEPT", |
"Received error number $0 while accepting the internal socket connection.", | "Received error number $0 while accepting the internal socket connection.", |
#if !defined(PEGASUS_OS_TYPE_WINDOWS) |
getSocketError()); |
errno); |
|
#else |
|
WSAGetLastError()); |
|
#endif |
|
throw Exception(parms); | throw Exception(parms); |
} | } |
|
|
|
Socket::disableBlocking(_tickle_peer_socket); |
|
Socket::disableBlocking(_tickle_client_socket); |
|
|
// add the tickler to the list of entries to be monitored and set to IDLE because Monitor only | // add the tickler to the list of entries to be monitored and set to IDLE because Monitor only |
// checks entries with IDLE state for events | // checks entries with IDLE state for events |
_MonitorEntry entry(_tickle_peer_socket, 1, INTERNAL); | _MonitorEntry entry(_tickle_peer_socket, 1, INTERNAL); |
|
|
}; | }; |
| |
AutoMutex autoMutex(_tickle_mutex); | AutoMutex autoMutex(_tickle_mutex); |
Socket::disableBlocking(_tickle_client_socket); |
|
Socket::write(_tickle_client_socket,&_buffer, 2); | Socket::write(_tickle_client_socket,&_buffer, 2); |
Socket::enableBlocking(_tickle_client_socket); |
|
} | } |
| |
void Monitor::setState( Uint32 index, _MonitorEntry::entry_status status ) | void Monitor::setState( Uint32 index, _MonitorEntry::entry_status status ) |
|
|
autoEntryMutex.unlock(); | autoEntryMutex.unlock(); |
o.enqueue(message); | o.enqueue(message); |
autoEntryMutex.lock(); | autoEntryMutex.lock(); |
|
// After enqueue a message and the autoEntryMutex has been released and locked again, |
|
// the array of _entries can be changed. The ArrayIterator has be reset with the original _entries. |
|
entries.reset(_entries); |
} | } |
} | } |
| |
|
|
place to calculate the max file descriptor (maximum socket number) | place to calculate the max file descriptor (maximum socket number) |
because we have to traverse the entire array. | because we have to traverse the entire array. |
*/ | */ |
PEGASUS_SOCKET maxSocketCurrentPass = 0; |
SocketHandle maxSocketCurrentPass = 0; |
for( int indx = 0; indx < (int)entries.size(); indx++) | for( int indx = 0; indx < (int)entries.size(); indx++) |
{ | { |
if(maxSocketCurrentPass < entries[indx].socket) | if(maxSocketCurrentPass < entries[indx].socket) |
|
|
int events = select(maxSocketCurrentPass, &fdread, NULL, NULL, &tv); | int events = select(maxSocketCurrentPass, &fdread, NULL, NULL, &tv); |
#endif | #endif |
autoEntryMutex.lock(); | autoEntryMutex.lock(); |
|
// After enqueue a message and the autoEntryMutex has been released and locked again, |
|
// the array of _entries can be changed. The ArrayIterator has be reset with the original _entries |
|
entries.reset(_entries); |
| |
#ifdef PEGASUS_OS_TYPE_WINDOWS |
if (events == PEGASUS_SOCKET_ERROR) |
if(events == SOCKET_ERROR) |
|
#else |
|
if(events == -1) |
|
#endif |
|
{ | { |
Tracer::trace(TRC_HTTP, Tracer::LEVEL4, | Tracer::trace(TRC_HTTP, Tracer::LEVEL4, |
"Monitor::run - errorno = %d has occurred on select.", errno); | "Monitor::run - errorno = %d has occurred on select.", errno); |
|
|
| |
entries[indx]._status = _MonitorEntry::BUSY; | entries[indx]._status = _MonitorEntry::BUSY; |
static char buffer[2]; | static char buffer[2]; |
Socket::disableBlocking(entries[indx].socket); |
|
Sint32 amt = Socket::read(entries[indx].socket,&buffer, 2); | Sint32 amt = Socket::read(entries[indx].socket,&buffer, 2); |
Socket::enableBlocking(entries[indx].socket); |
|
entries[indx]._status = _MonitorEntry::IDLE; | entries[indx]._status = _MonitorEntry::IDLE; |
} | } |
else | else |
|
|
autoEntryMutex.unlock(); | autoEntryMutex.unlock(); |
q->enqueue(msg); | q->enqueue(msg); |
autoEntryMutex.lock(); | autoEntryMutex.lock(); |
|
// After enqueue a message and the autoEntryMutex has been released and locked again, |
|
// the array of entries can be changed. The ArrayIterator has be reset with the original _entries |
|
entries.reset(_entries); |
entries[indx]._status = _MonitorEntry::IDLE; | entries[indx]._status = _MonitorEntry::IDLE; |
| |
return true; | return true; |
|
|
// Wait for the monitor to notice _stopConnections. Otherwise the | // Wait for the monitor to notice _stopConnections. Otherwise the |
// caller of this function may unbind the ports while the monitor | // caller of this function may unbind the ports while the monitor |
// is still accepting connections on them. | // is still accepting connections on them. |
try |
_stopConnectionsSem.wait(); |
{ |
|
_stopConnectionsSem.time_wait(10000); |
|
} |
|
catch (TimeOut &) |
|
{ |
|
// The monitor is probably busy processng a very long request, and is |
|
// not accepting connections. Let the caller unbind the ports. |
|
} |
|
} | } |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
|
|
| |
| |
int Monitor::solicitSocketMessages( | int Monitor::solicitSocketMessages( |
PEGASUS_SOCKET socket, |
SocketHandle socket, |
Uint32 events, | Uint32 events, |
Uint32 queueId, | Uint32 queueId, |
int type) | int type) |
|
|
| |
} | } |
| |
void Monitor::unsolicitSocketMessages(PEGASUS_SOCKET socket) |
void Monitor::unsolicitSocketMessages(SocketHandle socket) |
{ | { |
| |
PEG_METHOD_ENTER(TRC_HTTP, "Monitor::unsolicitSocketMessages"); | PEG_METHOD_ENTER(TRC_HTTP, "Monitor::unsolicitSocketMessages"); |