version 1.64, 2005/05/03 13:05:05
|
version 1.72.8.1, 2005/10/21 17:34:38
|
|
|
// Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#2065 | // Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#2065 |
// David Dillard, VERITAS Software Corp. | // David Dillard, VERITAS Software Corp. |
// (david.dillard@veritas.com) | // (david.dillard@veritas.com) |
|
// John Alex, IBM (johnalex@us.ibm.com) for Bug#3312 |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
|
// |
|
// Determine the correct type to use for the length passed to getsockname(). |
|
// The default is to use the 'socklen_t'. |
|
// |
|
|
|
#if defined(PEGASUS_OS_TYPE_WINDOWS) || defined(PEGASUS_OS_OS400) |
|
#define PEGASUS_SOCKLEN_T int |
|
#endif |
|
|
|
#if defined(PEGASUS_OS_HPUX) && !defined(_XOPEN_SOURCE_EXTENDED) |
|
#define PEGASUS_SOCKLEN_T int |
|
#endif |
|
|
|
|
|
#if defined(PEGASUS_OS_VMS) || defined(PEGASUS_OS_ZOS) |
|
#define PEGASUS_SOCKLEN_T unsigned |
|
#endif |
|
|
|
#ifndef PEGASUS_SOCKLEN_T |
|
#define PEGASUS_SOCKLEN_T socklen_t |
|
#endif |
|
|
static int MAX_CONNECTION_QUEUE_LENGTH = -1; | static int MAX_CONNECTION_QUEUE_LENGTH = -1; |
| |
| |
|
|
address_size = sizeof(struct sockaddr_in); | address_size = sizeof(struct sockaddr_in); |
} | } |
} | } |
|
~HTTPAcceptorRep() |
|
{ |
|
delete address; |
|
} |
struct sockaddr* address; | struct sockaddr* address; |
| |
#if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_VMS) | #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_VMS) |
|
|
| |
HTTPAcceptor::~HTTPAcceptor() | HTTPAcceptor::~HTTPAcceptor() |
{ | { |
|
destroyConnections(); |
unbind(); | unbind(); |
// ATTN: Is this correct in a multi-HTTPAcceptor server? | // ATTN: Is this correct in a multi-HTTPAcceptor server? |
Socket::uninitializeInterface(); | Socket::uninitializeInterface(); |
|
|
if (! message) | if (! message) |
return; | return; |
| |
|
PEGASUS_ASSERT(_rep != 0); |
switch (message->getType()) | switch (message->getType()) |
{ | { |
case SOCKET_MESSAGE: | case SOCKET_MESSAGE: |
|
|
void HTTPAcceptor::_bind() | void HTTPAcceptor::_bind() |
{ | { |
| |
|
PEGASUS_ASSERT(_rep != 0); |
// Create address: | // Create address: |
| |
memset(_rep->address, 0, sizeof(*_rep->address)); | memset(_rep->address, 0, sizeof(*_rep->address)); |
|
|
if ( _portNumber == 0 ) | if ( _portNumber == 0 ) |
{ | { |
sockaddr_in buf; | sockaddr_in buf; |
int bufSize = sizeof(buf); |
PEGASUS_SOCKLEN_T bufSize = sizeof(buf); |
if ( getsockname(_rep->socket, reinterpret_cast<sockaddr *>(&buf), &bufSize) == 0 ) | if ( getsockname(_rep->socket, reinterpret_cast<sockaddr *>(&buf), &bufSize) == 0 ) |
{ | { |
_portNumber = ntohs(buf.sin_port); | _portNumber = ntohs(buf.sin_port); |
|
|
| |
// close the socket | // close the socket |
Socket::close(_rep->socket); | Socket::close(_rep->socket); |
|
// Unlink Local Domain Socket Bug# 3312 |
|
if (_localConnection) |
|
{ |
|
#ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET |
|
PEG_TRACE_STRING(TRC_HTTP, Tracer::LEVEL2, |
|
"HTTPAcceptor::closeConnectionSocket Unlinking local connection." ); |
|
::unlink( |
|
reinterpret_cast<struct sockaddr_un*>(_rep->address)->sun_path); |
|
#else |
|
PEGASUS_ASSERT(false); |
|
#endif |
|
} |
|
|
} | } |
else | else |
{ | { |
|
|
Uint32 HTTPAcceptor::getOutstandingRequestCount() const | Uint32 HTTPAcceptor::getOutstandingRequestCount() const |
{ | { |
Uint32 count = 0; | Uint32 count = 0; |
|
if (_rep) |
|
{ |
AutoMutex autoMut(_rep->_connection_mut); | AutoMutex autoMut(_rep->_connection_mut); |
if (_rep->connections.size() > 0) | if (_rep->connections.size() > 0) |
{ | { |
HTTPConnection* connection = _rep->connections[0]; | HTTPConnection* connection = _rep->connections[0]; |
count = connection->getRequestCount(); | count = connection->getRequestCount(); |
} | } |
|
} |
return count; | return count; |
} | } |
| |
|
|
| |
void HTTPAcceptor::destroyConnections() | void HTTPAcceptor::destroyConnections() |
{ | { |
|
if (_rep) |
|
{ |
// For each connection created by this object: | // For each connection created by this object: |
| |
AutoMutex autoMut(_rep->_connection_mut); | AutoMutex autoMut(_rep->_connection_mut); |
|
|
| |
// Destroy the connection (causing it to close): | // Destroy the connection (causing it to close): |
| |
while (connection->refcount.value()) { } |
while (connection->refcount.get()) { } |
delete connection; | delete connection; |
} | } |
| |
_rep->connections.clear(); | _rep->connections.clear(); |
|
} |
} | } |
| |
void HTTPAcceptor::_acceptConnection() | void HTTPAcceptor::_acceptConnection() |
|
|
"HTTPAcceptor - accept() success. Socket: $1" | "HTTPAcceptor - accept() success. Socket: $1" |
,socket); | ,socket); |
| |
// Create a new conection and add it to the connection list: |
AutoPtr<MP_Socket> mp_socket(new MP_Socket( |
|
socket, _sslcontext, _sslContextObjectLock, _exportConnection)); |
| |
AutoPtr<MP_Socket> mp_socket(new MP_Socket(socket, _sslcontext, _exportConnection)); |
// Perform the SSL handshake, if applicable. Make the socket non-blocking |
|
// for this operation so we can send it back to the Monitor's select() loop |
|
// if it takes a while. |
|
|
|
mp_socket->disableBlocking(); |
|
Sint32 socketAcceptStatus = mp_socket->accept(); |
|
mp_socket->enableBlocking(); |
| |
Sint32 retVal; |
if (socketAcceptStatus < 0) |
|
|
if (_sslcontext) |
|
{ |
|
// |
|
// For SSL connections, obtain read lock to SSLContext object before |
|
// calling the accept() method of MP_Socket. |
|
// |
|
ReadLock rlock(*_sslContextObjectLock); |
|
retVal = mp_socket->accept(); |
|
} |
|
else |
|
{ |
|
retVal = mp_socket->accept(); |
|
} |
|
|
|
if (retVal < 0) |
|
{ | { |
PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2, | PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
"HTTPAcceptor: SSL_accept() failed"); | "HTTPAcceptor: SSL_accept() failed"); |
|
|
return; | return; |
} | } |
| |
|
// Create a new connection and add it to the connection list: |
|
|
HTTPConnection* connection = new HTTPConnection(_monitor, mp_socket, | HTTPConnection* connection = new HTTPConnection(_monitor, mp_socket, |
this, static_cast<MessageQueue *>(_outputMessageQueue), _exportConnection); | this, static_cast<MessageQueue *>(_outputMessageQueue), _exportConnection); |
| |
|
if (socketAcceptStatus == 0) |
|
{ |
|
PEG_TRACE_STRING(TRC_HTTP, Tracer::LEVEL2, |
|
"HTTPAcceptor: SSL_accept() pending"); |
|
connection->_acceptPending = true; |
|
} |
|
|
// Solicit events on this new connection's socket: | // Solicit events on this new connection's socket: |
int index; | int index; |
| |