(file) Return to HTTPAcceptor.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/HTTPAcceptor.cpp between version 1.93.4.1 and 1.93.4.4

version 1.93.4.1, 2007/04/04 11:04:44 version 1.93.4.4, 2008/01/02 21:05:03
Line 40 
Line 40 
 #include "TLS.h" #include "TLS.h"
 #include "HTTPAcceptor.h" #include "HTTPAcceptor.h"
 #include "HTTPConnection.h" #include "HTTPConnection.h"
   #include "HostAddress.h"
 #include "Tracer.h" #include "Tracer.h"
 #include <Pegasus/Common/MessageLoader.h> #include <Pegasus/Common/MessageLoader.h>
  
Line 64 
Line 65 
 class HTTPAcceptorRep class HTTPAcceptorRep
 { {
 public: public:
     HTTPAcceptorRep(Boolean local)      HTTPAcceptorRep(Uint16 connectionType)
     {     {
         if (local)          if (connectionType == HTTPAcceptor::LOCAL_CONNECTION)
         {         {
 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
             address =             address =
Line 76 
Line 77 
             PEGASUS_ASSERT(false);             PEGASUS_ASSERT(false);
 #endif #endif
         }         }
         else  #ifdef PEGASUS_ENABLE_IPV6
           else if (connectionType == HTTPAcceptor::IPV6_CONNECTION)
           {
               address =
                   reinterpret_cast<struct sockaddr*>(new struct sockaddr_in6);
               address_size = sizeof(struct sockaddr_in6);
           }
   #endif
           else if (connectionType == HTTPAcceptor::IPV4_CONNECTION)
         {         {
             address =             address =
                 reinterpret_cast<struct sockaddr*>(new struct sockaddr_in);                 reinterpret_cast<struct sockaddr*>(new struct sockaddr_in);
             address_size = sizeof(struct sockaddr_in);             address_size = sizeof(struct sockaddr_in);
         }         }
           else
           {
               PEGASUS_ASSERT(false);
       }
     }     }
   
     ~HTTPAcceptorRep()     ~HTTPAcceptorRep()
     {     {
         delete address;         delete address;
Line 105 
Line 119 
  
 HTTPAcceptor::HTTPAcceptor(Monitor* monitor, HTTPAcceptor::HTTPAcceptor(Monitor* monitor,
                            MessageQueue* outputMessageQueue,                            MessageQueue* outputMessageQueue,
                            Boolean localConnection,                             Uint16 connectionType,
                            Uint32 portNumber,                            Uint32 portNumber,
                            SSLContext * sslcontext,                            SSLContext * sslcontext,
                            ReadWriteSem* sslContextObjectLock)                            ReadWriteSem* sslContextObjectLock)
Line 114 
Line 128 
      _outputMessageQueue(outputMessageQueue),      _outputMessageQueue(outputMessageQueue),
      _rep(0),      _rep(0),
      _entry_index(-1),      _entry_index(-1),
      _localConnection(localConnection),       _connectionType(connectionType),
      _portNumber(portNumber),      _portNumber(portNumber),
      _sslcontext(sslcontext),      _sslcontext(sslcontext),
      _sslContextObjectLock(sslContextObjectLock)       _sslContextObjectLock(sslContextObjectLock),
        _idleConnectionTimeoutSeconds(0)
 { {
    Socket::initializeInterface();    Socket::initializeInterface();
  
Line 264 
Line 279 
         throw BindFailedException(parms);         throw BindFailedException(parms);
     }     }
  
     _rep = new HTTPAcceptorRep(_localConnection);      _rep = new HTTPAcceptorRep(_connectionType);
  
     // bind address     // bind address
     _bind();     _bind();
Line 279 
Line 294 
 { {
     PEGASUS_ASSERT(_rep != 0);     PEGASUS_ASSERT(_rep != 0);
     // Create address:     // Create address:
       memset(_rep->address, 0, _rep->address_size);
  
     memset(_rep->address, 0, sizeof(*_rep->address));      if (_connectionType == LOCAL_CONNECTION)
   
     if (_localConnection)  
     {     {
 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
         reinterpret_cast<struct sockaddr_un*>(_rep->address)->sun_family =         reinterpret_cast<struct sockaddr_un*>(_rep->address)->sun_family =
Line 298 
Line 312 
         PEGASUS_ASSERT(false);         PEGASUS_ASSERT(false);
 #endif #endif
     }     }
     else  #ifdef PEGASUS_ENABLE_IPV6
       else if (_connectionType == IPV6_CONNECTION)
       {
           reinterpret_cast<struct sockaddr_in6*>(_rep->address)->sin6_addr =
               in6addr_any;
           reinterpret_cast<struct sockaddr_in6*>(_rep->address)->sin6_family =
               AF_INET6;
           reinterpret_cast<struct sockaddr_in6*>(_rep->address)->sin6_port =
               htons(_portNumber);
       }
   #endif
       else if(_connectionType == IPV4_CONNECTION)
     {     {
         reinterpret_cast<struct sockaddr_in*>(_rep->address)->sin_addr.s_addr =         reinterpret_cast<struct sockaddr_in*>(_rep->address)->sin_addr.s_addr =
             INADDR_ANY;             INADDR_ANY;
Line 307 
Line 332 
         reinterpret_cast<struct sockaddr_in*>(_rep->address)->sin_port =         reinterpret_cast<struct sockaddr_in*>(_rep->address)->sin_port =
             htons(_portNumber);             htons(_portNumber);
     }     }
       else
       {
           PEGASUS_ASSERT(false);
       }
  
     // Create socket:     // Create socket:
  
     if (_localConnection)      if (_connectionType == LOCAL_CONNECTION)
     {     {
         _rep->socket = Socket::createSocket(AF_UNIX, SOCK_STREAM, 0);         _rep->socket = Socket::createSocket(AF_UNIX, SOCK_STREAM, 0);
     }     }
     else  #ifdef PEGASUS_ENABLE_IPV6
       else if (_connectionType == IPV6_CONNECTION)
       {
           _rep->socket = Socket::createSocket(PF_INET6, SOCK_STREAM, IPPROTO_TCP);
       }
   #endif
       else if (_connectionType == IPV4_CONNECTION)
     {     {
         _rep->socket = Socket::createSocket(PF_INET, SOCK_STREAM, IPPROTO_TCP);         _rep->socket = Socket::createSocket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
     }     }
       else
       {
           PEGASUS_ASSERT(false);
       }
  
     if (_rep->socket < 0)     if (_rep->socket < 0)
     {     {
Line 330 
Line 369 
         throw BindFailedException(parms);         throw BindFailedException(parms);
     }     }
  
       Socket::disableBlocking(_rep->socket);
  
 // set the close-on-exec bit for this file handle. // set the close-on-exec bit for this file handle.
 // any unix that forks needs this bit set. // any unix that forks needs this bit set.
Line 411 
Line 451 
 #if !defined(PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET) && \ #if !defined(PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET) && \
      (defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || \      (defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || \
       defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM))       defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM))
     if (_localConnection)      if (_connectionType == LOCAL_CONNECTION)
     {     {
         if (::chmod(PEGASUS_LOCAL_DOMAIN_SOCKET_PATH,         if (::chmod(PEGASUS_LOCAL_DOMAIN_SOCKET_PATH,
                 S_IRUSR | S_IWUSR | S_IXUSR |                 S_IRUSR | S_IWUSR | S_IXUSR |
Line 483 
Line 523 
         // close the socket         // close the socket
         Socket::close(_rep->socket);         Socket::close(_rep->socket);
         // Unlink Local Domain Socket Bug# 3312         // Unlink Local Domain Socket Bug# 3312
         if (_localConnection)          if (_connectionType == LOCAL_CONNECTION)
         {         {
 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
             PEG_TRACE_CSTRING(TRC_HTTP, Tracer::LEVEL2,             PEG_TRACE_CSTRING(TRC_HTTP, Tracer::LEVEL2,
Line 532 
Line 572 
         // close the socket         // close the socket
         Socket::close(_rep->socket);         Socket::close(_rep->socket);
         // Unlink Local Domain Socket Bug# 3312         // Unlink Local Domain Socket Bug# 3312
         if (_localConnection)          if (_connectionType == LOCAL_CONNECTION)
         {         {
 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
             PEG_TRACE_CSTRING(TRC_HTTP, Tracer::LEVEL2,             PEG_TRACE_CSTRING(TRC_HTTP, Tracer::LEVEL2,
Line 586 
Line 626 
     _socketWriteTimeout = socketWriteTimeout;     _socketWriteTimeout = socketWriteTimeout;
 } }
  
   void HTTPAcceptor::setIdleConnectionTimeout(Uint32 idleConnectionTimeoutSeconds)
   {
       _idleConnectionTimeoutSeconds = idleConnectionTimeoutSeconds;
   }
   
 void HTTPAcceptor::unbind() void HTTPAcceptor::unbind()
 { {
     if (_rep)     if (_rep)
Line 593 
Line 638 
         _portNumber = 0;         _portNumber = 0;
         Socket::close(_rep->socket);         Socket::close(_rep->socket);
  
         if (_localConnection)          if (_connectionType == LOCAL_CONNECTION)
         {         {
 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
             ::unlink(             ::unlink(
Line 650 
Line 695 
     struct sockaddr* accept_address;     struct sockaddr* accept_address;
     SocketLength address_size;     SocketLength address_size;
  
     if (_localConnection)      if (_connectionType == LOCAL_CONNECTION)
     {     {
 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
         accept_address =         accept_address =
Line 662 
Line 707 
     }     }
     else     else
     {     {
   #ifdef PEGASUS_ENABLE_IPV6
           accept_address =
              reinterpret_cast<struct sockaddr*>
              (new struct sockaddr_storage);
           address_size = sizeof(struct sockaddr_storage);
   #else
         accept_address =         accept_address =
             reinterpret_cast<struct sockaddr*>(new struct sockaddr_in);             reinterpret_cast<struct sockaddr*>(new struct sockaddr_in);
         address_size = sizeof(struct sockaddr_in);         address_size = sizeof(struct sockaddr_in);
   #endif
     }     }
  
       // It is not necessary to handle EINTR errors from this accept() call.
       // An EINTR error should not occur on a non-blocking socket.  If the
       // listen socket is blocking and EINTR occurs, the new socket connection
       // is not accepted here.
   
       // EAGAIN errors are also not handled here.  An EAGAIN error should not
       // occur after select() indicates that the listen socket is available for
       // reading.  If the accept() fails with an EAGAIN error code, a new
       // connection is not accepted here.
   
     SocketHandle socket = accept(_rep->socket, accept_address, &address_size);     SocketHandle socket = accept(_rep->socket, accept_address, &address_size);
  
     if (socket == PEGASUS_SOCKET_ERROR)     if (socket == PEGASUS_SOCKET_ERROR)
Line 695 
Line 757 
  
     String ipAddress;     String ipAddress;
  
     if (_localConnection)      if (_connectionType == LOCAL_CONNECTION)
     {     {
         ipAddress = "localhost";         ipAddress = "localhost";
     }     }
     else     else
     {     {
   #ifdef PEGASUS_ENABLE_IPV6
           char ipBuffer[PEGASUS_INET6_ADDRSTR_LEN];
           int rc;
           while ((rc = getnameinfo(accept_address, address_size, ipBuffer,
               PEGASUS_INET6_ADDRSTR_LEN, 0, 0, NI_NUMERICHOST)) == EAI_AGAIN)
               ;
           if (rc)
           {
               Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,
                   "HTTPAcceptor - getnameinfo() failure.  rc: $0", rc);
   
               PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
                   "HTTPAcceptor: getnameinfo() failed");
               delete accept_address;
               Socket::close(socket);
               return;
           }
           ipAddress = ipBuffer;
   #else
         unsigned char* sa = reinterpret_cast<unsigned char*>(         unsigned char* sa = reinterpret_cast<unsigned char*>(
             &reinterpret_cast<struct sockaddr_in*>(             &reinterpret_cast<struct sockaddr_in*>(
                 accept_address)->sin_addr.s_addr);                 accept_address)->sin_addr.s_addr);
         char ipBuffer[32];         char ipBuffer[32];
         sprintf(ipBuffer, "%u.%u.%u.%u", sa[0], sa[1], sa[2], sa[3]);         sprintf(ipBuffer, "%u.%u.%u.%u", sa[0], sa[1], sa[2], sa[3]);
         ipAddress = ipBuffer;         ipAddress = ipBuffer;
   #endif
     }     }
  
     delete accept_address;     delete accept_address;
Line 737 
Line 819 
     AutoPtr<MP_Socket> mp_socket(new MP_Socket(     AutoPtr<MP_Socket> mp_socket(new MP_Socket(
         socket, _sslcontext, _sslContextObjectLock));         socket, _sslcontext, _sslContextObjectLock));
  
       mp_socket->disableBlocking();
     mp_socket->setSocketWriteTimeout(_socketWriteTimeout);     mp_socket->setSocketWriteTimeout(_socketWriteTimeout);
  
     // Perform the SSL handshake, if applicable.  Make the socket non-blocking      // Perform the SSL handshake, if applicable.
     // 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();     Sint32 socketAcceptStatus = mp_socket->accept();
     mp_socket->enableBlocking();  
  
     if (socketAcceptStatus < 0)     if (socketAcceptStatus < 0)
     {     {
Line 760 
Line 839 
     HTTPConnection* connection = new HTTPConnection(_monitor, mp_socket,     HTTPConnection* connection = new HTTPConnection(_monitor, mp_socket,
         ipAddress, this, static_cast<MessageQueue *>(_outputMessageQueue));         ipAddress, this, static_cast<MessageQueue *>(_outputMessageQueue));
  
       if (_idleConnectionTimeoutSeconds)
       {
           connection->_idleConnectionTimeoutSeconds =
               _idleConnectionTimeoutSeconds;
           Time::gettimeofday(&connection->_idleStartTime);
       }
   
     if (socketAcceptStatus == 0)     if (socketAcceptStatus == 0)
     {     {
         PEG_TRACE_CSTRING(TRC_HTTP, Tracer::LEVEL2,         PEG_TRACE_CSTRING(TRC_HTTP, Tracer::LEVEL2,
             "HTTPAcceptor: SSL_accept() pending");             "HTTPAcceptor: SSL_accept() pending");
         connection->_acceptPending = true;         connection->_acceptPending = true;
           Time::gettimeofday(&connection->_acceptPendingStartTime);
     }     }
  
     // Solicit events on this new connection's socket:     // Solicit events on this new connection's socket:


Legend:
Removed from v.1.93.4.1  
changed lines
  Added in v.1.93.4.4

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2