#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 Methods | |
| ACE_SOCK_Acceptor (void) | |
| Default constructor. More... | |
| 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) | |
| Initialize a passive-mode QoS-enabled acceptor socket. Returns 0 on success and -1 on failure. More... | |
| 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) |
| Initialize a passive-mode QoS-enabled acceptor socket. Returns 0 on success and -1 on failure. More... | |
| int | close (void) |
| Close the socket. Returns 0 on success and -1 on failure. More... | |
| ~ACE_SOCK_Acceptor (void) | |
| Default dtor. More... | |
| 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. More... | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. More... | |
Protected Methods | |
| int | shared_accept_start (ACE_Time_Value *timeout, int restart, int &in_blocking_mode) const |
| Perform operations that must occur before <ACE_OS::accept> is called. More... | |
| int | shared_accept_finish (ACE_SOCK_Stream new_stream, int in_blocking_mode, int reset_new_handle) const |
| Perform operations that must occur after <ACE_OS::accept> is called. More... | |
| int | shared_open (const ACE_Addr &local_sap, int protocol_family, int backlog) |
Private Methods | |
| int | get_remote_addr (ACE_Addr &) const |
| Do not allow this function to percolate up to this interface... More... | |
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 36 of file SOCK_Acceptor.h.
|
|
Reimplemented in ACE_LSOCK_Acceptor. Definition at line 132 of file SOCK_Acceptor.h. |
|
|
Reimplemented in ACE_LSOCK_Acceptor. Definition at line 133 of file SOCK_Acceptor.h. |
|
|
Default constructor.
Definition at line 24 of file SOCK_Acceptor.cpp. References ACE_TRACE.
00025 {
00026 ACE_TRACE ("ACE_SOCK_Acceptor::ACE_SOCK_Acceptor");
00027 }
|
|
||||||||||||||||||||||||
|
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. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open.
00388 {
00389 ACE_TRACE ("ACE_SOCK_Acceptor::ACE_SOCK_Acceptor");
00390 if (this->open (local_sap,
00391 reuse_addr,
00392 protocol_family,
00393 backlog,
00394 protocol) == -1)
00395 ACE_ERROR ((LM_ERROR,
00396 ACE_LIB_TEXT ("%p\n"),
00397 ACE_LIB_TEXT ("ACE_SOCK_Acceptor")));
00398 }
|
|
||||||||||||||||||||||||||||||||||||
|
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_LIB_TEXT, ACE_SOCK_GROUP, 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_LIB_TEXT ("%p\n"),
00345 ACE_LIB_TEXT ("ACE_SOCK_Acceptor")));
00346 }
|
|
|
Default dtor.
Definition at line 7 of file SOCK_Acceptor.i. References ACE_TRACE.
00008 {
00009 ACE_TRACE ("ACE_SOCK_Acceptor::~ACE_SOCK_Acceptor");
00010 }
|
|
||||||||||||||||||||||||||||
|
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> == 1 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 <net_stream> will be in non-blocking mode and vice versa. Reimplemented in ACE_MEM_Acceptor. Definition at line 156 of file SOCK_Acceptor.cpp. References ACE_OS::accept, 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.
00162 {
00163 ACE_TRACE ("ACE_SOCK_Acceptor::accept");
00164
00165 int in_blocking_mode = 0;
00166 if (this->shared_accept_start (timeout,
00167 restart,
00168 in_blocking_mode) == -1)
00169 return -1;
00170 else
00171 {
00172 // On Win32 the third parameter to <accept> must be a NULL
00173 // pointer if we want to ignore the client's address.
00174 int *len_ptr = 0;
00175 int len = 0;
00176 sockaddr *addr = 0;
00177
00178 if (remote_addr != 0)
00179 {
00180 len = remote_addr->get_size ();
00181 len_ptr = &len;
00182 addr = (sockaddr *) remote_addr->get_addr ();
00183 }
00184
00185 do
00186 new_stream.set_handle (ACE_OS::accept (this->get_handle (),
00187 addr,
00188 len_ptr,
00189 qos_params));
00190 while (new_stream.get_handle () == ACE_INVALID_HANDLE
00191 && restart != 0
00192 && errno == EINTR
00193 && timeout == 0);
00194
00195 // Reset the size of the addr, which is only necessary for UNIX
00196 // domain sockets.
00197 if (new_stream.get_handle () != ACE_INVALID_HANDLE
00198 && remote_addr != 0)
00199 remote_addr->set_size (len);
00200 }
00201
00202 return this->shared_accept_finish (new_stream,
00203 in_blocking_mode,
00204 reset_new_handle);
00205 }
|
|
||||||||||||||||||||||||
|
Accept a new <ACE_SOCK_Stream> connection. A <timeout> of 0 means block forever, a <timeout> of {0, 0} means poll. <restart> == 1 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 <net_stream> will be in non-blocking mode and vice versa. Reimplemented in ACE_LOCK_SOCK_Acceptor. Definition at line 102 of file SOCK_Acceptor.cpp. References ACE_OS::accept, 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_MEM_Acceptor::accept, ACE_LOCK_SOCK_Acceptor::accept, ACE_Service_Manager::handle_input, and ACE_Pipe::open.
00107 {
00108 ACE_TRACE ("ACE_SOCK_Acceptor::accept");
00109
00110 int in_blocking_mode = 0;
00111 if (this->shared_accept_start (timeout,
00112 restart,
00113 in_blocking_mode) == -1)
00114 return -1;
00115 else
00116 {
00117 // On Win32 the third parameter to <accept> must be a NULL
00118 // pointer if we want to ignore the client's address.
00119 int *len_ptr = 0;
00120 sockaddr *addr = 0;
00121 int len = 0;
00122
00123 if (remote_addr != 0)
00124 {
00125 len = remote_addr->get_size ();
00126 len_ptr = &len;
00127 addr = (sockaddr *) remote_addr->get_addr ();
00128 }
00129
00130 do
00131 new_stream.set_handle (ACE_OS::accept (this->get_handle (),
00132 addr,
00133 len_ptr));
00134 while (new_stream.get_handle () == ACE_INVALID_HANDLE
00135 && restart != 0
00136 && errno == EINTR
00137 && timeout == 0);
00138
00139 // Reset the size of the addr, so the proper UNIX/IPv4/IPv6 family
00140 // is known.
00141 if (new_stream.get_handle () != ACE_INVALID_HANDLE
00142 && remote_addr != 0)
00143 {
00144 remote_addr->set_size (len);
00145 remote_addr->set_type (addr->sa_family);
00146 }
00147 }
00148
00149 return this->shared_accept_finish (new_stream,
00150 in_blocking_mode,
00151 reset_new_handle);
00152 }
|
|
|
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. Definition at line 209 of file SOCK_Acceptor.cpp. References ACE_TRACE.
00210 {
00211 ACE_TRACE ("ACE_SOCK_Acceptor::dump");
00212 }
|
|
|
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, and shared_open.
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). <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. References ACE_TRACE, ACE_Addr::get_type, ACE_Sock_Connect::ipv6_enabled, ACE_SOCK::open, ACE_Addr::sap_any, and shared_open. 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_Sock_Connect::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 64 of file SOCK_Acceptor.cpp. References ACE_NONBLOCK, ACE_TRACE, ACE_Flag_Manip::clr_flags, and ACE_IPC_SAP::get_handle. Referenced by accept, and ACE_LSOCK_Acceptor::accept.
00067 {
00068 ACE_TRACE ("ACE_SOCK_Acceptor::shared_accept_finish ()");
00069
00070 ACE_HANDLE new_handle = new_stream.get_handle ();
00071
00072 // Check to see if we were originally in blocking mode, and if so,
00073 // set the <new_stream>'s handle and <this> handle to be in blocking
00074 // mode.
00075 if (in_blocking_mode)
00076 {
00077 // Save/restore errno.
00078 ACE_Errno_Guard error (errno);
00079
00080 // Only disable ACE_NONBLOCK if we weren't in non-blocking mode
00081 // originally.
00082 ACE::clr_flags (this->get_handle (),
00083 ACE_NONBLOCK);
00084 ACE::clr_flags (new_handle,
00085 ACE_NONBLOCK);
00086 }
00087
00088 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
00089 if (reset_new_handle)
00090 // Reset the event association inherited by the new handle.
00091 ::WSAEventSelect ((SOCKET) new_handle, 0, 0);
00092 #else
00093 ACE_UNUSED_ARG (reset_new_handle);
00094 #endif /* ACE_WIN32 */
00095
00096 return new_handle == ACE_INVALID_HANDLE ? -1 : 0;
00097 }
|
|
||||||||||||||||
|
Perform operations that must occur before <ACE_OS::accept> is called.
Definition at line 32 of file SOCK_Acceptor.cpp. References ACE_BIT_DISABLED, ACE_NONBLOCK, ACE_TRACE, ACE_Flag_Manip::get_flags, ACE_IPC_SAP::get_handle, ACE::handle_timed_accept, and ACE_Flag_Manip::set_flags. Referenced by accept, ACE_MEM_Acceptor::accept, and ACE_LSOCK_Acceptor::accept.
00035 {
00036 ACE_TRACE ("ACE_SOCK_Acceptor::shared_accept_start");
00037
00038 ACE_HANDLE handle = this->get_handle ();
00039
00040 // Handle the case where we're doing a timed <accept>.
00041 if (timeout != 0)
00042 {
00043 if (ACE::handle_timed_accept (handle,
00044 timeout,
00045 restart) == -1)
00046 return -1;
00047 else
00048 {
00049 in_blocking_mode = ACE_BIT_DISABLED (ACE::get_flags (handle),
00050 ACE_NONBLOCK);
00051 // Set the handle into non-blocking mode if it's not already
00052 // in it.
00053 if (in_blocking_mode
00054 && ACE::set_flags (handle,
00055 ACE_NONBLOCK) == -1)
00056 return -1;
00057 }
00058 }
00059
00060 return 0;
00061 }
|
|
||||||||||||||||
|
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 215 of file SOCK_Acceptor.cpp. References ACE_ASSERT, ACE_TRACE, ACE_OS::bind, ACE_Sock_Connect::bind_port, close, ACE_Addr::get_addr, ACE_Addr::get_size, ACE_OS::listen, ACE_OS_String::memset, and ACE_Addr::sap_any. Referenced by open.
00218 {
00219 ACE_TRACE ("ACE_SOCK_Acceptor::shared_open");
00220 int error = 0;
00221
00222 #if defined (ACE_HAS_IPV6)
00223 ACE_ASSERT (protocol_family == PF_INET || protocol_family == PF_INET6);
00224
00225 if (protocol_family == PF_INET6)
00226 {
00227 sockaddr_in6 local_inet6_addr;
00228 ACE_OS::memset (ACE_reinterpret_cast (void *,
00229 &local_inet6_addr),
00230 0,
00231 sizeof local_inet6_addr);
00232
00233 if (local_sap == ACE_Addr::sap_any)
00234 {
00235 local_inet6_addr.sin6_family = AF_INET6;
00236 local_inet6_addr.sin6_port = 0;
00237 local_inet6_addr.sin6_addr = in6addr_any;
00238 }
00239 else
00240 local_inet6_addr = *ACE_reinterpret_cast (sockaddr_in6 *,
00241 local_sap.get_addr ());
00242
00243 // We probably don't need a bind_port written here.
00244 // There are currently no supported OS's that define
00245 // ACE_LACKS_WILDCARD_BIND.
00246 if (ACE_OS::bind (this->get_handle (),
00247 ACE_reinterpret_cast (sockaddr *,
00248 &local_inet6_addr),
00249 sizeof local_inet6_addr) == -1)
00250 error = 1;
00251 }
00252 else
00253 #endif
00254 if (protocol_family == PF_INET)
00255 {
00256 sockaddr_in local_inet_addr;
00257 ACE_OS::memset (ACE_reinterpret_cast (void *,
00258 &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 = *ACE_reinterpret_cast (sockaddr_in *,
00268 local_sap.get_addr ());
00269 if (local_inet_addr.sin_port == 0)
00270 {
00271 if (ACE::bind_port (this->get_handle ()) == -1)
00272 error = 1;
00273 }
00274 else if (ACE_OS::bind (this->get_handle (),
00275 ACE_reinterpret_cast (sockaddr *,
00276 &local_inet_addr),
00277 sizeof local_inet_addr) == -1)
00278 error = 1;
00279 }
00280 else if (ACE_OS::bind (this->get_handle (),
00281 (sockaddr *) local_sap.get_addr (),
00282 local_sap.get_size ()) == -1)
00283 error = 1;
00284
00285 if (error != 0
00286 || ACE_OS::listen (this->get_handle (),
00287 backlog) == -1)
00288 {
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. Definition at line 139 of file SOCK_Acceptor.h. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002