Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions

ACE_SOCK_Dgram Class Reference

Defines the member functions for the ACE_SOCK datagram abstraction. More...

#include <SOCK_Dgram.h>

Inheritance diagram for ACE_SOCK_Dgram:
Inheritance graph
[legend]
Collaboration diagram for ACE_SOCK_Dgram:
Collaboration graph
[legend]

List of all members.

Public Types

typedef ACE_INET_Addr PEER_ADDR

Public Member Functions

 ACE_SOCK_Dgram (void)
 Default constructor.
 ACE_SOCK_Dgram (const ACE_Addr &local, int protocol_family=ACE_PROTOCOL_FAMILY_INET, int protocol=0, int reuse_addr=0)
 ACE_SOCK_Dgram (const ACE_Addr &local, int protocol_family, int protocol, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g=0, u_long flags=0, int reuse_addr=0)
int open (const ACE_Addr &local, int protocol_family=ACE_PROTOCOL_FAMILY_INET, int protocol=0, int reuse_addr=0)
int open (const ACE_Addr &local, int protocol_family, int protocol, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g=0, u_long flags=0, int reuse_addr=0)
 ~ACE_SOCK_Dgram (void)
 Default dtor.
ssize_t send (const void *buf, size_t n, const ACE_Addr &addr, int flags=0) const
 Send an n byte buf to the datagram socket (uses <sendto(3)>).
ssize_t recv (void *buf, size_t n, ACE_Addr &addr, int flags=0) const
ssize_t recv (iovec *io_vec, ACE_Addr &addr, int flags=0, const ACE_Time_Value *timeout=0) const
ssize_t send (const iovec iov[], int n, const ACE_Addr &addr, int flags=0) const
ssize_t recv (iovec iov[], int n, ACE_Addr &addr, int flags=0) const
ssize_t recv (void *buf, size_t n, ACE_Addr &addr, int flags, const ACE_Time_Value *timeout) const
ssize_t send (const void *buf, size_t n, const ACE_Addr &addr, int flags, const ACE_Time_Value *timeout) const
ssize_t send (const iovec buffers[], int buffer_count, size_t &number_of_bytes_sent, int flags, const ACE_Addr &addr, ACE_OVERLAPPED *overlapped, ACE_OVERLAPPED_COMPLETION_FUNC func) const
ssize_t recv (iovec buffers[], int buffer_count, size_t &number_of_bytes_recvd, int &flags, ACE_Addr &addr, ACE_OVERLAPPED *overlapped, ACE_OVERLAPPED_COMPLETION_FUNC func) const
ssize_t send (const void *buf, size_t n, const ACE_Addr &addr, int flags, ACE_OVERLAPPED *overlapped, ACE_OVERLAPPED_COMPLETION_FUNC func) const
 Send an n byte buf to the datagram socket (uses <WSASendTo>).
ssize_t recv (void *buf, size_t n, ACE_Addr &addr, int flags, ACE_OVERLAPPED *overlapped, ACE_OVERLAPPED_COMPLETION_FUNC func) const
void dump (void) const
 Dump the state of an object.
int set_nic (const ACE_TCHAR *net_if, int addr_family=AF_UNSPEC)
 Set NIC to use as multicast interface.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Protected Member Functions

int shared_open (const ACE_Addr &local, int protocol_family)
 Open is shared by this and by <LSOCK_Dgram>.
int make_multicast_ifaddr (ip_mreq *mreq, const ACE_INET_Addr &mcast_addr, const ACE_TCHAR *net_if)

Private Member Functions

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

Detailed Description

Defines the member functions for the ACE_SOCK datagram abstraction.

Definition at line 36 of file SOCK_Dgram.h.


Member Typedef Documentation

Definition at line 195 of file SOCK_Dgram.h.


Constructor & Destructor Documentation

ACE_SOCK_Dgram::ACE_SOCK_Dgram ( void   ) 

Default constructor.

Definition at line 14 of file SOCK_Dgram.inl.

{
  ACE_TRACE ("ACE_SOCK_Dgram::ACE_SOCK_Dgram");
}

