ACE_SOCK_SEQPACK_Acceptor Class Reference

Defines a factory that creates new s passively. More...

#include <SOCK_SEQPACK_Acceptor.h>

Inheritance diagram for ACE_SOCK_SEQPACK_Acceptor:

Inheritance graph
[legend]
Collaboration diagram for ACE_SOCK_SEQPACK_Acceptor:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_Multihomed_INET_Addr PEER_ADDR
typedef ACE_SOCK_SEQPACK_Association PEER_STREAM

Public Member Functions

 ACE_SOCK_SEQPACK_Acceptor (void)
 Default constructor.

 ACE_SOCK_SEQPACK_Acceptor (const ACE_Addr &local_sap, int reuse_addr=0, int protocol_family=PF_UNSPEC, int backlog=ACE_DEFAULT_BACKLOG, int protocol=132)
 ACE_SOCK_SEQPACK_Acceptor (const ACE_Multihomed_INET_Addr &local_sap, int reuse_addr=0, int protocol_family=PF_UNSPEC, int backlog=ACE_DEFAULT_BACKLOG, int protocol=132)
 Multihomed version of same.

 ACE_SOCK_SEQPACK_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=132)
int open (const ACE_Addr &local_sap, int reuse_addr=0, int protocol_family=PF_UNSPEC, int backlog=ACE_DEFAULT_BACKLOG, int protocol=132)
int open (const ACE_Multihomed_INET_Addr &local_sap, int reuse_addr=0, int protocol_family=PF_UNSPEC, int backlog=ACE_DEFAULT_BACKLOG, int protocol=132)
 Multihomed version of same.

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=132)
int close (void)
 Close the socket. Returns 0 on success and -1 on failure.

 ~ACE_SOCK_SEQPACK_Acceptor (void)
 Default dtor.

int accept (ACE_SOCK_SEQPACK_Association &new_association, 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_SEQPACK_Association new_association, int in_blocking_mode, int reset_new_handle) const
int shared_open (const ACE_Addr &local_sap, int protocol_family, int backlog)
int shared_open (const ACE_Multihomed_INET_Addr &local_sap, int protocol_family, int backlog)
 Multihomed version of same.


Private Member Functions

int get_remote_addr (ACE_Addr &) const
 Do not allow this function to percolate up to this interface...


Detailed Description

Defines a factory that creates new s passively.

The has its own "passive-mode" socket. This serves as a factory to create so-called "data-mode" sockets, which are what the encapsulates. Therefore, by inheriting from , gets its very own socket.

Definition at line 45 of file SOCK_SEQPACK_Acceptor.h.


Member Typedef Documentation

typedef ACE_Multihomed_INET_Addr ACE_SOCK_SEQPACK_Acceptor::PEER_ADDR
 

Definition at line 140 of file SOCK_SEQPACK_Acceptor.h.

typedef ACE_SOCK_SEQPACK_Association ACE_SOCK_SEQPACK_Acceptor::PEER_STREAM
 

Definition at line 141 of file SOCK_SEQPACK_Acceptor.h.


Constructor & Destructor Documentation

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_SOCK_SEQPACK_Acceptor::ACE_SOCK_SEQPACK_Acceptor void   ) 
 

Default constructor.

Definition at line 24 of file SOCK_SEQPACK_Acceptor.cpp.

References ACE_TRACE.

00025 {
00026   ACE_TRACE ("ACE_SOCK_SEQPACK_Acceptor::ACE_SOCK_SEQPACK_Acceptor");
00027 }

ACE_SOCK_SEQPACK_Acceptor::ACE_SOCK_SEQPACK_Acceptor const ACE_Addr local_sap,
int  reuse_addr = 0,
int  protocol_family = PF_UNSPEC,
int  backlog = ACE_DEFAULT_BACKLOG,
int  protocol = 132
 

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.

Definition at line 554 of file SOCK_SEQPACK_Acceptor.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open().

00559 {
00560   ACE_TRACE ("ACE_SOCK_SEQPACK_Acceptor::ACE_SOCK_SEQPACK_Acceptor");
00561   if (this->open (local_sap,
00562                   reuse_addr,
00563                   protocol_family,
00564                   backlog,
00565                   protocol) == -1)
00566     ACE_ERROR ((LM_ERROR,
00567                 ACE_LIB_TEXT ("%p\n"),
00568                 ACE_LIB_TEXT ("ACE_SOCK_SEQPACK_Acceptor")));
00569 }

