3 //=============================================================================
5 * @file SOCK_Acceptor.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 //=============================================================================
11 #ifndef ACE_SOCK_ACCEPTOR_H
12 #define ACE_SOCK_ACCEPTOR_H
13 #include /**/ "ace/pre.h"
15 #include "ace/SOCK_Stream.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
24 class ACE_Accept_QoS_Params
;
27 * @class ACE_SOCK_Acceptor
29 * @brief Defines a factory that creates new ACE_Streams passively.
31 * The ACE_SOCK_Acceptor has its own "passive-mode" socket.
32 * This serves as a factory to create so-called "data-mode"
33 * sockets, which are what the ACE_SOCK_Stream encapsulates.
34 * Therefore, by inheriting from ACE_SOCK, ACE_SOCK_Acceptor
35 * gets its very own socket.
37 class ACE_Export ACE_SOCK_Acceptor
: public ACE_SOCK
40 /// Default constructor.
44 * Initialize a passive-mode BSD-style acceptor socket (no QoS).
45 * @a local_sap is the address that we're going to listen for
46 * connections on. If @a reuse_addr is 1 then we'll use the
47 * @c SO_REUSEADDR to reuse this address.
48 * @a ipv6_only is used when opening a IPv6 acceptor. If non-zero,
49 * the socket will only accept connections from IPv6 peers. If zero
50 * the socket will accept both IPv4 and v6 if it is able to.
52 ACE_SOCK_Acceptor (const ACE_Addr
&local_sap
,
54 int protocol_family
= PF_UNSPEC
,
55 int backlog
= ACE_DEFAULT_BACKLOG
,
59 /// Initialize a passive-mode QoS-enabled acceptor socket.
60 ACE_SOCK_Acceptor (const ACE_Addr
&local_sap
,
61 ACE_Protocol_Info
*protocolinfo
,
65 int protocol_family
= PF_UNSPEC
,
66 int backlog
= ACE_DEFAULT_BACKLOG
,
71 * Initialize a passive-mode BSD-style acceptor socket (no QoS).
72 * @a local_sap is the address that we're going to listen for
73 * connections on. If @a reuse_addr is 1 then we'll use the
74 * @c SO_REUSEADDR to reuse this address.
75 * @a ipv6_only is used when opening a IPv6 acceptor. If non-zero,
76 * the socket will only accept connections from IPv6 peers. If zero
77 * the socket will accept both IPv4 and v6 if it is able to.
78 * @retval Returns 0 on success and
81 int open (const ACE_Addr
&local_sap
,
83 int protocol_family
= PF_UNSPEC
,
84 int backlog
= ACE_DEFAULT_BACKLOG
,
88 /// Initialize a passive-mode QoS-enabled acceptor socket. Returns 0
89 /// on success and -1 on failure.
90 int open (const ACE_Addr
&local_sap
,
91 ACE_Protocol_Info
*protocolinfo
,
95 int protocol_family
= PF_UNSPEC
,
96 int backlog
= ACE_DEFAULT_BACKLOG
,
100 /// Close the socket. Returns 0 on success and -1 on failure.
104 ~ACE_SOCK_Acceptor ();
106 // = Passive connection <accept> methods.
108 * Accept a new ACE_SOCK_Stream connection. A @a timeout of 0
109 * means block forever, a @a timeout of {0, 0} means poll. @a restart
110 * == true means "restart if interrupted," i.e., if errno == EINTR.
111 * Note that @a new_stream inherits the "blocking mode" of @c this
112 * ACE_SOCK_Acceptor, i.e., if @c this acceptor factory is in
113 * non-blocking mode, the @a new_stream will be in non-blocking mode
116 int accept (ACE_SOCK_Stream
&new_stream
,
117 ACE_Addr
*remote_addr
= 0,
118 ACE_Time_Value
*timeout
= 0,
120 bool reset_new_handle
= false) const;
123 * Accept a new ACE_SOCK_Stream connection using the QoS
124 * information in @a qos_params. A @a timeout of 0 means block
125 * forever, a @a timeout of {0, 0} means poll. @a restart == true means
126 * "restart if interrupted," i.e., if errno == EINTR. Note that
127 * @a new_stream inherits the "blocking mode" of @c this
128 * ACE_SOCK_Acceptor, i.e., if @c this acceptor factory is in
129 * non-blocking mode, the @a new_stream will be in non-blocking mode
132 int accept (ACE_SOCK_Stream
&new_stream
,
133 ACE_Accept_QoS_Params qos_params
,
134 ACE_Addr
*remote_addr
= 0,
135 ACE_Time_Value
*timeout
= 0,
137 bool reset_new_handle
= false) const;
140 typedef ACE_INET_Addr PEER_ADDR
;
141 typedef ACE_SOCK_Stream PEER_STREAM
;
143 /// Dump the state of an object.
146 /// Declare the dynamic allocation hooks.
147 ACE_ALLOC_HOOK_DECLARE
;
150 /// Perform operations that must occur before <ACE_OS::accept> is
152 int shared_accept_start (ACE_Time_Value
*timeout
,
154 int &in_blocking_mode
) const;
156 /// Perform operations that must occur after <ACE_OS::accept> is
158 int shared_accept_finish (ACE_SOCK_Stream new_stream
,
159 int in_blocking_mode
,
160 bool reset_new_handle
) const;
163 * This method factors out the common <open> code and is called by
164 * both the QoS-enabled <open> method and the BSD-style <open>
167 int shared_open (const ACE_Addr
&local_sap
,
173 /// Do not allow this function to percolate up to this interface...
174 int get_remote_addr (ACE_Addr
&) const;
177 ACE_END_VERSIONED_NAMESPACE_DECL
179 #if defined (__ACE_INLINE__)
180 #include "ace/SOCK_Acceptor.inl"
181 #endif /* __ACE_INLINE__ */
183 #include /**/ "ace/post.h"
184 #endif /* ACE_SOCK_ACCEPTOR_H */