(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.106.2.1 and 1.116

version 1.106.2.1, 2007/12/14 20:31:37 version 1.116, 2008/02/26 19:15:05
Line 99 
Line 99 
  
     ~HTTPAcceptorRep()     ~HTTPAcceptorRep()
     {     {
           closeSocket();
         delete address;         delete address;
     }     }
   
       void closeSocket()
       {
           Socket::close(socket);
       }
   
     struct sockaddr* address;     struct sockaddr* address;
  
     SocketLength address_size;     SocketLength address_size;
Line 389 
Line 396 
         MessageLoaderParms parms("Common.HTTPAcceptor.FAILED_CREATE_SOCKET",         MessageLoaderParms parms("Common.HTTPAcceptor.FAILED_CREATE_SOCKET",
             "Failed to create socket");             "Failed to create socket");
         PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,         PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
             "HTTPAcceptor::_bind _rep->socket < 0");              "HTTPAcceptor::_bind:  createSocket() _rep->socket failed");
         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 425 
Line 433 
     if (setsockopt(_rep->socket, SOL_SOCKET, SO_REUSEADDR,     if (setsockopt(_rep->socket, SOL_SOCKET, SO_REUSEADDR,
             (char *)&opt, sizeof(opt)) < 0)             (char *)&opt, sizeof(opt)) < 0)
     {     {
         Socket::close(_rep->socket);  
         delete _rep;         delete _rep;
         _rep = 0;         _rep = 0;
         MessageLoaderParms parms("Common.HTTPAcceptor.FAILED_SET_SOCKET_OPTION",         MessageLoaderParms parms("Common.HTTPAcceptor.FAILED_SET_SOCKET_OPTION",
Line 441 
Line 448 
     //     //
     if (::bind(_rep->socket, _rep->address, _rep->address_size) < 0)     if (::bind(_rep->socket, _rep->address, _rep->address_size) < 0)
     {     {
         Socket::close(_rep->socket);          MessageLoaderParms parms(
               "Common.HTTPAcceptor.FAILED_BIND_SOCKET_DETAIL",
               "Failed to bind socket on port $0: $1.",
               _portNumber, PEGASUS_SYSTEM_NETWORK_ERRORMSG_NLS);
   
         delete _rep;         delete _rep;
         _rep = 0;         _rep = 0;
         MessageLoaderParms parms("Common.HTTPAcceptor.FAILED_BIND_SOCKET",  
             "Failed to bind socket");  
         PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,         PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
             "HTTPAcceptor::_bind: Failed to bind socket.");             "HTTPAcceptor::_bind: Failed to bind socket.");
         throw BindFailedException(parms);         throw BindFailedException(parms);
Line 481 
Line 490 
                 S_IRGRP | S_IWGRP | S_IXGRP |                 S_IRGRP | S_IWGRP | S_IXGRP |
                 S_IROTH | S_IWOTH | S_IXOTH ) < 0 )                 S_IROTH | S_IWOTH | S_IXOTH ) < 0 )
         {         {
             Socket::close(_rep->socket);              MessageLoaderParms parms(
                   "Common.HTTPAcceptor.FAILED_SET_LDS_FILE_OPTION",
                   "Failed to set permission on local domain socket {0}: {1}.",
                   PEGASUS_LOCAL_DOMAIN_SOCKET_PATH,
                   PEGASUS_SYSTEM_ERRORMSG_NLS );
   
             delete _rep;             delete _rep;
             _rep = 0;             _rep = 0;
             MessageLoaderParms parms("Common.HTTPAcceptor.FAILED_BIND_SOCKET",  
                 "Failed to bind socket");  
             PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,             PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
                 "HTTPAcceptor::_bind: Failed to set domain socket "                 "HTTPAcceptor::_bind: Failed to set domain socket "
                     "permissions.");                     "permissions.");