ACE_SOCK_Dgram::ACE_SOCK_Dgram ( const ACE_Addr local,
int  protocol_family = ACE_PROTOCOL_FAMILY_INET,
int  protocol = 0,
int  reuse_addr = 0 
)

This is a BSD-style method (i.e., no QoS) for initiating a socket dgram that will accept datagrams at the <local> address.

Definition at line 224 of file SOCK_Dgram.cpp.

{
  ACE_TRACE ("ACE_SOCK_Dgram::ACE_SOCK_Dgram");

  if (this->open (local,
                  protocol_family,
                  protocol,
                  reuse_addr) == -1)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("ACE_SOCK_Dgram")));
}

ACE_SOCK_Dgram::ACE_SOCK_Dgram ( const ACE_Addr local,
int  protocol_family,
int  protocol,
ACE_Protocol_Info protocolinfo,
ACE_SOCK_GROUP  g = 0,
u_long  flags = 0,
int  reuse_addr = 0 
)

This is a QoS-enabed method for initiating a socket dgram that will accept datagrams at the <local> address. The qos_params are passed to <ACE_OS::join_leaf>.

Definition at line 240 of file SOCK_Dgram.cpp.

{
  ACE_TRACE ("ACE_SOCK_Dgram::ACE_SOCK_Dgram");
  if (this->open (local,
                  protocol_family,
                  protocol,
                  protocolinfo,
                  g,
                  flags,
                  reuse_addr) == -1)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("ACE_SOCK_Dgram")));
}

ACE_SOCK_Dgram::~ACE_SOCK_Dgram ( void   ) 

Default dtor.

Definition at line 20 of file SOCK_Dgram.inl.

{
  ACE_TRACE ("ACE_SOCK_Dgram::~ACE_SOCK_Dgram");
}


Member Function Documentation

void ACE_SOCK_Dgram::dump ( void   )  const

Dump the state of an object.

Reimplemented from ACE_SOCK.

Reimplemented in ACE_SOCK_Dgram_Bcast, and ACE_SOCK_Dgram_Mcast.

int ACE_SOCK_Dgram::get_remote_addr ( ACE_Addr  )  const [private]

Do not allow this function to percolate up to this interface...

Reimplemented from ACE_SOCK.

Reimplemented in ACE_SOCK_Dgram_Bcast.

int ACE_SOCK_Dgram::make_multicast_ifaddr ( ip_mreq *  mreq,
const ACE_INET_Addr mcast_addr,
const ACE_TCHAR net_if 
) [protected]

Create a multicast addr/if pair, in format useful for system calls. If mreq param is NULL, just verify the passed addr/interface specs.

Definition at line 610 of file SOCK_Dgram.cpp.

{
  ACE_TRACE ("ACE_SOCK_Dgram_Mcast::make_multicast_ifaddr");
  ip_mreq  lmreq;       // Scratch copy.
  if (net_if != 0)
    {
#if defined (ACE_WIN32) || defined(__INTERIX)
      // This port number is not necessary, just convenient
      ACE_INET_Addr interface_addr;
      if (interface_addr.set (mcast_addr.get_port_number (), net_if) == -1)
        return -1;
      lmreq.imr_interface.s_addr =
        ACE_HTONL (interface_addr.get_ip_address ());
#else
      ifreq if_address;

      ACE_OS::strcpy (if_address.ifr_name, ACE_TEXT_ALWAYS_CHAR (net_if));

      if (ACE_OS::ioctl (this->get_handle (),
                         SIOCGIFADDR,
                         &if_address) == -1)
        return -1;

      sockaddr_in *socket_address =
        reinterpret_cast<sockaddr_in*> (&if_address.ifr_addr);
      lmreq.imr_interface.s_addr = socket_address->sin_addr.s_addr;
#endif /* ACE_WIN32 || __INTERIX */
    }
  else
    lmreq.imr_interface.s_addr = INADDR_ANY;

  lmreq.IMR_MULTIADDR.s_addr = ACE_HTONL (mcast_addr.get_ip_address ());

  // Set return info, if requested.
  if (ret_mreq)
    *ret_mreq = lmreq;

  return 0;
}

