Public Member Functions | Public Attributes | Protected Member Functions

ACE_SOCK Class Reference

An abstract class that forms the basis for more specific classes, such as ACE_SOCK_Acceptor and ACE_SOCK_Stream. Do not instantiate this class. More...

#include <SOCK.h>

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

List of all members.

Public Member Functions

int set_option (int level, int option, void *optval, int optlen) const
 Wrapper around the setsockopt system call.
int get_option (int level, int option, void *optval, int *optlen) const
 Wrapper around the getsockopt system call.
int close (void)
int get_local_addr (ACE_Addr &) const
int get_remote_addr (ACE_Addr &) const
void dump (void) const
 Dump the state of an object.
int open (int type, int protocol_family, int protocol, int reuse_addr)
 Wrapper around the BSD-style socket system call (no QoS).
int open (int type, int protocol_family, int protocol, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g, u_long flags, int reuse_addr)
 Wrapper around the QoS-enabled WSASocket function.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Protected Member Functions

 ACE_SOCK (int type, int protocol_family, int protocol=0, int reuse_addr=0)
 ACE_SOCK (int type, int protocol_family, int protocol, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g, u_long flags, int reuse_addr)
 ACE_SOCK (void)
 ~ACE_SOCK (void)
 Protected destructor.

Detailed Description

An abstract class that forms the basis for more specific classes, such as ACE_SOCK_Acceptor and ACE_SOCK_Stream. Do not instantiate this class.

This class provides functions that are common to all of the <ACE_SOCK_*> classes. ACE_SOCK provides the ability to get and set socket options, get the local and remote addresses, and open and close a socket handle.

Definition at line 41 of file SOCK.h.


Constructor & Destructor Documentation

ACE_SOCK::ACE_SOCK ( int  type,
int  protocol_family,
int  protocol = 0,
int  reuse_addr = 0 
) [protected]

Constructor with arguments to call the BSD-style socket system call (no QoS).

Definition at line 115 of file SOCK.cpp.

{
  // ACE_TRACE ("ACE_SOCK::ACE_SOCK");
  if (this->open (type,
                  protocol_family,
                  protocol,
                  reuse_addr) == -1)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("ACE_SOCK::ACE_SOCK")));
}

ACE_SOCK::ACE_SOCK ( int  type,
int  protocol_family,
int  protocol,
ACE_Protocol_Info protocolinfo,
ACE_SOCK_GROUP  g,
u_long  flags,
int  reuse_addr 
) [protected]

Constructor with arguments to call the QoS-enabled WSASocket function.

Definition at line 164 of file SOCK.cpp.

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

ACE_SOCK::ACE_SOCK ( void   )  [protected]

Default constructor is protected to prevent instances of this class from being defined.

Definition at line 24 of file SOCK.cpp.

{
  // ACE_TRACE ("ACE_SOCK::ACE_SOCK");
}

ACE_SOCK::~ACE_SOCK ( void   )  [protected]

Protected destructor.

Not a virtual destructor. Protected destructor to prevent operator delete() from being called through a base class ACE_SOCK pointer/reference.

Definition at line 10 of file SOCK.inl.

{
  // ACE_TRACE ("ACE_SOCK::~ACE_SOCK");
}


Member Function Documentation

int ACE_SOCK::close ( void   ) 

Close the socket. This method also sets the object's handle value to ACE_INVALID_HANDLE.

Returns:
The result of closing the socket; 0 if the handle value was already ACE_INVALID_HANDLE.

Reimplemented in ACE_SOCK_Acceptor, ACE_SOCK_Dgram_Bcast, ACE_SOCK_SEQPACK_Acceptor, ACE_SOCK_SEQPACK_Association, ACE_SOCK_Stream, ACE_SSL_SOCK_Acceptor, and ACE_SSL_SOCK_Stream.

Definition at line 71 of file SOCK.cpp.

{
  ACE_TRACE ("ACE_SOCK::close");
  int result = 0;

  if (this->get_handle () != ACE_INVALID_HANDLE)
    {
      result = ACE_OS::closesocket (this->get_handle ());
      this->set_handle (ACE_INVALID_HANDLE);
    }
  return result;
}

void ACE_SOCK::dump ( void   )  const

Dump the state of an object.

Reimplemented from ACE_IPC_SAP.

Reimplemented in ACE_LSOCK_Acceptor, ACE_SOCK_Acceptor, ACE_SOCK_CODgram, ACE_SOCK_Dgram, ACE_SOCK_Dgram_Bcast, ACE_SOCK_Dgram_Mcast, ACE_SOCK_IO, ACE_SOCK_SEQPACK_Acceptor, ACE_SOCK_SEQPACK_Association, and ACE_SOCK_Stream.