Line 498 
Line 510 
  
     //int const _maxConnectionQueueLength = 15;     //int const _maxConnectionQueueLength = 15;
  
     if (listen(_rep->socket, _maxConnectionQueueLength) < 0)      if (::listen(_rep->socket, _maxConnectionQueueLength) < 0)
     {     {
         Socket::close(_rep->socket);          MessageLoaderParms parms(
               "Common.HTTPAcceptor.FAILED_LISTEN_SOCKET",
               "Failed to listen on socket {0}: {1}.",
               (int)_rep->socket,PEGASUS_SYSTEM_NETWORK_ERRORMSG_NLS );
   
         delete _rep;         delete _rep;
         _rep = 0;         _rep = 0;
         MessageLoaderParms parms("Common.HTTPAcceptor.FAILED_BIND_SOCKET",  
             "Failed to bind socket");  
         PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,         PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
             "HTTPAcceptor::_bind: Failed to bind socket(1).");             "HTTPAcceptor::_bind: Failed to bind socket(1).");
         throw BindFailedException(parms);         throw BindFailedException(parms);
Line 516 
Line 530 
             _rep->socket,             _rep->socket,
             SocketMessage::READ | SocketMessage::EXCEPTION,             SocketMessage::READ | SocketMessage::EXCEPTION,
             getQueueId(),             getQueueId(),
             Monitor::ACCEPTOR)))              MonitorEntry::TYPE_ACCEPTOR)))
     {     {
         Socket::close(_rep->socket);  
         delete _rep;         delete _rep;
         _rep = 0;         _rep = 0;
         MessageLoaderParms parms(         MessageLoaderParms parms(
Line 544 
Line 557 
         //_monitor->unsolicitSocketMessages(_rep->socket);         //_monitor->unsolicitSocketMessages(_rep->socket);
  
         // close the socket         // close the socket
         Socket::close(_rep->socket);          _rep->closeSocket();
         // Unlink Local Domain Socket Bug# 3312         // Unlink Local Domain Socket Bug# 3312
         if (_connectionType == LOCAL_CONNECTION)         if (_connectionType == LOCAL_CONNECTION)
         {         {
Line 593 
Line 606 
         // unregister the socket         // unregister the socket
         _monitor->unsolicitSocketMessages(_rep->socket);         _monitor->unsolicitSocketMessages(_rep->socket);
         // close the socket         // close the socket
         Socket::close(_rep->socket);          _rep->closeSocket();
         // Unlink Local Domain Socket Bug# 3312          // Unlink Local Domain Socket
         if (_connectionType == LOCAL_CONNECTION)         if (_connectionType == LOCAL_CONNECTION)
         {         {
 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
Line 626 
Line 639 
     if (_rep)     if (_rep)
     {     {
         AutoMutex autoMut(_rep->_connection_mut);         AutoMutex autoMut(_rep->_connection_mut);
         if (_rep->connections.size() > 0)          for (Uint32 i = 0, n = _rep->connections.size(); i < n; i++)
           {
               HTTPConnection* connection = _rep->connections[i];
               if (connection->isResponsePending())
         {         {
             HTTPConnection* connection = _rep->connections[0];                  count++;
             count = connection->getRequestCount();              }
         }         }
     }     }
     return count;     return count;
Line 659 
Line 675 
     if (_rep)     if (_rep)
     {     {
         _portNumber = 0;         _portNumber = 0;
         Socket::close(_rep->socket);          _rep->closeSocket();
  
         if (_connectionType == LOCAL_CONNECTION)         if (_connectionType == LOCAL_CONNECTION)
         {         {
Line 742 
Line 758 
 #endif #endif
     }     }
  
     SocketHandle socket;      // It is not necessary to handle EINTR errors from this accept() call.
 #ifdef PEGASUS_OS_TYPE_WINDOWS      // An EINTR error should not occur on a non-blocking socket.  If the
     socket = accept(_rep->socket, accept_address, &address_size);      // listen socket is blocking and EINTR occurs, the new socket connection
 #else      // is not accepted here.
     while (  
         ((socket = accept(_rep->socket, accept_address, &address_size)) == -1)      // EAGAIN errors are also not handled here.  An EAGAIN error should not
         && (errno == EINTR))      // occur after select() indicates that the listen socket is available for
         ;      // reading.  If the accept() fails with an EAGAIN error code, a new
 #endif      // connection is not accepted here.
   
       SocketHandle socket = accept(_rep->socket, accept_address, &address_size);
  
     if (socket == PEGASUS_SOCKET_ERROR)     if (socket == PEGASUS_SOCKET_ERROR)
     {     {
Line 776 
Line 794 
         return;         return;
     }     }
  
       // Use an AutoPtr to ensure the socket handle is closed on exception
       AutoPtr<SocketHandle, CloseSocketHandle> socketPtr(&socket);
   
   #ifndef PEGASUS_OS_TYPE_WINDOWS
       // We need to ensure that the socket number is not higher than
       // what fits into FD_SETSIZE, because we else won't be able to select on it
       // and won't ever communicate correct on that socket.
       if (socket >= FD_SETSIZE)
       {
           // the remote connection is invalid, destroy client address.
           delete accept_address;
   
           Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,
               "HTTPAcceptor out of available sockets. "
                   "Closing connection to the new client.");
   
           PEG_TRACE(
               (TRC_DISCARDED_DATA,
                Tracer::LEVEL2,
                "accept() returned too large socket number %d.",
                socket));
   
           return;
       }
   #endif
   
     String ipAddress;     String ipAddress;
  
     if (_connectionType == LOCAL_CONNECTION)     if (_connectionType == LOCAL_CONNECTION)
Line 801 
Line 845 
             PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,             PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
                 "HTTPAcceptor: getnameinfo() failed");                 "HTTPAcceptor: getnameinfo() failed");
             delete accept_address;             delete accept_address;
             Socket::close(socket);  
             return;             return;
         }         }
         ipAddress = ipBuffer;         ipAddress = ipBuffer;
Line 842 
Line 885 
  
     SharedPtr<MP_Socket> mp_socket(new MP_Socket(     SharedPtr<MP_Socket> mp_socket(new MP_Socket(
         socket, _sslcontext, _sslContextObjectLock, ipAddress));         socket, _sslcontext, _sslContextObjectLock, ipAddress));
       // mp_socket now has responsibility for closing the socket handle
       socketPtr.release();
  
       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)
     {     {
         PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,         PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
             "HTTPAcceptor: SSL_accept() failed");             "HTTPAcceptor: SSL_accept() failed");
         mp_socket->close();  
         return;         return;
     }     }
  
     // Create a new connection and add it to the connection list:     // Create a new connection and add it to the connection list:
  
     HTTPConnection* connection = new HTTPConnection(_monitor, mp_socket,      AutoPtr<HTTPConnection> connection(new HTTPConnection(
         ipAddress, this, static_cast<MessageQueue *>(_outputMessageQueue));          _monitor,
           mp_socket,
           ipAddress,
           this,
           static_cast<MessageQueue *>(_outputMessageQueue)));
  
     if (_idleConnectionTimeoutSeconds)     if (_idleConnectionTimeoutSeconds)
     {     {
Line 887 
Line 932 
     if (-1 ==  (index = _monitor->solicitSocketMessages(     if (-1 ==  (index = _monitor->solicitSocketMessages(
             connection->getSocket(),             connection->getSocket(),
             SocketMessage::READ | SocketMessage::EXCEPTION,             SocketMessage::READ | SocketMessage::EXCEPTION,
             connection->getQueueId(), Monitor::CONNECTION)) )              connection->getQueueId(), MonitorEntry::TYPE_CONNECTION)) )
     {     {
         // ATTN-DE-P2-2003100503::TODO::Need to enhance code to return  
         // an error message to Client application.  
         PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,         PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
             "HTTPAcceptor::_acceptConnection: Attempt to allocate entry in "             "HTTPAcceptor::_acceptConnection: Attempt to allocate entry in "
                 "_entries table failed.");                 "_entries table failed.");
         delete connection;  
         Socket::close(socket);  
         return;         return;
     }     }
  
     // Save the socket for cleanup later:  
     connection->_entry_index = index;     connection->_entry_index = index;
     AutoMutex autoMut(_rep->_connection_mut);     AutoMutex autoMut(_rep->_connection_mut);
     _rep->connections.append(connection);      _rep->connections.append(connection.get());
       connection.release();
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.106.2.1  
changed lines
  Added in v.1.116

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2