int ACE_SOCK_Dgram::open ( const ACE_Addr local,
int  protocol_family,
int  protocol,
ACE_Protocol_Info protocolinfo,
ACE_SOCK_GROUP  g = 0,
u_long  flags = 0,
int  reuse_addr = 0 
)

This is a QoS-enabed method for initiating a socket dgram that will accept datagrams at the <local> address. The qos_params are passed to <ACE_OS::join_leaf>.

Definition at line 167 of file SOCK_Dgram.cpp.

{
  if (ACE_SOCK::open (SOCK_DGRAM,
                      protocol_family,
                      protocol,
                      protocolinfo,
                      g,
                      flags,
                      reuse_addr) == -1)
    return -1;
  else if (this->shared_open (local,
                              protocol_family) == -1)
    return -1;
  else
    return 0;
}

int ACE_SOCK_Dgram::open ( const ACE_Addr local,
int  protocol_family = ACE_PROTOCOL_FAMILY_INET,
int  protocol = 0,
int  reuse_addr = 0 
)

This is a BSD-style method (i.e., no QoS) for initiating a socket dgram that will accept datagrams at the <local> address.

Definition at line 193 of file SOCK_Dgram.cpp.

{
  ACE_TRACE ("ACE_SOCK_Dgram::open");

  if (local != ACE_Addr::sap_any)
    protocol_family = local.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_DGRAM,
                      protocol_family,
                      protocol,
                      reuse_addr) == -1)
    return -1;
  else
    return this->shared_open (local,
                              protocol_family);
}

ssize_t ACE_SOCK_Dgram::recv ( void *  buf,
size_t  n,
ACE_Addr addr,
int  flags,
const ACE_Time_Value timeout 
) const

Wait up to timeout amount of time to receive a datagram into buf. The ACE_Time_Value indicates how long to blocking trying to receive. If timeout == 0, the caller will block until action is possible, else will wait until the relative time specified in *timeout elapses). If <recv> times out a -1 is returned with errno == ETIME. If it succeeds the number of bytes received is returned.

Definition at line 450 of file SOCK_Dgram.cpp.

{
  ACE_Handle_Set handle_set;
  handle_set.reset ();
  handle_set.set_bit (this->get_handle ());

  // Check the status of the current socket.
#if defined (ACE_WIN32)
  // This arg is ignored on Windows and causes pointer truncation
  // warnings on 64-bit compiles.
  int select_width = 0;
#else
  int select_width = int (this->get_handle ()) + 1;
#endif /* ACE_WIN32 */
  switch (ACE_OS::select (select_width,
                          handle_set,
                          0,
                          0,
                          timeout))
    {
    case -1:
      return -1;
      /* NOTREACHED */
    case 0:
      errno = ETIME;
      return -1;
      /* NOTREACHED */
    default:
      // Goes fine, call <recv> to get data
      return this->recv (buf, n, addr, flags);
    }
}

ssize_t ACE_SOCK_Dgram::recv ( void *  buf,
size_t  n,
ACE_Addr addr,
int  flags = 0 
) const

Receive an n byte buf from the datagram socket (uses <recvfrom(3)>).

Definition at line 47 of file SOCK_Dgram.inl.

{
  ACE_TRACE ("ACE_SOCK_Dgram::recv");
  sockaddr *saddr = (sockaddr *) addr.get_addr ();
  int addr_len = addr.get_size ();

  ssize_t const status = ACE_OS::recvfrom (this->get_handle (),
                                           (char *) buf,
                                           n,
                                           flags,
                                           (sockaddr *) saddr,
                                           &addr_len);
  addr.set_size (addr_len);
  addr.set_type (saddr->sa_family);
  return status;
}

ssize_t ACE_SOCK_Dgram::recv ( iovec *  io_vec,
ACE_Addr addr,
int  flags = 0,
const ACE_Time_Value timeout = 0 
) const

Allows a client to read from a socket without having to provide a buffer to read. This method determines how much data is in the socket, allocates a buffer of this size, reads in the data, and returns the number of bytes read. The caller is responsible for deleting the member in the <iov_base> field of <io_vec> using the ``delete []'' syntax.