ACE_SOCK_SEQPACK_Acceptor::ACE_SOCK_SEQPACK_Acceptor const ACE_Multihomed_INET_Addr local_sap,
int  reuse_addr = 0,
int  protocol_family = PF_UNSPEC,
int  backlog = ACE_DEFAULT_BACKLOG,
int  protocol = 132
 

Multihomed version of same.

Definition at line 573 of file SOCK_SEQPACK_Acceptor.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open().

00578 {
00579   ACE_TRACE ("ACE_SOCK_SEQPACK_Acceptor::ACE_SOCK_SEQPACK_Acceptor");
00580   if (this->open (local_sap,
00581                   reuse_addr,
00582                   protocol_family,
00583                   backlog,
00584                   protocol) == -1)
00585     ACE_ERROR ((LM_ERROR,
00586                 ACE_LIB_TEXT ("%p\n"),
00587                 ACE_LIB_TEXT ("ACE_SOCK_SEQPACK_Acceptor")));
00588 }

ACE_SOCK_SEQPACK_Acceptor::ACE_SOCK_SEQPACK_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 = 132
 

Initialize a passive-mode QoS-enabled acceptor socket. Returns 0 on success and -1 on failure.

Definition at line 455 of file SOCK_SEQPACK_Acceptor.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_SOCK_GROUP, ACE_TRACE, LM_ERROR, and open().

00463 {
00464   ACE_TRACE ("ACE_SOCK_SEQPACK_Acceptor::ACE_SOCK_SEQPACK_Acceptor");
00465   if (this->open (local_sap,
00466                   protocolinfo,
00467                   g,
00468                   flags,
00469                   reuse_addr,
00470                   protocol_family,
00471                   backlog,
00472                   protocol) == -1)
00473     ACE_ERROR ((LM_ERROR,
00474                 ACE_LIB_TEXT ("%p\n"),
00475                 ACE_LIB_TEXT ("ACE_SOCK_SEQPACK_Acceptor")));
00476 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ACE_SOCK_SEQPACK_Acceptor::~ACE_SOCK_SEQPACK_Acceptor void   ) 
 

Default dtor.

Definition at line 8 of file SOCK_SEQPACK_Acceptor.inl.

References ACE_TRACE.

00009 {
00010   ACE_TRACE ("ACE_SOCK_SEQPACK_Acceptor::~ACE_SOCK_SEQPACK_Acceptor");
00011 }


Member Function Documentation

int ACE_SOCK_SEQPACK_Acceptor::accept ACE_SOCK_SEQPACK_Association new_association,
ACE_Addr remote_addr = 0,
ACE_Time_Value timeout = 0,
int  restart = 1,
int  reset_new_handle = 0
const
 

Accept a new connection. A of 0 means block forever, a of {0, 0} means poll. == 1 means "restart if interrupted," i.e., if errno == EINTR. Note that inherits the "blocking mode" of , i.e., if acceptor factory is in non-blocking mode, the will be in non-blocking mode and vice versa.

Definition at line 102 of file SOCK_SEQPACK_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().

00107 {
00108   ACE_TRACE ("ACE_SOCK_SEQPACK_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_association.set_handle (ACE_OS::accept (this->get_handle (),
00132                                                addr,
00133                                                len_ptr));
00134       while (new_association.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_association.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_association,
00150                                      in_blocking_mode,
00151                                      reset_new_handle);
00152 }

int ACE_SOCK_SEQPACK_Acceptor::close void   ) 
 

Close the socket. Returns 0 on success and -1 on failure.

Reimplemented from ACE_SOCK.

Definition at line 591 of file SOCK_SEQPACK_Acceptor.cpp.

References ACE_SOCK::close().

Referenced by shared_open().

00592 {
00593   return ACE_SOCK::close ();
00594 }

void ACE_SOCK_SEQPACK_Acceptor::dump void   )  const
 

Dump the state of an object.

Reimplemented from ACE_SOCK.

Definition at line 155 of file SOCK_SEQPACK_Acceptor.cpp.

References ACE_TRACE.

00156 {
00157 #if defined (ACE_HAS_DUMP)
00158   ACE_TRACE ("ACE_SOCK_SEQPACK_Acceptor::dump");
00159 #endif /* ACE_HAS_DUMP */
00160 }

