version 1.81.8.9, 2006/07/21 18:17:51
|
version 1.81.8.12, 2006/10/18 04:24:42
|
|
|
# include <netinet/tcp.h> | # include <netinet/tcp.h> |
# include <arpa/inet.h> | # include <arpa/inet.h> |
# include <sys/socket.h> | # include <sys/socket.h> |
|
|
# ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET | # ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET |
# include <unistd.h> | # include <unistd.h> |
# include <sys/un.h> | # include <sys/un.h> |
|
|
{ | { |
if (local) | if (local) |
{ | { |
|
|
#ifndef PEGASUS_OS_TYPE_WINDOWS | #ifndef PEGASUS_OS_TYPE_WINDOWS |
#ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET | #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET |
| |
|
|
Mutex _connection_mut; | Mutex _connection_mut; |
| |
PEGASUS_SOCKET socket; | PEGASUS_SOCKET socket; |
#ifdef PEGASUS_OS_TYPE_WINDOWS |
|
|
// Added for NamedPipe implementation for windows |
|
#if defined PEGASUS_OS_TYPE_WINDOWS && !defined(PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET) |
NamedPipeServer* namedPipeServer; | NamedPipeServer* namedPipeServer; |
#endif | #endif |
Array<HTTPConnection*> connections; | Array<HTTPConnection*> connections; |
/* |
|
#ifdef PEGASUS_OS_TYPE_WINDOWS |
|
// This method creates and connects to a named pipe |
|
void createNamedPipe(); |
|
NamedPipeServer* namedPipeServer; |
|
void _acceptNamedPipeConnection(NamedPipeMessage* namedPipeMessage); |
|
#endif |
|
*/ |
|
|
|
|
|
}; | }; |
| |
//------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ |
|
|
| |
break; | break; |
} | } |
#ifdef PEGASUS_OS_TYPE_WINDOWS |
|
|
// Added for NamedPipe implementation for windows |
|
#if defined PEGASUS_OS_TYPE_WINDOWS && !defined(PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET) |
case NAMEDPIPE_MESSAGE: | case NAMEDPIPE_MESSAGE: |
{ | { |
NamedPipeMessage* namedPipeMessage = (NamedPipeMessage*)message; | NamedPipeMessage* namedPipeMessage = (NamedPipeMessage*)message; |
|
|
Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, | Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
"HTTPAcceptor::handleEnqueue: Invalid NAMEDPIPE_MESSAGE received."); | "HTTPAcceptor::handleEnqueue: Invalid NAMEDPIPE_MESSAGE received."); |
} | } |
|
|
break; | break; |
|
|
} | } |
#endif | #endif |
// may Need to close connection for Named Pipe too.....?? | // may Need to close connection for Named Pipe too.....?? |
|
|
for (Uint32 i = 0, n = _rep->connections.size(); i < n; i++) | for (Uint32 i = 0, n = _rep->connections.size(); i < n; i++) |
{ | { |
HTTPConnection* connection = _rep->connections[i]; | HTTPConnection* connection = _rep->connections[i]; |
|
// Added for NamedPipe implementation for windows |
|
#if defined PEGASUS_OS_TYPE_WINDOWS && !defined(PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET) |
if(!connection->isNamedPipeConnection()) | if(!connection->isNamedPipeConnection()) |
{ | { |
|
#endif |
PEGASUS_SOCKET socket = connection->getSocket(); | PEGASUS_SOCKET socket = connection->getSocket(); |
| |
if (socket == closeConnectionMessage->socket) | if (socket == closeConnectionMessage->socket) |
|
|
delete connection; | delete connection; |
break; | break; |
} | } |
|
// Added for NamedPipe implementation for windows |
|
#if defined PEGASUS_OS_TYPE_WINDOWS && !defined(PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET) |
} | } |
else | else |
{ | { |
|
|
break; | break; |
} | } |
} | } |
|
#endif |
} | } |
| |
break; | break; |
|
|
#endif | #endif |
| |
| |
#ifdef PEGASUS_OS_TYPE_WINDOWS |
#if defined PEGASUS_OS_TYPE_WINDOWS |
if (!_localConnection) | if (!_localConnection) |
{ | { |
|
#endif |
memset(_rep->address, 0, sizeof(*_rep->address)); | memset(_rep->address, 0, sizeof(*_rep->address)); |
|
#if defined PEGASUS_OS_TYPE_WINDOWS |
} | } |
#else |
|
memset(_rep->address, 0, sizeof(*_rep->address)); |
|
#endif | #endif |
| |
#ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG | #ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG |
|
|
| |
if (_localConnection) | if (_localConnection) |
{ | { |
|
// Added for NamedPipe implementation for windows |
#ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET | #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET |
| |
#ifdef PEGASUS_OS_TYPE_WINDOWS | #ifdef PEGASUS_OS_TYPE_WINDOWS |
#ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG | #ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG |
{ | { |
AutoMutex automut(Monitor::_cout_mut); | AutoMutex automut(Monitor::_cout_mut); |
PEGASUS_STD(cout) |
PEGASUS_STD(cout) << "in HTTPAcceptor::_bind before calling _createNamedPipe() " |
<< "in HTTPAcceptor::_bind before calling _createNamedPipe() " |
|
<< PEGASUS_STD(endl); | << PEGASUS_STD(endl); |
} | } |
#endif | #endif |
// _rep->createNamedPipe(); |
|
_createNamedPipe(); | _createNamedPipe(); |
#ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG | #ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG |
{ | { |
|
|
} | } |
#endif | #endif |
return; | return; |
#else |
# else // Other than Windows platform |
reinterpret_cast<struct sockaddr_un*>(_rep->address)->sun_family = | reinterpret_cast<struct sockaddr_un*>(_rep->address)->sun_family = |
AF_UNIX; | AF_UNIX; |
strcpy( | strcpy( |
|
|
} | } |
#endif | #endif |
| |
|
|
// | // |
// Set the socket option SO_REUSEADDR to reuse the socket address so | // Set the socket option SO_REUSEADDR to reuse the socket address so |
// that we can rebind to a new socket using the same address when we | // that we can rebind to a new socket using the same address when we |
|
|
throw BindFailedException(parms); | throw BindFailedException(parms); |
} | } |
| |
|
|
// | // |
// Bind socket to port: | // Bind socket to port: |
// | // |
|
|
throw BindFailedException(parms); | throw BindFailedException(parms); |
} | } |
| |
|
|
// | // |
// Get the actual port value used if the caller specified a port value of 0. | // Get the actual port value used if the caller specified a port value of 0. |
// | // |
|
|
} | } |
} | } |
| |
|
|
// | // |
// Change permissions on Linux local domain socket to allow writes by others. | // Change permissions on Linux local domain socket to allow writes by others. |
// | // |
|
|
#endif | #endif |
| |
// Set up listening on the given socket: | // Set up listening on the given socket: |
|
|
//int const MAX_CONNECTION_QUEUE_LENGTH = 15; | //int const MAX_CONNECTION_QUEUE_LENGTH = 15; |
| |
if (listen(_rep->socket, MAX_CONNECTION_QUEUE_LENGTH) < 0) | if (listen(_rep->socket, MAX_CONNECTION_QUEUE_LENGTH) < 0) |
|
|
for (Uint32 i = 0, n = _rep->connections.size(); i < n; i++) | for (Uint32 i = 0, n = _rep->connections.size(); i < n; i++) |
{ | { |
HTTPConnection* connection = _rep->connections[i]; | HTTPConnection* connection = _rep->connections[i]; |
|
// Added for NamedPipe implementation for windows |
|
#if defined PEGASUS_OS_TYPE_WINDOWS && !defined(PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET) |
if(!connection->isNamedPipeConnection()) | if(!connection->isNamedPipeConnection()) |
{ | { |
|
#endif |
PEGASUS_SOCKET socket = connection->getSocket(); | PEGASUS_SOCKET socket = connection->getSocket(); |
| |
// Unsolicit SocketMessages: | // Unsolicit SocketMessages: |
| |
_monitor->unsolicitSocketMessages(socket); | _monitor->unsolicitSocketMessages(socket); |
| |
|
// Added for NamedPipe implementation for windows |
// Destroy the connection (causing it to close): | // Destroy the connection (causing it to close): |
|
#if defined PEGASUS_OS_TYPE_WINDOWS && !defined(PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET) |
} | } |
else | else |
{ | { |
NamedPipe namedPipe = connection->getNamedPipe(); | NamedPipe namedPipe = connection->getNamedPipe(); |
_monitor->unsolicitPipeMessages(namedPipe); | _monitor->unsolicitPipeMessages(namedPipe); |
|
|
::FlushFileBuffers(namedPipe.getPipe()); |
|
::DisconnectNamedPipe(namedPipe.getPipe()); |
|
::CloseHandle(namedPipe.getPipe()); |
|
} | } |
|
#endif |
while (connection->refcount.get()) { } | while (connection->refcount.get()) { } |
delete connection; | delete connection; |
} | } |
|
|
return; | return; |
| |
// Accept the connection (populate the address): | // Accept the connection (populate the address): |
|
|
struct sockaddr* accept_address; | struct sockaddr* accept_address; |
PEGASUS_SOCKLEN_T address_size; | PEGASUS_SOCKLEN_T address_size; |
| |
|
|
_rep->connections.append(connection); | _rep->connections.append(connection); |
} | } |
| |
#ifdef PEGASUS_OS_TYPE_WINDOWS |
// Added for NamedPipe implementation for windows |
|
#if defined PEGASUS_OS_TYPE_WINDOWS && !defined(PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET) |
void HTTPAcceptor::_createNamedPipe() | void HTTPAcceptor::_createNamedPipe() |
{ | { |
#ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG | #ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG |
|
|
PEGASUS_STD(cout) << "Entering HTTPAcceptor::_createNamedPipe()." << PEGASUS_STD(endl); | PEGASUS_STD(cout) << "Entering HTTPAcceptor::_createNamedPipe()." << PEGASUS_STD(endl); |
} | } |
#endif | #endif |
_rep->namedPipeServer = new NamedPipeServer("\\\\.\\pipe\\MyNamedPipe"); |
_rep->namedPipeServer = new NamedPipeServer(PEGASUS_NAMEDPIPE_PATH); |
#ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG | #ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG |
{ | { |
AutoMutex automut(Monitor::_cout_mut); | AutoMutex automut(Monitor::_cout_mut); |
|
|
delete _rep; | delete _rep; |
_rep = 0; | _rep = 0; |
//l10n | //l10n |
//throw BindFailedException("Failed to solicit socket messaeges"); |
|
MessageLoaderParms parms("Common.HTTPAcceptor.FAILED_SOLICIT_SOCKET_MESSAGES", | MessageLoaderParms parms("Common.HTTPAcceptor.FAILED_SOLICIT_SOCKET_MESSAGES", |
"Failed to solicit socket messaeges"); | "Failed to solicit socket messaeges"); |
PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2, | PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
|
|
#ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG | #ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG |
{ | { |
AutoMutex automut(Monitor::_cout_mut); //added | AutoMutex automut(Monitor::_cout_mut); //added |
PEGASUS_STD(cout) << "in HTTPAcceptor::_createNamedPipe() _monitor->solicitSocketMessages failed" << PEGASUS_STD(endl); |
PEGASUS_STD(cout) << "in HTTPAcceptor::_createNamedPipe() _monitor->solicitSocketMessages failed" |
|
<< PEGASUS_STD(endl); |
} | } |
#endif | #endif |
} | } |
|
|
} | } |
#endif | #endif |
return; | return; |
|
|
} | } |
#endif |
|
|
|
| |
#ifdef PEGASUS_OS_TYPE_WINDOWS |
|
void HTTPAcceptor::_acceptNamedPipeConnection() | void HTTPAcceptor::_acceptNamedPipeConnection() |
{ | { |
PEGASUS_ASSERT(_rep != 0); | PEGASUS_ASSERT(_rep != 0); |
| |
if (!_rep) | if (!_rep) |
return; | return; |
{ |
|
#ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG | #ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG |
|
{ |
AutoMutex automut(Monitor::_cout_mut); | AutoMutex automut(Monitor::_cout_mut); |
cout <<"In HTTPAcceptor::_acceptNamedPipeConnection " << endl; | cout <<"In HTTPAcceptor::_acceptNamedPipeConnection " << endl; |
#endif |
|
} | } |
|
#endif |
| |
// shouldnt we be using the private var.... |
|
// _namedPipeServer->accept() |
|
| |
NamedPipeServerEndPiont nPSEndPoint = _rep->namedPipeServer->accept(); | NamedPipeServerEndPiont nPSEndPoint = _rep->namedPipeServer->accept(); |
// Registerpe to receive Messages on Connection pipe: |
// Register to receive Messages on Connection pipe: |
#ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG | #ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG |
{ | { |
AutoMutex automut(Monitor::_cout_mut); | AutoMutex automut(Monitor::_cout_mut); |
|
|
HTTPConnection* connection = new HTTPConnection(_monitor, nPSEndPoint, | HTTPConnection* connection = new HTTPConnection(_monitor, nPSEndPoint, |
this, static_cast<MessageQueue *>(_outputMessageQueue), _exportConnection); | this, static_cast<MessageQueue *>(_outputMessageQueue), _exportConnection); |
| |
/* NOT SURE WHAT TO DO HERE .... |
|
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; |
#ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG | #ifdef PEGASUS_LOCALDOMAINSOCKET_DEBUG |
|
|
Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, | Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
"HTTPAcceptor::_acceptPipeConnection: Attempt to allocate entry in _entries table failed."); | "HTTPAcceptor::_acceptPipeConnection: Attempt to allocate entry in _entries table failed."); |
delete connection; | delete connection; |
// May have to close the PIPE here... |
|
//Socket::close(socket); |
|
return; | return; |
} | } |
| |