Definition at line 50 of file SOCK_Dgram.cpp.

{
  ACE_TRACE ("ACE_SOCK_Dgram::recv");
#if defined (FIONREAD)
  ACE_Handle_Set handle_set;
  handle_set.reset ();
  handle_set.set_bit (this->get_handle ());

  // Check the status of the current socket to make sure there's data
  // to recv (or time out).
#  if defined (ACE_WIN32)
  // This arg is ignored on Windows and causes pointer truncation
  // warnings on 64-bit compiles.
  int select_width = 0;
#  else
  int select_width = int (this->get_handle ()) + 1;
#  endif /* ACE_WIN32 */
  switch (ACE_OS::select (select_width,
                          handle_set,
                          0, 0,
                          timeout))
    {
    case -1:
      return -1;
      /* NOTREACHED */
    case 0:
      errno = ETIME;
      return -1;
      /* NOTREACHED */
    default:
      // Goes fine, fallthrough to get data
      break;
    }

  sockaddr *saddr = (sockaddr *) addr.get_addr ();
  int addr_len = addr.get_size ();
  int inlen;

  if (ACE_OS::ioctl (this->get_handle (),
                     FIONREAD,
                     &inlen) == -1)
    return -1;
  else if (inlen > 0)
    {
      ACE_NEW_RETURN (io_vec->iov_base,
                      char[inlen],
                      -1);
      ssize_t rcv_len = ACE_OS::recvfrom (this->get_handle (),
                                          (char *) io_vec->iov_base,
                                          inlen,
                                          flags,
                                          (sockaddr *) saddr,
                                          &addr_len);
      if (rcv_len < 0)
        {
          delete [] (char *)io_vec->iov_base;
          io_vec->iov_base = 0;
        }
      else
        {
          io_vec->iov_len = ACE_Utils::truncate_cast<u_long> (rcv_len);
          addr.set_size (addr_len);
        }
      return rcv_len;
    }
  else
    return 0;
#else
  ACE_UNUSED_ARG (flags);
  ACE_UNUSED_ARG (addr);
  ACE_UNUSED_ARG (io_vec);
  ACE_UNUSED_ARG (timeout);
  ACE_NOTSUP_RETURN (-1);
#endif /* FIONREAD */
}

ssize_t ACE_SOCK_Dgram::recv ( iovec  buffers[],
int  buffer_count,
size_t &  number_of_bytes_recvd,
int &  flags,
ACE_Addr addr,
ACE_OVERLAPPED overlapped,
ACE_OVERLAPPED_COMPLETION_FUNC  func 
) const

Recv <buffer_count> worth of buffers from addr using overlapped I/O (uses <WSARecvFrom>). Returns 0 on success.

Definition at line 91 of file SOCK_Dgram.inl.

{
  ACE_TRACE ("ACE_SOCK_Dgram::recv");
  sockaddr *saddr = (sockaddr *) addr.get_addr ();
  int addr_len = addr.get_size ();

  ssize_t status = ACE_OS::recvfrom (this->get_handle (),
                                     buffers,
                                     buffer_count,
                                     number_of_bytes_recvd,
                                     flags,
                                     (sockaddr *) saddr,
                                     &addr_len,
                                     overlapped,
                                     func);
  addr.set_size (addr_len);
  addr.set_type (saddr->sa_family);
  return status;
}

ssize_t ACE_SOCK_Dgram::recv ( void *  buf,
size_t  n,
ACE_Addr addr,
int  flags,
ACE_OVERLAPPED overlapped,
ACE_OVERLAPPED_COMPLETION_FUNC  func 
) const

Receive an n byte buf from the datagram socket (uses <WSARecvFrom>).

Definition at line 145 of file SOCK_Dgram.inl.

{
  ACE_TRACE ("ACE_SOCK_Dgram::recv");

  iovec buffer[1];
  buffer[0].iov_len = static_cast<u_long> (n);  // Betting on < 4G
  buffer[0].iov_base = (char *) buf;
  size_t number_of_bytes_recvd = 0;
  return this->recv (buffer,
                     1,
                     number_of_bytes_recvd,
                     flags,
                     addr,
                     overlapped,
                     func);
}

