#include <SOCK_Acceptor.h>
Inheritance diagram for ACE_SOCK_Acceptor:


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, int restart=1, int reset_new_handle=0) const |
| int | accept (ACE_SOCK_Stream &new_stream, ACE_Accept_QoS_Params qos_params, ACE_Addr *remote_addr=0, ACE_Time_Value *timeout=0, int restart=1, int reset_new_handle=0) 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, int restart, int &in_blocking_mode) const |
| int | shared_accept_finish (ACE_SOCK_Stream new_stream, int in_blocking_mode, int 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... | |
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, and ACE_MEM_Acceptor. Definition at line 135 of file SOCK_Acceptor.h. |
|
|
Reimplemented in ACE_LSOCK_Acceptor, and ACE_MEM_Acceptor. Definition at line 136 of file SOCK_Acceptor.h. |
|
|
Default constructor.
Definition at line 27 of file SOCK_Acceptor.cpp. References ACE_TRACE.
00028 {
00029 ACE_TRACE ("ACE_SOCK_Acceptor::ACE_SOCK_Acceptor");
00030 }
|
|
||||||||||||||||||||||||
|
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 Definition at line 383 of file SOCK_Acceptor.cpp. References ACE_ERROR, ACE_TEXT, ACE_TRACE, LM_ERROR, and open().
|
|
||||||||||||||||||||||||||||||||||||
|
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. References ACE_ERROR, ACE_SOCK_GROUP, ACE_TEXT, ACE_TRACE, LM_ERROR, and open().
00333 {
00334 ACE_TRACE ("ACE_SOCK_Acceptor::ACE_SOCK_Acceptor");
00335 if (this->open (local_sap,
00336 protocolinfo,
00337 g,
00338 flags,
00339 reuse_addr,
00340 protocol_family,
00341 backlog,
00342 protocol) == -1)
00343 ACE_ERROR ((LM_ERROR,
00344 ACE_TEXT ("%p\n"),
00345 ACE_TEXT ("ACE_SOCK_Acceptor")));
00346 }
|
|
|
Default dtor.
Definition at line 8 of file SOCK_Acceptor.inl. References ACE_TRACE.
00009 {
00010 ACE_TRACE ("ACE_SOCK_Acceptor::~ACE_SOCK_Acceptor");
00011 }
|
|
||||||||||||||||||||||||||||
|
Accept a new ACE_SOCK_Stream connection using the QoS information in . A timeout of 0 means block forever, a timeout of {0, 0} means poll. == 1 means "restart if interrupted," i.e., if errno == EINTR. Note that inherits the "blocking mode" of Reimplemented in ACE_MEM_Acceptor. Definition at line 160 of file SOCK_Acceptor.cpp. References ACE_TRACE, ACE_Addr::get_addr(), ACE_IPC_SAP::get_handle(), ACE_Addr::get_size(), ACE_IPC_SAP::set_handle(), ACE_Addr::set_size(), shared_accept_finish(), and shared_accept_start().
00166 {
00167 ACE_TRACE ("ACE_SOCK_Acceptor::accept");
00168
00169 int in_blocking_mode = 0;
00170 if (this->shared_accept_start (timeout,
00171 restart,
00172 in_blocking_mode) == -1)
00173 return -1;
00174 else
00175 {
00176 // On Win32 the third parameter to <accept> must be a NULL
00177 // pointer if we want to ignore the client's address.
00178 int *len_ptr = 0;
00179 int len = 0;
00180 sockaddr *addr = 0;
00181
00182 if (remote_addr != 0)
00183 {
00184 len = remote_addr->get_size ();
00185 len_ptr = &len;
00186 addr = (sockaddr *) remote_addr->get_addr ();
00187 }
00188
00189 do
00190 new_stream.set_handle (ACE_OS::accept (this->get_handle (),
00191 addr,
00192 len_ptr,
00193 qos_params));
00194 while (new_stream.get_handle () == ACE_INVALID_HANDLE
00195 && restart != 0
00196 && errno == EINTR
00197 && timeout == 0);
00198
00199 // Reset the size of the addr, which is only necessary for UNIX
00200 // domain sockets.
00201 if (new_stream.get_handle () != ACE_INVALID_HANDLE
00202 && remote_addr != 0)
00203 remote_addr->set_size (len);
00204 }
00205
00206 return this->shared_accept_finish (new_stream,
00207 in_blocking_mode,
00208 reset_new_handle);
00209 }
|
|
||||||||||||||||||||||||
|
Accept a new ACE_SOCK_Stream connection. A timeout of 0 means block forever, a timeout of {0, 0} means poll. == 1 means "restart if interrupted," i.e., if errno == EINTR. Note that inherits the "blocking mode" of Reimplemented in ACE_LOCK_SOCK_Acceptor< ACE_LOCK >, and ACE_MEM_Acceptor. Definition at line 105 of file SOCK_Acceptor.cpp. References ACE_TRACE, ACE_Addr::get_addr(), ACE_IPC_SAP::get_handle(), ACE_Addr::get_size(), ACE_IPC_SAP::set_handle(), ACE_Addr::set_size(), ACE_Addr::set_type(), shared_accept_finish(), and shared_accept_start(). Referenced by ACE_LOCK_SOCK_Acceptor< ACE_LOCK >::accept(), ACE_Service_Manager::handle_input(), and ACE_Pipe::open().
00110 {
00111 ACE_TRACE ("ACE_SOCK_Acceptor::accept");
00112
00113 int in_blocking_mode = 0;
00114 if (this->shared_accept_start (timeout,
00115 restart,
00116 in_blocking_mode) == -1)
00117 return -1;
00118 else
00119 {
00120 // On Win32 the third parameter to <accept> must be a NULL
00121 // pointer if we want to ignore the client's address.
00122 int *len_ptr = 0;
00123 sockaddr *addr = 0;
00124 int len = 0;
00125
00126 if (remote_addr != 0)
00127 {
00128 len = remote_addr->get_size ();
00129 len_ptr = &len;
00130 addr = (sockaddr *) remote_addr->get_addr ();
00131 }
00132
00133 do
00134 new_stream.set_handle (ACE_OS::accept (this->get_handle (),
00135 addr,
00136 len_ptr));
00137 while (new_stream.get_handle () == ACE_INVALID_HANDLE
00138 && restart != 0
00139 && errno == EINTR
00140 && timeout == 0);
00141
00142 // Reset the size of the addr, so the proper UNIX/IPv4/IPv6 family
00143 // is known.
00144 if (new_stream.get_handle () != ACE_INVALID_HANDLE
00145 && remote_addr != 0)
00146 {
00147 remote_addr->set_size (len);
00148 if (addr)
00149 remote_addr->set_type (addr->sa_family);
00150 }
00151 }
00152
00153 return this->shared_accept_finish (new_stream,
00154 in_blocking_mode,
00155 reset_new_handle);
00156 }
|
|
|
Close the socket. Returns 0 on success and -1 on failure.
Reimplemented from ACE_SOCK. Definition at line 401 of file SOCK_Acceptor.cpp. References ACE_SOCK::close(). Referenced by ACE_Service_Manager::handle_close(), ACE_Pipe::open(), ACE_LSOCK_Acceptor::remove(), and shared_open().
00402 {
00403 return ACE_SOCK::close ();
00404 }
|
|
|
Dump the state of an object.
Reimplemented from ACE_SOCK. Reimplemented in ACE_LSOCK_Acceptor, and ACE_MEM_Acceptor. Definition at line 213 of file SOCK_Acceptor.cpp. References ACE_TRACE.
00214 {
00215 #if defined (ACE_HAS_DUMP)
00216 ACE_TRACE ("ACE_SOCK_Acceptor::dump");
00217 #endif /* ACE_HAS_DUMP */
00218 }
|
|
|
Do not allow this function to percolate up to this interface...
Reimplemented from ACE_SOCK. |
|
||||||||||||||||||||||||||||||||||||
|
Initialize a passive-mode QoS-enabled acceptor socket. Returns 0 on success and -1 on failure. Reimplemented in ACE_MEM_Acceptor. Definition at line 297 of file SOCK_Acceptor.cpp. References ACE_SOCK_GROUP, ACE_TRACE, ACE_Addr::get_type(), ACE_SOCK::open(), PF_UNSPEC, shared_open(), and SOCK_STREAM.
00305 {
00306 ACE_TRACE ("ACE_SOCK_Acceptor::open");
00307
00308 if (protocol_family == PF_UNSPEC)
00309 protocol_family = local_sap.get_type ();
00310
00311 if (ACE_SOCK::open (SOCK_STREAM,
00312 protocol_family,
00313 protocol,
00314 protocolinfo,
00315 g,
00316 flags,
00317 reuse_addr) == -1)
00318 return -1;
00319 else
00320 return this->shared_open (local_sap,
00321 protocol_family,
00322 backlog);
00323 }
|
|
||||||||||||||||||||||||
|
Initialize a passive-mode BSD-style acceptor socket (no QoS). is the address that we're going to listen for connections on. If is 1 then we'll use the to reuse this address. Returns 0 on success and -1 on failure. Reimplemented in ACE_LSOCK_Acceptor, and ACE_MEM_Acceptor. Definition at line 351 of file SOCK_Acceptor.cpp. References ACE_TRACE, ACE_Addr::get_type(), ACE::ipv6_enabled(), ACE_SOCK::open(), PF_INET, PF_UNSPEC, shared_open(), and SOCK_STREAM. Referenced by ACE_SOCK_Acceptor(), ACE_Service_Manager::open(), ACE_Pipe::open(), ACE_MEM_Acceptor::open(), and ACE_LSOCK_Acceptor::open().
00356 {
00357 ACE_TRACE ("ACE_SOCK_Acceptor::open");
00358
00359 if (local_sap != ACE_Addr::sap_any)
00360 protocol_family = local_sap.get_type ();
00361 else if (protocol_family == PF_UNSPEC)
00362 {
00363 #if defined (ACE_HAS_IPV6)
00364 protocol_family = ACE::ipv6_enabled () ? PF_INET6 : PF_INET;
00365 #else
00366 protocol_family = PF_INET;
00367 #endif /* ACE_HAS_IPV6 */
00368 }
00369
00370 if (ACE_SOCK::open (SOCK_STREAM,
00371 protocol_family,
00372 protocol,
00373 reuse_addr) == -1)
00374 return -1;
00375 else
00376 return this->shared_open (local_sap,
00377 protocol_family,
00378 backlog);
00379 }
|
|
||||||||||||||||
|
Perform operations that must occur after <ACE_OS::accept> is called. Definition at line 67 of file SOCK_Acceptor.cpp. References ACE_NONBLOCK, ACE_TRACE, ACE::clr_flags(), and ACE_IPC_SAP::get_handle(). Referenced by accept(), and ACE_LSOCK_Acceptor::accept().
00070 {
00071 ACE_TRACE ("ACE_SOCK_Acceptor::shared_accept_finish ()");
00072
00073 ACE_HANDLE new_handle = new_stream.get_handle ();
00074
00075 // Check to see if we were originally in blocking mode, and if so,
00076 // set the <new_stream>'s handle and <this> handle to be in blocking
00077 // mode.
00078 if (in_blocking_mode)
00079 {
00080 // Save/restore errno.
00081 ACE_Errno_Guard error (errno);
00082
00083 // Only disable ACE_NONBLOCK if we weren't in non-blocking mode
00084 // originally.
00085 ACE::clr_flags (this->get_handle (),
00086 ACE_NONBLOCK);
00087 ACE::clr_flags (new_handle,
00088 ACE_NONBLOCK);
00089 }
00090
00091 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
00092 if (reset_new_handle)
00093 // Reset the event association inherited by the new handle.
00094 ::WSAEventSelect ((SOCKET) new_handle, 0, 0);
00095 #else
00096 ACE_UNUSED_ARG (reset_new_handle);
00097 #endif /* ACE_WIN32 */
00098
00099 return new_handle == ACE_INVALID_HANDLE ? -1 : 0;
00100 }
|
|
||||||||||||||||
|
Perform operations that must occur before <ACE_OS::accept> is called. Definition at line 35 of file SOCK_Acceptor.cpp. References ACE_BIT_DISABLED, ACE_NONBLOCK, ACE_TRACE, ACE_IPC_SAP::get_handle(), ACE::handle_timed_accept(), and ACE::set_flags(). Referenced by accept(), ACE_MEM_Acceptor::accept(), and ACE_LSOCK_Acceptor::accept().
00038 {
00039 ACE_TRACE ("ACE_SOCK_Acceptor::shared_accept_start");
00040
00041 ACE_HANDLE handle = this->get_handle ();
00042
00043 // Handle the case where we're doing a timed <accept>.
00044 if (timeout != 0)
00045 {
00046 if (ACE::handle_timed_accept (handle,
00047 timeout,
00048 restart) == -1)
00049 return -1;
00050 else
00051 {
00052 in_blocking_mode = ACE_BIT_DISABLED (ACE::get_flags (handle),
00053 ACE_NONBLOCK);
00054 // Set the handle into non-blocking mode if it's not already
00055 // in it.
00056 if (in_blocking_mode
00057 && ACE::set_flags (handle,
00058 ACE_NONBLOCK) == -1)
00059 return -1;
00060 }
00061 }
00062
00063 return 0;
00064 }
|
|
||||||||||||||||
|
This method factors out the common code and is called by both the QoS-enabled method and the BSD-style method. Definition at line 221 of file SOCK_Acceptor.cpp. References ACE_NTOHL, ACE_TRACE, ACE_OS::bind(), ACE::bind_port(), close(), ACE_Addr::get_addr(), ACE_Addr::get_size(), ACE_OS::listen(), ACE_OS::memset(), and PF_INET. Referenced by open().
00224 {
00225 ACE_TRACE ("ACE_SOCK_Acceptor::shared_open");
00226 int error = 0;
00227
00228 #if defined (ACE_HAS_IPV6)
00229 if (protocol_family == PF_INET6)
00230 {
00231 sockaddr_in6 local_inet6_addr;
00232 ACE_OS::memset (reinterpret_cast<void *> (&local_inet6_addr),
00233 0,
00234 sizeof local_inet6_addr);
00235
00236 if (local_sap == ACE_Addr::sap_any)
00237 {
00238 local_inet6_addr.sin6_family = AF_INET6;
00239 local_inet6_addr.sin6_port = 0;
00240 local_inet6_addr.sin6_addr = in6addr_any;
00241 }
00242 else
00243 local_inet6_addr = *reinterpret_cast<sockaddr_in6 *> (local_sap.get_addr ());
00244
00245 // We probably don't need a bind_port written here.
00246 // There are currently no supported OS's that define
00247 // ACE_LACKS_WILDCARD_BIND.
00248 if (ACE_OS::bind (this->get_handle (),
00249 reinterpret_cast<sockaddr *> (&local_inet6_addr),
00250 sizeof local_inet6_addr) == -1)
00251 error = 1;
00252 }
00253 else
00254 #endif
00255 if (protocol_family == PF_INET)
00256 {
00257 sockaddr_in local_inet_addr;
00258 ACE_OS::memset (reinterpret_cast<void *> (&local_inet_addr),
00259 0,
00260 sizeof local_inet_addr);
00261
00262 if (local_sap == ACE_Addr::sap_any)
00263 {
00264 local_inet_addr.sin_port = 0;
00265 }
00266 else
00267 local_inet_addr = *reinterpret_cast<sockaddr_in *> (local_sap.get_addr ());
00268 if (local_inet_addr.sin_port == 0)
00269 {
00270 if (ACE::bind_port (this->get_handle (),
00271 ACE_NTOHL (ACE_UINT32 (local_inet_addr.sin_addr.s_addr))) == -1)
00272 error = 1;
00273 }
00274 else if (ACE_OS::bind (this->get_handle (),
00275 reinterpret_cast<sockaddr *> (&local_inet_addr),
00276 sizeof local_inet_addr) == -1)
00277 error = 1;
00278 }
00279 else if (ACE_OS::bind (this->get_handle (),
00280 (sockaddr *) local_sap.get_addr (),
00281 local_sap.get_size ()) == -1)
00282 error = 1;
00283
00284 if (error != 0
00285 || ACE_OS::listen (this->get_handle (),
00286 backlog) == -1)
00287 {
00288 ACE_Errno_Guard g (errno); // Preserve across close() below.
00289 error = 1;
00290 this->close ();
00291 }
00292
00293 return error ? -1 : 0;
00294 }
|
|
|
Declare the dynamic allocation hooks.
Reimplemented from ACE_SOCK. Reimplemented in ACE_LSOCK_Acceptor, and ACE_MEM_Acceptor. Definition at line 142 of file SOCK_Acceptor.h. |
1.3.6