Ejemplo n.º 1
0
int
Acceptor::validate_connection(const ACE_Asynch_Accept::Result&  result,
                              const ACE_INET_Addr& /*remote*/,
                              const ACE_INET_Addr& /*local*/)
{
  ACE_GUARD_RETURN (ACE_SYNCH_RECURSIVE_MUTEX, monitor, this->mutex(),-1);

  --this->ref_cnt_;

  int rc = 0;

  if (!result.success())
    {
      ACE_Errno_Guard g (errno);
      errno = result.error();
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%t) Acceptor: %p\n"),
                  ACE_TEXT ("accept failed")));
      rc = -1;
    }
  
  if (this->should_finish ())
    {
      rc = -1;
    }

  return rc;
}
Ejemplo n.º 2
0
int
Acceptor::validate_connection(const ACE_Asynch_Accept::Result&  result,
                              const ACE_INET_Addr& /*remote*/,
                              const ACE_INET_Addr& /*local*/)
{
    int rc = 0;

    if (!result.success())
    {
        ACE_Errno_Guard g (errno);

        ACE_Log_Msg::instance ()->errnum (result.error ());
        ACE_OS::last_error (result.error ());

        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%t) Acceptor: error=%d %p\n"),
                    (int) result.error(),
                    ACE_TEXT ("accept failed")));

        rc = -1;
    }
    return rc;
}
Ejemplo n.º 3
0
template <class HANDLER> void
ACE_Asynch_Acceptor<HANDLER>::handle_accept (const ACE_Asynch_Accept::Result &result)
{
  ACE_TRACE ("ACE_Asynch_Acceptor<>::handle_accept");

  // Variable for error tracking
  int error = 0;

  // If the asynchronous accept fails.
  if (!result.success () || result.accept_handle () == ACE_INVALID_HANDLE)
    {
      error = 1;
    }

#if defined (ACE_WIN32)
  // In order to use accept handle with other Window Sockets 1.1
  // functions, we call the setsockopt function with the
  // SO_UPDATE_ACCEPT_CONTEXT option. This option initializes the
  // socket so that other Windows Sockets routines to access the
  // socket correctly.
  if (!error &&
      ACE_OS::setsockopt (result.accept_handle (),
                          SOL_SOCKET,
                          SO_UPDATE_ACCEPT_CONTEXT,
                          (char *) &this->listen_handle_,
                          sizeof (this->listen_handle_)) == -1)
    {
      error = 1;
    }
#endif /* ACE_WIN32 */

  // Parse address.
  ACE_INET_Addr local_address;
  ACE_INET_Addr remote_address;
  if (!error &&
      (this->validate_new_connection_ || this->pass_addresses_))
    // Parse the addresses.
    this->parse_address (result,
                         remote_address,
                         local_address);

  // Validate remote address
  if (!error &&
      this->validate_new_connection_ &&
      (this->validate_connection (result, remote_address, local_address) == -1))
    {
      error = 1;
    }

  HANDLER *new_handler = 0;
  if (!error)
    {
      // The Template method
      new_handler = this->make_handler ();
      if (new_handler == 0)
        {
          error = 1;
        }
    }

  // If no errors
  if (!error)
    {
      // Update the Proactor.
      new_handler->proactor (this->proactor ());

      // Pass the addresses
      if (this->pass_addresses_)
        new_handler->addresses (remote_address,
                                local_address);

      // Pass the ACT
      if (result.act () != 0)
        new_handler->act (result.act ());

      // Set up the handler's new handle value
      new_handler->handle (result.accept_handle ());

      // Initiate the handler
      new_handler->open (result.accept_handle (),
                         result.message_block ());
    }

  // On failure, no choice but to close the socket
  if (error &&
      result.accept_handle() != ACE_INVALID_HANDLE )
    ACE_OS::closesocket (result.accept_handle ());

  // Delete the dynamically allocated message_block
  result.message_block ().release ();

  // Start off another asynchronous accept to keep the backlog going,
  // unless we closed the listen socket already (from the destructor),
  // or this callback is the result of a canceled/aborted accept.
  if (this->should_reissue_accept () &&
      this->listen_handle_ != ACE_INVALID_HANDLE
#if defined (ACE_WIN32)
      && result.error () != ERROR_OPERATION_ABORTED
#else
      && result.error () != ECANCELED
#endif
      )
    this->accept (this->bytes_to_read_, result.act ());
}