ssize_t ACE_SOCK_Dgram::recv ( iovec  iov[],
int  n,
ACE_Addr addr,
int  flags = 0 
) const

Recv an <iovec> of size n to the datagram socket (uses <recvmsg(3)>).

Definition at line 390 of file SOCK_Dgram.cpp.

{
  ACE_TRACE ("ACE_SOCK_Dgram::recv");

  ssize_t length = 0;
  int i;

  for (i = 0; i < n; i++)
#if ! (defined(__BORLANDC__) || defined(linux) || defined(ACE_HAS_RTEMS))
    // The iov_len is unsigned on Linux, RTEMS and with Borland. If we go
    // ahead and try the if, it will emit a warning.
    if (iov[i].iov_len < 0)
      return -1;
    else
#endif
      length += iov[i].iov_len;

  char *buf = 0;

#if defined (ACE_HAS_ALLOCA)
  buf = alloca (length);
#else
  ACE_NEW_RETURN (buf,
                  char[length],
                  -1);
#endif /* !defined (ACE_HAS_ALLOCA) */

  length = ACE_SOCK_Dgram::recv (buf, length, addr, flags);

  if (length != -1)
    {
      char *ptr = buf;
      int copyn = length;

      for (i = 0;
           i < n && copyn > 0;
           i++)
        {
          ACE_OS::memcpy (iov[i].iov_base, ptr,
                          // iov_len is int on some platforms, size_t on others
                          copyn > (int) iov[i].iov_len
                            ? (size_t) iov[i].iov_len
                            : (size_t) copyn);
          ptr += iov[i].iov_len;
          copyn -= iov[i].iov_len;
        }
    }

#if !defined (ACE_HAS_ALLOCA)
  delete [] buf;
#endif /* !defined (ACE_HAS_ALLOCA) */
  return length;
}

ssize_t ACE_SOCK_Dgram::send ( const iovec  iov[],
int  n,
const ACE_Addr addr,
int  flags = 0 
) const

Send an <iovec> of size n to the datagram socket (uses <sendmsg(3)>).

Reimplemented in ACE_SOCK_Dgram_Bcast.

Definition at line 340 of file SOCK_Dgram.cpp.

{
  ACE_TRACE ("ACE_SOCK_Dgram::send");

  size_t length = 0;
  int i;

  // Determine the total length of all the buffers in <iov>.
  for (i = 0; i < n; i++)
#if ! (defined(__BORLANDC__) || defined(linux) || defined(ACE_HAS_RTEMS))
    // The iov_len is unsigned on Linux, RTEMS and with Borland. If we go
    // ahead and try the if, it will emit a warning.
    if (iov[i].iov_len < 0)
      return -1;
    else
#endif
      length += iov[i].iov_len;

  char *buf = 0;

#if defined (ACE_HAS_ALLOCA)
  buf = alloca (length);
#else
  ACE_NEW_RETURN (buf,
                  char[length],
                  -1);
#endif /* !defined (ACE_HAS_ALLOCA) */

  char *ptr = buf;

  for (i = 0; i < n; i++)
    {
      ACE_OS::memcpy (ptr, iov[i].iov_base, iov[i].iov_len);
      ptr += iov[i].iov_len;
    }

  ssize_t result = ACE_SOCK_Dgram::send (buf, length, addr, flags);
#if !defined (ACE_HAS_ALLOCA)
  delete [] buf;
#endif /* !defined (ACE_HAS_ALLOCA) */
  return result;
}

ssize_t ACE_SOCK_Dgram::send ( const void *  buf,
size_t  n,
const ACE_Addr addr,
int  flags = 0 
) const

Send an n byte buf to the datagram socket (uses <sendto(3)>).

Reimplemented in ACE_SOCK_Dgram_Bcast.

Definition at line 28 of file SOCK_Dgram.inl.