int ACE_SOCK_SEQPACK_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_SEQPACK_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 = 132
 

Initialize a passive-mode QoS-enabled acceptor socket. Returns 0 on success and -1 on failure.

Definition at line 423 of file SOCK_SEQPACK_Acceptor.cpp.

References ACE_SOCK_GROUP, ACE_TRACE, ACE_Addr::get_type(), and ACE_SOCK::open().

00431 {
00432   ACE_TRACE ("ACE_SOCK_SEQPACK_Acceptor::open");
00433 
00434   if (protocol_family == PF_UNSPEC)
00435     protocol_family = local_sap.get_type ();
00436 
00437 #if defined (ACE_HAS_LKSCTP)
00438   if (ACE_SOCK::open (SOCK_STREAM,
00439 #else
00440   if (ACE_SOCK::open (SOCK_SEQPACKET,
00441 #endif
00442                       protocol_family,
00443                       protocol,
00444                       protocolinfo,
00445                       g,
00446                       flags,
00447                       reuse_addr) == -1)
00448     return -1;
00449   else
00450     return this->shared_open (local_sap,
00451                               protocol_family,
00452                               backlog);
00453 }

int ACE_SOCK_SEQPACK_Acceptor::open const ACE_Multihomed_INET_Addr local_sap,
int  reuse_addr = 0,
int  protocol_family = PF_UNSPEC,
int  backlog = ACE_DEFAULT_BACKLOG,
int  protocol = 132
 

Multihomed version of same.

Definition at line 518 of file SOCK_SEQPACK_Acceptor.cpp.

References ACE_TRACE, ACE_Addr::get_type(), ACE::ipv6_enabled(), and ACE_SOCK::open().

00523 {
00524   ACE_TRACE ("ACE_SOCK_SEQPACK_Acceptor::open");
00525 
00526   if (local_sap.ACE_Addr::operator!= (ACE_Addr::sap_any))
00527     protocol_family = local_sap.get_type ();
00528   else if (protocol_family == PF_UNSPEC)
00529     {
00530 #if defined (ACE_HAS_IPV6)
00531       protocol_family = ACE::ipv6_enabled () ? PF_INET6 : PF_INET;
00532 #else
00533       protocol_family = PF_INET;
00534 #endif /* ACE_HAS_IPV6 */
00535     }
00536 
00537 #if defined (ACE_HAS_LKSCTP)
00538   if (ACE_SOCK::open (SOCK_STREAM,
00539 #else
00540   if (ACE_SOCK::open (SOCK_SEQPACKET,
00541 #endif
00542                       protocol_family,
00543                       protocol,
00544                       reuse_addr) == -1)
00545     return -1;
00546   else
00547     return this->shared_open (local_sap,
00548                               protocol_family,
00549                               backlog);
00550 }

int ACE_SOCK_SEQPACK_Acceptor::open const ACE_Addr local_sap,
int  reuse_addr = 0,
int  protocol_family = PF_UNSPEC,
int  backlog = ACE_DEFAULT_BACKLOG,
int  protocol = 132
 

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.

Definition at line 481 of file SOCK_SEQPACK_Acceptor.cpp.

References ACE_TRACE, ACE_Addr::get_type(), ACE::ipv6_enabled(), and ACE_SOCK::open().

Referenced by ACE_SOCK_SEQPACK_Acceptor().

00486 {
00487   ACE_TRACE ("ACE_SOCK_SEQPACK_Acceptor::open");
00488 
00489   if (local_sap != ACE_Addr::sap_any)
00490     protocol_family = local_sap.get_type ();
00491   else if (protocol_family == PF_UNSPEC)
00492     {
00493 #if defined (ACE_HAS_IPV6)
00494       protocol_family = ACE::ipv6_enabled () ? PF_INET6 : PF_INET;
00495 #else
00496       protocol_family = PF_INET;
00497 #endif /* ACE_HAS_IPV6 */
00498     }
00499 
00500 #if defined (ACE_HAS_LKSCTP)
00501   if (ACE_SOCK::open (SOCK_STREAM,
00502 #else
00503   if (ACE_SOCK::open (SOCK_SEQPACKET,
00504 #endif
00505                       protocol_family,
00506                       protocol,
00507                       reuse_addr) == -1)
00508     return -1;
00509   else
00510     return this->shared_open (local_sap,
00511                               protocol_family,
00512                               backlog);
00513 }

int ACE_SOCK_SEQPACK_Acceptor::shared_accept_finish ACE_SOCK_SEQPACK_Association  new_association,
int  in_blocking_mode,
int  reset_new_handle
const [protected]
 

Perform operations that must occur after <ACE_OS::accept> is called.

Definition at line 64 of file SOCK_SEQPACK_Acceptor.cpp.

References ACE_NONBLOCK, ACE_TRACE, ACE::clr_flags(), and ACE_IPC_SAP::get_handle().

Referenced by accept().

00067 {
00068   ACE_TRACE ("ACE_SOCK_SEQPACK_Acceptor::shared_accept_finish ()");
00069 
00070   ACE_HANDLE new_handle = new_association.get_handle ();
00071 
00072   // Check to see if we were originally in blocking mode, and if so,
00073   // set the <new_association>'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 }

int ACE_SOCK_SEQPACK_Acceptor::shared_accept_start ACE_Time_Value timeout,
int  restart,
int &  in_blocking_mode
const [protected]
 

Perform operations that must occur before <ACE_OS::accept> is called.

Definition at line 32 of file SOCK_SEQPACK_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().

00035 {
00036   ACE_TRACE ("ACE_SOCK_SEQPACK_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 }

int ACE_SOCK_SEQPACK_Acceptor::shared_open const ACE_Multihomed_INET_Addr local_sap,
int  protocol_family,
int  backlog
[protected]
 

Multihomed version of same.

Definition at line 241 of file SOCK_SEQPACK_Acceptor.cpp.

References ACE_ASSERT, ACE_NEW_NORETURN, ACE_TRACE, ACE_OS::bind(), close(), ACE_INET_Addr::get_addr(), ACE_Multihomed_INET_Addr::get_addresses(), ACE_Multihomed_INET_Addr::get_num_secondary_addresses(), ACE_Addr::get_size(), ACE_OS::listen(), ACE_OS::memcpy(), and ACE_OS::memset().

00244 {
00245   ACE_TRACE ("ACE_SOCK_SEQPACK_Acceptor::shared_open");
00246   int error = 0;
00247 
00248   // TODO: Add multi-address support to IPV6
00249 #if defined (ACE_HAS_IPV6)
00250   ACE_ASSERT (protocol_family == PF_INET || protocol_family == PF_INET6);
00251 
00252   if (protocol_family == PF_INET6)
00253     {
00254       sockaddr_in6 local_inet6_addr;
00255       ACE_OS::memset (reinterpret_cast<void *> (&local_inet6_addr),
00256                       0,
00257                       sizeof local_inet6_addr);
00258 
00259       if (local_sap.ACE_Addr::operator== (ACE_Addr::sap_any))
00260         {
00261           local_inet6_addr.sin6_family = AF_INET6;
00262           local_inet6_addr.sin6_port = 0;
00263           local_inet6_addr.sin6_addr = in6addr_any;
00264         }
00265       else
00266         local_inet6_addr = *reinterpret_cast<sockaddr_in6 *> (local_sap.get_addr ());
00267 
00268       // We probably don't need a bind_port written here.
00269       // There are currently no supported OS's that define
00270       // ACE_LACKS_WILDCARD_BIND.
00271       if (ACE_OS::bind (this->get_handle (),
00272                         reinterpret_cast<sockaddr *> (&local_inet6_addr),
00273                         sizeof local_inet6_addr) == -1)
00274         error = 1;
00275     }
00276   else
00277 #endif
00278   if (protocol_family == PF_INET)
00279     {
00280       sockaddr_in local_inet_addr;
00281       ACE_OS::memset (reinterpret_cast<void *> (&local_inet_addr),
00282                       0,
00283                       sizeof local_inet_addr);
00284 
00285       if (local_sap.ACE_Addr::operator== (ACE_Addr::sap_any))
00286         {
00287           local_inet_addr.sin_port = 0;
00288         }
00289       else
00290         local_inet_addr = *reinterpret_cast<sockaddr_in *> (local_sap.get_addr ());
00291 
00292 //  A port number of 0 means that the user is requesting that the
00293 //  operating system choose an arbitrary, unused port.  Since some
00294 //  operating systems don't provide this service, ACE provides an
00295 //  emulation layer.  Therefore, the "ACE way" to bind an arbitrary,
00296 //  unused port is to call ACE:bind_port, which either
00297 //
00298 //    (1)  Calls ACE_OS::bind with port 0, if the operating system
00299 //         directly supports the automated selection, or
00300 //
00301 //    (2)  Performs more complicated logic to emulate this feature if
00302 //         it's missing from the OS.
00303 //
00304 //  The emulation logic in choice (2) is compiled if and only if
00305 //  ACE_LACKS_WILDCARD_BIND is defined at compile time.
00306 //
00307 //  Along these lines, the following block of code seems like it would
00308 //  be sufficient to support the wildcard bind operation:
00309 //
00310 //      if (local_inet_addr.sin_port == 0)
00311 //         {
00312 //           if (ACE::bind_port (this->get_handle (),
00313 //               ACE_NTOHL (ACE_UINT32 (local_inet_addr.sin_addr.s_addr))) == -1)
00314 //             error = 1;
00315 //
00316 //         }
00317 //      else
00318 //
00319 //  Unfortunately, this code is insufficient because it does not
00320 //  address the possibility of secondary addresses.
00321 //
00322 //  However, rather than writing the correct code now, I'm putting it
00323 //  off, because this class, ACE_SOCK_SEQPACK_Acceptor, is currently
00324 //  only used with SCTP, and ACE currently supports SCTP only through
00325 //  the OpenSS7 and LKSCTP implmentations, which are available only on
00326 //  Linux.  Linux has native support for the wildcard bind, so the
00327 //  following code works regardless of whether or not the port is 0.
00328 
00329         {
00330           // The total number of addresses is the number of secondary
00331           // addresses plus one.
00332           size_t num_addresses = local_sap.get_num_secondary_addresses() + 1;
00333 
00334           // Create an array of sockaddr_in to hold the underlying
00335           // representations of the primary and secondary
00336           // addresses.
00337           sockaddr_in*  local_inet_addrs = 0;
00338           ACE_NEW_NORETURN (local_inet_addrs,
00339                             sockaddr_in[num_addresses]);
00340 
00341           if (!local_inet_addrs)
00342             error = 1;
00343           else
00344             {
00345               // Populate the array by invoking the get_addresses method
00346               // on the Multihomed_INET_Addr
00347               local_sap.get_addresses(local_inet_addrs,
00348                                       num_addresses);
00349 
00350 #if defined (ACE_HAS_LKSCTP)
00351 
00352               sockaddr_in *local_sockaddr = 0;
00353 
00354               // bind the primary first
00355               if (ACE_OS::bind (this->get_handle (),
00356                                 reinterpret_cast<sockaddr *> (&(local_inet_addrs[0])),
00357                                 sizeof(sockaddr)) == -1)
00358               {
00359                 error = 1;
00360               }
00361 
00362               // do we need to bind multiple addresses?
00363               if (num_addresses > 1)
00364               {
00365                 ACE_NEW_NORETURN(local_sockaddr,
00366                                sockaddr_in[num_addresses - 1]);
00367 
00368                 // all of the secondary addresses need the local port set
00369                 for (size_t i = 1; i < num_addresses; i++)
00370                 {
00371                   local_inet_addrs[i].sin_port = local_inet_addrs[0].sin_port;
00372                 }
00373 
00374                 // copy only the sockaddrs that we need to bindx
00375                 for (size_t i = 0; i < num_addresses - 1; i++)
00376                 {
00377                   ACE_OS::memcpy(&(local_sockaddr[i]),
00378                                  &(local_inet_addrs[i + 1]),
00379                                  sizeof(sockaddr_in));
00380                 }
00381 
00382                 // now call bindx
00383                 if (!error && sctp_bindx(this->get_handle (),
00384                                          reinterpret_cast<sockaddr *> (local_sockaddr),
00385                                          num_addresses - 1,
00386                                          SCTP_BINDX_ADD_ADDR))
00387                 {
00388                   error = 1;
00389                 }
00390 
00391                 delete [] local_sockaddr;
00392               }
00393 #else
00394               // Call bind
00395               size_t name_len = (sizeof local_inet_addr) * num_addresses;
00396               if (ACE_OS::bind (this->get_handle (),
00397                                 reinterpret_cast<sockaddr *> (local_inet_addrs),
00398                                 static_cast<int> (name_len)) == -1)
00399                 error = 1;
00400 #endif /* ACE_HAS_LKSCTP */
00401             }
00402 
00403           delete [] local_inet_addrs;
00404         }
00405     }
00406   else if (ACE_OS::bind (this->get_handle (),
00407                          (sockaddr *) local_sap.get_addr (),
00408                          local_sap.get_size ()) == -1)
00409     error = 1;
00410 
00411   if (error != 0
00412       || ACE_OS::listen (this->get_handle (),
00413                          backlog) == -1)
00414     {
00415       error = 1;
00416       this->close ();
00417     }
00418 
00419   return error ? -1 : 0;
00420 }

int ACE_SOCK_SEQPACK_Acceptor::shared_open const ACE_Addr local_sap,
int  protocol_family,
int  backlog
[protected]
 

This method factors out the common code and is called by both the QoS-enabled method and the BSD-style method.

Definition at line 163 of file SOCK_SEQPACK_Acceptor.cpp.

References ACE_ASSERT, ACE_TRACE, ACE_OS::bind(), ACE::bind_port(), close(), ACE_Addr::get_addr(), ACE_Addr::get_size(), ACE_OS::listen(), and ACE_OS::memset().

00166 {
00167   ACE_TRACE ("ACE_SOCK_SEQPACK_Acceptor::shared_open");
00168   int error = 0;
00169 
00170 #if defined (ACE_HAS_IPV6)
00171   ACE_ASSERT (protocol_family == PF_INET || protocol_family == PF_INET6);
00172 
00173   if (protocol_family == PF_INET6)
00174     {
00175       sockaddr_in6 local_inet6_addr;
00176       ACE_OS::memset (reinterpret_cast<void *> (&local_inet6_addr),
00177                       0,
00178                       sizeof local_inet6_addr);
00179 
00180       if (local_sap == ACE_Addr::sap_any)
00181         {
00182           local_inet6_addr.sin6_family = AF_INET6;
00183           local_inet6_addr.sin6_port = 0;
00184           local_inet6_addr.sin6_addr = in6addr_any;
00185         }
00186       else
00187         local_inet6_addr = *reinterpret_cast<sockaddr_in6 *> (local_sap.get_addr ());
00188 
00189       // We probably don't need a bind_port written here.
00190       // There are currently no supported OS's that define
00191       // ACE_LACKS_WILDCARD_BIND.
00192       if (ACE_OS::bind (this->get_handle (),
00193                         reinterpret_cast<sockaddr *> (&local_inet6_addr),
00194                         sizeof local_inet6_addr) == -1)
00195         error = 1;
00196     }
00197   else
00198 #endif
00199   if (protocol_family == PF_INET)
00200     {
00201       sockaddr_in local_inet_addr;
00202       ACE_OS::memset (reinterpret_cast<void *> (&local_inet_addr),
00203                       0,
00204                       sizeof local_inet_addr);
00205 
00206       if (local_sap == ACE_Addr::sap_any)
00207         {
00208           local_inet_addr.sin_port = 0;
00209         }
00210       else
00211         local_inet_addr = *reinterpret_cast<sockaddr_in *> (local_sap.get_addr ());
00212       if (local_inet_addr.sin_port == 0)
00213         {
00214           if (ACE::bind_port (this->get_handle ()) == -1)
00215             error = 1;
00216         }
00217       else if (ACE_OS::bind (this->get_handle (),
00218                              reinterpret_cast<sockaddr *> (&local_inet_addr),
00219                              sizeof local_inet_addr) == -1)
00220         error = 1;
00221     }
00222   else if (ACE_OS::bind (this->get_handle (),
00223                          (sockaddr *) local_sap.get_addr (),
00224                          local_sap.get_size ()) == -1)
00225     error = 1;
00226 
00227   if (error != 0
00228       || ACE_OS::listen (this->get_handle (),
00229                          backlog) == -1)
00230     {
00231       error = 1;
00232       this->close ();
00233     }
00234 
00235   return error ? -1 : 0;
00236 }


Member Data Documentation

ACE_SOCK_SEQPACK_Acceptor::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented from ACE_SOCK.

Definition at line 147 of file SOCK_SEQPACK_Acceptor.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:29:58 2006 for ACE by doxygen 1.3.6