Definition at line 17 of file SOCK.cpp.

{
#if defined (ACE_HAS_DUMP)
  ACE_TRACE ("ACE_SOCK::dump");
#endif /* ACE_HAS_DUMP */
}

int ACE_SOCK::get_local_addr ( ACE_Addr sa  )  const

Return the local endpoint address in the referenced <ACE_Addr>. Returns 0 if successful, else -1.

Reimplemented in ACE_LSOCK_Acceptor.

Definition at line 51 of file SOCK.cpp.

{
  ACE_TRACE ("ACE_SOCK::get_local_addr");

  int len = sa.get_size ();
  sockaddr *addr = reinterpret_cast<sockaddr *> (sa.get_addr ());

  if (ACE_OS::getsockname (this->get_handle (),
                           addr,
                           &len) == -1)
    return -1;

  sa.set_type (addr->sa_family);
  sa.set_size (len);
  return 0;
}

int ACE_SOCK::get_option ( int  level,
int  option,
void *  optval,
int *  optlen 
) const

Wrapper around the getsockopt system call.

Reimplemented in ACE_SSL_SOCK.

Definition at line 29 of file SOCK.inl.

{
  ACE_TRACE ("ACE_SOCK::get_option");
  return ACE_OS::getsockopt (this->get_handle (), level,
                             option, (char *) optval, optlen);
}

int ACE_SOCK::get_remote_addr ( ACE_Addr sa  )  const

Return the address of the remotely connected peer (if there is one), in the referenced ACE_Addr. Returns 0 if successful, else -1.

Reimplemented in ACE_SOCK_Acceptor, ACE_SOCK_Dgram, ACE_SOCK_Dgram_Bcast, ACE_SOCK_SEQPACK_Acceptor, and ACE_SSL_SOCK_Stream.

Definition at line 33 of file SOCK.cpp.

{
  ACE_TRACE ("ACE_SOCK::get_remote_addr");

  int len = sa.get_size ();
  sockaddr *addr = reinterpret_cast<sockaddr *> (sa.get_addr ());

  if (ACE_OS::getpeername (this->get_handle (),
                           addr,
                           &len) == -1)
    return -1;

  sa.set_size (len);
  sa.set_type (addr->sa_family);
  return 0;
}

int ACE_SOCK::open ( int  type,
int  protocol_family,
int  protocol,
ACE_Protocol_Info protocolinfo,
ACE_SOCK_GROUP  g,
u_long  flags,
int  reuse_addr 
)

Wrapper around the QoS-enabled WSASocket function.

Definition at line 131 of file SOCK.cpp.

{
  ACE_TRACE ("ACE_SOCK::open");

  this->set_handle (ACE_OS::socket (protocol_family,
                                    type,
                                    protocol,
                                    protocolinfo,
                                    g,
                                    flags));
  int one = 1;

  if (this->get_handle () == ACE_INVALID_HANDLE)
    return -1;
  else if (reuse_addr
           && this->set_option (SOL_SOCKET,
                                SO_REUSEADDR,
                                &one,
                                sizeof one) == -1)
    {
      this->close ();
      return -1;
    }
  else
    return 0;
}

int ACE_SOCK::open ( int  type,
int  protocol_family,
int  protocol,
int  reuse_addr 
)

Wrapper around the BSD-style socket system call (no QoS).

Definition at line 85 of file SOCK.cpp.

{
  ACE_TRACE ("ACE_SOCK::open");
  int one = 1;

  this->set_handle (ACE_OS::socket (protocol_family,
                                    type,
                                    protocol));

  if (this->get_handle () == ACE_INVALID_HANDLE)
    return -1;
  else if (protocol_family != PF_UNIX
           && reuse_addr
           && this->set_option (SOL_SOCKET,
                                SO_REUSEADDR,
                                &one,
                                sizeof one) == -1)
    {
      this->close ();
      return -1;
    }
  return 0;
}

int ACE_SOCK::set_option ( int  level,
int  option,
void *  optval,
int  optlen 
) const

Wrapper around the setsockopt system call.

Reimplemented in ACE_SSL_SOCK.

Definition at line 16 of file SOCK.inl.

{
  ACE_TRACE ("ACE_SOCK::set_option");
  return ACE_OS::setsockopt (this->get_handle (), level,
                             option, (char *) optval, optlen);
}


Member Data Documentation


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