{
  ACE_TRACE ("ACE_SOCK_Dgram::send");
  sockaddr *saddr = (sockaddr *) addr.get_addr ();
  int len = addr.get_size ();
  return ACE_OS::sendto (this->get_handle (),
                         (const char *) buf,
                         n,
                         flags,
                         (struct sockaddr *) saddr,
                         len);
}

ssize_t ACE_SOCK_Dgram::send ( const void *  buf,
size_t  n,
const ACE_Addr addr,
int  flags,
ACE_OVERLAPPED overlapped,
ACE_OVERLAPPED_COMPLETION_FUNC  func 
) const

Send an n byte buf to the datagram socket (uses <WSASendTo>).

Reimplemented in ACE_SOCK_Dgram_Mcast_QoS.

Definition at line 120 of file SOCK_Dgram.inl.

{
  ACE_TRACE ("ACE_SOCK_Dgram::send");

  iovec buffer[1];
  buffer[0].iov_len = static_cast<u_long> (n);  // Betting on < 4G
  buffer[0].iov_base = (char *) buf;
  size_t number_of_bytes_sent = 0;
  return this->send (buffer,
                     1,
                     number_of_bytes_sent,
                     flags,
                     addr,
                     overlapped,
                     func);
}

ssize_t ACE_SOCK_Dgram::send ( const iovec  buffers[],
int  buffer_count,
size_t &  number_of_bytes_sent,
int  flags,
const ACE_Addr addr,
ACE_OVERLAPPED overlapped,
ACE_OVERLAPPED_COMPLETION_FUNC  func 
) const

Send <buffer_count> worth of buffers to addr using overlapped I/O (uses <WSASendTo>). Returns 0 on success.

Reimplemented in ACE_SOCK_Dgram_Mcast_QoS.

Definition at line 68 of file SOCK_Dgram.inl.

{
  ACE_TRACE ("ACE_SOCK_Dgram::send");
  sockaddr *saddr = (sockaddr *) addr.get_addr ();
  int len = addr.get_size ();
  return ACE_OS::sendto (this->get_handle (),
                         buffers,
                         buffer_count,
                         number_of_bytes_sent,
                         flags,
                         (const sockaddr *) saddr,
                         len,
                         overlapped,
                         func);
}

ssize_t ACE_SOCK_Dgram::send ( const void *  buf,
size_t  n,
const ACE_Addr addr,
int  flags,
const ACE_Time_Value timeout 
) const

Wait up to timeout amount of time to send a datagram to buf. The ACE_Time_Value indicates how long to blocking trying to receive. If timeout == 0, the caller will block until action is possible, else will wait until the relative time specified in *timeout elapses). If <send> times out a -1 is returned with errno == ETIME. If it succeeds the number of bytes sent is returned.

Definition at line 488 of file SOCK_Dgram.cpp.

{
  ACE_Handle_Set handle_set;
  handle_set.reset ();
  handle_set.set_bit (this->get_handle ());

  // Check the status of the current socket.
#if defined (ACE_WIN32)
  // This arg is ignored on Windows and causes pointer truncation
  // warnings on 64-bit compiles.
  int select_width = 0;
#else
  int select_width = int (this->get_handle ()) + 1;
#endif /* ACE_WIN32 */
  switch (ACE_OS::select (select_width,
                          0,
                          handle_set,
                          0,
                          timeout))
    {
    case -1:
      return -1;
      /* NOTREACHED */
    case 0:
      errno = ETIME;
      return -1;
      /* NOTREACHED */
    default:
      // Goes fine, call <send> to transmit the data.
      return this->send (buf, n, addr, flags);
    }
}

int ACE_SOCK_Dgram::set_nic ( const ACE_TCHAR net_if,
int  addr_family = AF_UNSPEC 
)

Set NIC to use as multicast interface.

Definition at line 526 of file SOCK_Dgram.cpp.

