Defines a factory that creates new ACE_Streams passively. More...
#include <SOCK_Acceptor.h>
Public Types | |
typedef ACE_INET_Addr | PEER_ADDR |
typedef ACE_SOCK_Stream | PEER_STREAM |
Public Member Functions | |
ACE_SOCK_Acceptor (void) | |
Default constructor. | |
ACE_SOCK_Acceptor (const ACE_Addr &local_sap, int reuse_addr=0, int protocol_family=PF_UNSPEC, int backlog=ACE_DEFAULT_BACKLOG, int protocol=0) | |
ACE_SOCK_Acceptor (const ACE_Addr &local_sap, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g, u_long flags, int reuse_addr, int protocol_family=PF_UNSPEC, int backlog=ACE_DEFAULT_BACKLOG, int protocol=0) | |
int | open (const ACE_Addr &local_sap, int reuse_addr=0, int protocol_family=PF_UNSPEC, int backlog=ACE_DEFAULT_BACKLOG, int protocol=0) |
int | open (const ACE_Addr &local_sap, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g, u_long flags, int reuse_addr, int protocol_family=PF_UNSPEC, int backlog=ACE_DEFAULT_BACKLOG, int protocol=0) |
int | close (void) |
Close the socket. Returns 0 on success and -1 on failure. | |
~ACE_SOCK_Acceptor (void) | |
Default dtor. | |
int | accept (ACE_SOCK_Stream &new_stream, ACE_Addr *remote_addr=0, ACE_Time_Value *timeout=0, bool restart=true, bool reset_new_handle=false) const |
int | accept (ACE_SOCK_Stream &new_stream, ACE_Accept_QoS_Params qos_params, ACE_Addr *remote_addr=0, ACE_Time_Value *timeout=0, bool restart=true, bool reset_new_handle=false) const |
void | dump (void) const |
Dump the state of an object. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Protected Member Functions | |
int | shared_accept_start (ACE_Time_Value *timeout, bool restart, int &in_blocking_mode) const |
int | shared_accept_finish (ACE_SOCK_Stream new_stream, int in_blocking_mode, bool reset_new_handle) const |
int | shared_open (const ACE_Addr &local_sap, int protocol_family, int backlog) |
Private Member Functions | |
int | get_remote_addr (ACE_Addr &) const |
Do not allow this function to percolate up to this interface... |
Defines a factory that creates new ACE_Streams passively.
The ACE_SOCK_Acceptor has its own "passive-mode" socket. This serves as a factory to create so-called "data-mode" sockets, which are what the ACE_SOCK_Stream encapsulates. Therefore, by inheriting from ACE_SOCK, ACE_SOCK_Acceptor gets its very own socket.
Definition at line 39 of file SOCK_Acceptor.h.
Reimplemented in ACE_LSOCK_Acceptor.
Definition at line 135 of file SOCK_Acceptor.h.
Reimplemented in ACE_LSOCK_Acceptor.
Definition at line 136 of file SOCK_Acceptor.h.
ACE_SOCK_Acceptor::ACE_SOCK_Acceptor | ( | void | ) |
Default constructor.
Definition at line 27 of file SOCK_Acceptor.cpp.
{ ACE_TRACE ("ACE_SOCK_Acceptor::ACE_SOCK_Acceptor"); }
ACE_SOCK_Acceptor::ACE_SOCK_Acceptor | ( | const ACE_Addr & | local_sap, | |
int | reuse_addr = 0 , |
|||
int | protocol_family = PF_UNSPEC , |
|||
int | backlog = ACE_DEFAULT_BACKLOG , |
|||
int | protocol = 0 | |||
) |
Initialize a passive-mode BSD-style acceptor socket (no QoS). local_sap is the address that we're going to listen for connections on. If reuse_addr is 1 then we'll use the SO_REUSEADDR
to reuse this address.
Definition at line 383 of file SOCK_Acceptor.cpp.
ACE_SOCK_Acceptor::ACE_SOCK_Acceptor | ( | const ACE_Addr & | local_sap, | |
ACE_Protocol_Info * | protocolinfo, | |||
ACE_SOCK_GROUP | g, | |||
u_long | flags, | |||
int | reuse_addr, | |||
int | protocol_family = PF_UNSPEC , |
|||
int | backlog = ACE_DEFAULT_BACKLOG , |
|||
int | protocol = 0 | |||
) |
Initialize a passive-mode QoS-enabled acceptor socket. Returns 0 on success and -1 on failure.
Definition at line 325 of file SOCK_Acceptor.cpp.
ACE_SOCK_Acceptor::~ACE_SOCK_Acceptor | ( | void | ) |
Default dtor.
Definition at line 8 of file SOCK_Acceptor.inl.
{ ACE_TRACE ("ACE_SOCK_Acceptor::~ACE_SOCK_Acceptor"); }
int ACE_SOCK_Acceptor::accept | ( | ACE_SOCK_Stream & | new_stream, | |
ACE_Addr * | remote_addr = 0 , |
|||
ACE_Time_Value * | timeout = 0 , |
|||
bool | restart = true , |
|||
bool | reset_new_handle = false | |||
) | const |
Accept a new ACE_SOCK_Stream connection. A timeout of 0 means block forever, a timeout of {0, 0} means poll. restart == true means "restart if interrupted," i.e., if errno == EINTR. Note that new_stream inherits the "blocking mode" of this
ACE_SOCK_Acceptor, i.e., if this
acceptor factory is in non-blocking mode, the new_stream will be in non-blocking mode and vice versa.
Reimplemented in ACE_LOCK_SOCK_Acceptor< ACE_LOCK >.
Definition at line 105 of file SOCK_Acceptor.cpp.
{ ACE_TRACE ("ACE_SOCK_Acceptor::accept"); int in_blocking_mode = 0; if (this->shared_accept_start (timeout, restart, in_blocking_mode) == -1) return -1; else { // On Win32 the third parameter to <accept> must be a NULL // pointer if we want to ignore the client's address. int *len_ptr = 0; sockaddr *addr = 0; int len = 0; if (remote_addr != 0) { len = remote_addr->get_size (); len_ptr = &len; addr = (sockaddr *) remote_addr->get_addr (); } do new_stream.set_handle (ACE_OS::accept (this->get_handle (), addr, len_ptr)); while (new_stream.get_handle () == ACE_INVALID_HANDLE && restart && errno == EINTR && timeout == 0); // Reset the size of the addr, so the proper UNIX/IPv4/IPv6 family // is known. if (new_stream.get_handle () != ACE_INVALID_HANDLE && remote_addr != 0) { remote_addr->set_size (len); if (addr) remote_addr->set_type (addr->sa_family); } } return this->shared_accept_finish (new_stream, in_blocking_mode, reset_new_handle); }
int ACE_SOCK_Acceptor::accept | ( | ACE_SOCK_Stream & | new_stream, | |
ACE_Accept_QoS_Params | qos_params, | |||
ACE_Addr * | remote_addr = 0 , |
|||
ACE_Time_Value * | timeout = 0 , |
|||
bool | restart = true , |
|||
bool | reset_new_handle = false | |||
) | const |
Accept a new ACE_SOCK_Stream connection using the QoS information in qos_params. A timeout of 0 means block forever, a timeout of {0, 0} means poll. restart == true means "restart if interrupted," i.e., if errno == EINTR. Note that new_stream inherits the "blocking mode" of this
ACE_SOCK_Acceptor, i.e., if this
acceptor factory is in non-blocking mode, the new_stream will be in non-blocking mode and vice versa.
Definition at line 160 of file SOCK_Acceptor.cpp.
{ ACE_TRACE ("ACE_SOCK_Acceptor::accept"); int in_blocking_mode = 0; if (this->shared_accept_start (timeout, restart, in_blocking_mode) == -1) return -1; else { // On Win32 the third parameter to <accept> must be a NULL // pointer if we want to ignore the client's address. int *len_ptr = 0; int len = 0; sockaddr *addr = 0; if (remote_addr != 0) { len = remote_addr->get_size (); len_ptr = &len; addr = (sockaddr *) remote_addr->get_addr (); } do new_stream.set_handle (ACE_OS::accept (this->get_handle (), addr, len_ptr, qos_params)); while (new_stream.get_handle () == ACE_INVALID_HANDLE && restart && errno == EINTR && timeout == 0); // Reset the size of the addr, which is only necessary for UNIX // domain sockets. if (new_stream.get_handle () != ACE_INVALID_HANDLE && remote_addr != 0) remote_addr->set_size (len); } return this->shared_accept_finish (new_stream, in_blocking_mode, reset_new_handle); }
int ACE_SOCK_Acceptor::close | ( | void | ) |
Close the socket. Returns 0 on success and -1 on failure.
Reimplemented from ACE_SOCK.
Definition at line 401 of file SOCK_Acceptor.cpp.
{ return ACE_SOCK::close (); }
void ACE_SOCK_Acceptor::dump | ( | void | ) | const |
Dump the state of an object.
Reimplemented from ACE_SOCK.
Reimplemented in ACE_LSOCK_Acceptor.
Definition at line 213 of file SOCK_Acceptor.cpp.
{ #if defined (ACE_HAS_DUMP) ACE_TRACE ("ACE_SOCK_Acceptor::dump"); #endif /* ACE_HAS_DUMP */ }
int ACE_SOCK_Acceptor::get_remote_addr | ( | ACE_Addr & | ) | const [private] |
Do not allow this function to percolate up to this interface...
Reimplemented from ACE_SOCK.
int ACE_SOCK_Acceptor::open | ( | const ACE_Addr & | local_sap, | |
ACE_Protocol_Info * | protocolinfo, | |||
ACE_SOCK_GROUP | g, | |||
u_long | flags, | |||
int | reuse_addr, | |||
int | protocol_family = PF_UNSPEC , |
|||
int | backlog = ACE_DEFAULT_BACKLOG , |
|||
int | protocol = 0 | |||
) |
Initialize a passive-mode QoS-enabled acceptor socket. Returns 0 on success and -1 on failure.
Definition at line 297 of file SOCK_Acceptor.cpp.
{ ACE_TRACE ("ACE_SOCK_Acceptor::open"); if (protocol_family == PF_UNSPEC) protocol_family = local_sap.get_type (); if (ACE_SOCK::open (SOCK_STREAM, protocol_family, protocol, protocolinfo, g, flags, reuse_addr) == -1) return -1; else return this->shared_open (local_sap, protocol_family, backlog); }
int ACE_SOCK_Acceptor::open | ( | const ACE_Addr & | local_sap, | |
int | reuse_addr = 0 , |
|||
int | protocol_family = PF_UNSPEC , |
|||
int | backlog = ACE_DEFAULT_BACKLOG , |
|||
int | protocol = 0 | |||
) |
Initialize a passive-mode BSD-style acceptor socket (no QoS). local_sap is the address that we're going to listen for connections on. If reuse_addr is 1 then we'll use the SO_REUSEADDR
to reuse this address. Returns 0 on success and -1 on failure.
Reimplemented in ACE_LSOCK_Acceptor.
Definition at line 351 of file SOCK_Acceptor.cpp.
{ ACE_TRACE ("ACE_SOCK_Acceptor::open"); if (local_sap != ACE_Addr::sap_any) protocol_family = local_sap.get_type (); else if (protocol_family == PF_UNSPEC) { #if defined (ACE_HAS_IPV6) protocol_family = ACE::ipv6_enabled () ? PF_INET6 : PF_INET; #else protocol_family = PF_INET; #endif /* ACE_HAS_IPV6 */ } if (ACE_SOCK::open (SOCK_STREAM, protocol_family, protocol, reuse_addr) == -1) return -1; else return this->shared_open (local_sap, protocol_family, backlog); }
int ACE_SOCK_Acceptor::shared_accept_finish | ( | ACE_SOCK_Stream | new_stream, | |
int | in_blocking_mode, | |||
bool | reset_new_handle | |||
) | const [protected] |
Perform operations that must occur after <ACE_OS::accept> is called.
Definition at line 67 of file SOCK_Acceptor.cpp.
{ ACE_TRACE ("ACE_SOCK_Acceptor::shared_accept_finish ()"); ACE_HANDLE new_handle = new_stream.get_handle (); // Check to see if we were originally in blocking mode, and if so, // set the <new_stream>'s handle and <this> handle to be in blocking // mode. if (in_blocking_mode) { // Save/restore errno. ACE_Errno_Guard error (errno); // Only disable ACE_NONBLOCK if we weren't in non-blocking mode // originally. ACE::clr_flags (this->get_handle (), ACE_NONBLOCK); ACE::clr_flags (new_handle, ACE_NONBLOCK); } #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0) if (reset_new_handle) // Reset the event association inherited by the new handle. ::WSAEventSelect ((SOCKET) new_handle, 0, 0); #else ACE_UNUSED_ARG (reset_new_handle); #endif /* ACE_WIN32 */ return new_handle == ACE_INVALID_HANDLE ? -1 : 0; }
int ACE_SOCK_Acceptor::shared_accept_start | ( | ACE_Time_Value * | timeout, | |
bool | restart, | |||
int & | in_blocking_mode | |||
) | const [protected] |
Perform operations that must occur before <ACE_OS::accept> is called.
Definition at line 35 of file SOCK_Acceptor.cpp.
{ ACE_TRACE ("ACE_SOCK_Acceptor::shared_accept_start"); ACE_HANDLE handle = this->get_handle (); // Handle the case where we're doing a timed <accept>. if (timeout != 0) { if (ACE::handle_timed_accept (handle, timeout, restart) == -1) return -1; else { in_blocking_mode = ACE_BIT_DISABLED (ACE::get_flags (handle), ACE_NONBLOCK); // Set the handle into non-blocking mode if it's not already // in it. if (in_blocking_mode && ACE::set_flags (handle, ACE_NONBLOCK) == -1) return -1; } } return 0; }
int ACE_SOCK_Acceptor::shared_open | ( | const ACE_Addr & | local_sap, | |
int | protocol_family, | |||
int | backlog | |||
) | [protected] |
This method factors out the common <open> code and is called by both the QoS-enabled <open> method and the BSD-style <open> method.
Definition at line 221 of file SOCK_Acceptor.cpp.
{ ACE_TRACE ("ACE_SOCK_Acceptor::shared_open"); int error = 0; #if defined (ACE_HAS_IPV6) if (protocol_family == PF_INET6) { sockaddr_in6 local_inet6_addr; ACE_OS::memset (reinterpret_cast<void *> (&local_inet6_addr), 0, sizeof local_inet6_addr); if (local_sap == ACE_Addr::sap_any) { local_inet6_addr.sin6_family = AF_INET6; local_inet6_addr.sin6_port = 0; local_inet6_addr.sin6_addr = in6addr_any; } else local_inet6_addr = *reinterpret_cast<sockaddr_in6 *> (local_sap.get_addr ()); // We probably don't need a bind_port written here. // There are currently no supported OS's that define // ACE_LACKS_WILDCARD_BIND. if (ACE_OS::bind (this->get_handle (), reinterpret_cast<sockaddr *> (&local_inet6_addr), sizeof local_inet6_addr) == -1) error = 1; } else #endif if (protocol_family == PF_INET) { sockaddr_in local_inet_addr; ACE_OS::memset (reinterpret_cast<void *> (&local_inet_addr), 0, sizeof local_inet_addr); if (local_sap == ACE_Addr::sap_any) { local_inet_addr.sin_port = 0; } else local_inet_addr = *reinterpret_cast<sockaddr_in *> (local_sap.get_addr ()); if (local_inet_addr.sin_port == 0) { if (ACE::bind_port (this->get_handle (), ACE_NTOHL (ACE_UINT32 (local_inet_addr.sin_addr.s_addr))) == -1) error = 1; } else if (ACE_OS::bind (this->get_handle (), reinterpret_cast<sockaddr *> (&local_inet_addr), sizeof local_inet_addr) == -1) error = 1; } else if (ACE_OS::bind (this->get_handle (), (sockaddr *) local_sap.get_addr (), local_sap.get_size ()) == -1) error = 1; if (error != 0 || ACE_OS::listen (this->get_handle (), backlog) == -1) { ACE_Errno_Guard g (errno); // Preserve across close() below. error = 1; this->close (); } return error ? -1 : 0; }
Declare the dynamic allocation hooks.
Reimplemented from ACE_SOCK.
Reimplemented in ACE_LSOCK_Acceptor.
Definition at line 142 of file SOCK_Acceptor.h.