{
#if defined (IP_MULTICAST_IF) && (IP_MULTICAST_IF != 0)
# if defined (ACE_HAS_IPV6)
  bool ipv6_mif_set = false;
  if (addr_family == AF_INET6 || addr_family == AF_UNSPEC)
    {
      ACE_INET_Addr addr;
      addr.set (static_cast<u_short> (0), ACE_IPV6_ANY);
      ipv6_mreq send_mreq;
      if (this->make_multicast_ifaddr6 (&send_mreq,
                                        addr,
                                        net_if) == -1)
        return -1;

      // Only let this attempt to set unknown interface when INET6 is
      // specifically requested. Otherwise we will just try INET.
      if (send_mreq.ipv6mr_interface != 0 || addr_family == AF_INET6)
        {
          if (this->ACE_SOCK::set_option
                              (IPPROTO_IPV6, IPV6_MULTICAST_IF,
                               &(send_mreq.ipv6mr_interface),
                               sizeof send_mreq.ipv6mr_interface) == -1)
            return -1;
        }
      ipv6_mif_set = send_mreq.ipv6mr_interface != 0;
    }

#   if defined (ACE_WIN32)
  // For Win32 net_if is distintly different between INET6 and INET
  // so it is always either an INET6 if or an INET if.
  if (!ipv6_mif_set && (addr_family == AF_INET || addr_family == AF_UNSPEC))
#   else
  if (addr_family == AF_INET || addr_family == AF_UNSPEC)
#   endif
    {
      ACE_INET_Addr addr (static_cast<u_short> (0));
      ip_mreq  send_mreq;
      if (this->make_multicast_ifaddr (&send_mreq,
                                       addr,
                                       net_if) == -1)
        {
          if (!ipv6_mif_set)
            return -1;
        }
      else if (this->ACE_SOCK::set_option (IPPROTO_IP,
                                           IP_MULTICAST_IF,
                                           &(send_mreq.imr_interface),
                                           sizeof send_mreq.imr_interface) == -1)
        {
          if (!ipv6_mif_set)
            return -1;
        }
    }
# else /* ACE_HAS_IPV6 */
  ACE_UNUSED_ARG (addr_family);
  ACE_INET_Addr addr (static_cast<u_short> (0));
  ip_mreq  send_mreq;
  if (this->make_multicast_ifaddr (&send_mreq,
                                   addr,
                                   net_if) == -1)
    return -1;
  if (this->ACE_SOCK::set_option (IPPROTO_IP,
                                  IP_MULTICAST_IF,
                                  &(send_mreq.imr_interface),
                                  sizeof send_mreq.imr_interface) == -1)
    return -1;
# endif /* !ACE_HAS_IPV6 */
#else /* IP_MULTICAST_IF */
  // Send interface option not supported - ignore it.
  // (We may have been invoked by ::subscribe, so we have to allow
  // a non-null interface parameter in this function.)
  ACE_UNUSED_ARG (net_if);
  ACE_UNUSED_ARG (addr_family);
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Send interface specification not ")
              ACE_TEXT ("supported - IGNORED.\n")));
#endif /* !IP_MULTICAST_IF */

  return 0;
}

int ACE_SOCK_Dgram::shared_open ( const ACE_Addr local,
int  protocol_family 
) [protected]

Open is shared by this and by <LSOCK_Dgram>.

Definition at line 135 of file SOCK_Dgram.cpp.

{
  ACE_TRACE ("ACE_SOCK_Dgram::shared_open");
  bool error = false;

  if (local == ACE_Addr::sap_any)
    {
      if (protocol_family == PF_INET
#if defined (ACE_HAS_IPV6)
          || protocol_family == PF_INET6
#endif /* ACE_HAS_IPV6 */
          )
        {
          if (ACE::bind_port (this->get_handle (),
                              INADDR_ANY,
                              protocol_family) == -1)
            error = true;
        }
    }
  else if (ACE_OS::bind (this->get_handle (),
                         reinterpret_cast<sockaddr *> (local.get_addr ()),
                         local.get_size ()) == -1)
    error = true;

  if (error)
    this->close ();

  return error ? -1 : 0;
}


Member Data Documentation

Declare the dynamic allocation hooks.

Reimplemented from ACE_SOCK.

Reimplemented in ACE_SOCK_Dgram_Mcast_QoS, ACE_SOCK_Dgram_Bcast, and ACE_SOCK_Dgram_Mcast.

Definition at line 205 of file SOCK_Dgram.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines