Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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 Methods

 ~ACE_SOCK (void)
 Default ctor/dtor. More...

int set_option (int level, int option, void *optval, int optlen) const
 Wrapper around the <setsockopt> system call. More...

int get_option (int level, int option, void *optval, int *optlen) const
 Wrapper around the <getsockopt> system call. More...

int close (void)
 Close down the socket handle. More...

int get_local_addr (ACE_Addr &) const
 Return the local endpoint address in the referenced <ACE_Addr>. Returns 0 if successful, else -1. More...

int get_remote_addr (ACE_Addr &) const
void dump (void) const
 Dump the state of an object. More...

int open (int type, int protocol_family, int protocol, int reuse_addr)
 Wrapper around the BSD-style <socket> system call (no QoS). More...

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. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Protected Methods

 ACE_SOCK (int type, int protocol_family, int protocol=0, int reuse_addr=0)
 Constructor with arguments to call the BSD-style <socket> system call (no QoS). More...

 ACE_SOCK (int type, int protocol_family, int protocol, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g, u_long flags, int reuse_addr)
 Constructor with arguments to call the QoS-enabled <WSASocket> function. More...

 ACE_SOCK (void)
 Default constructor is protected to prevent instances of this class from being defined. More...


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 39 of file SOCK.h.


Constructor & Destructor Documentation

ASYS_INLINE ACE_SOCK::~ACE_SOCK void   
 

Default ctor/dtor.

Definition at line 7 of file SOCK.i.

00008 {
00009   // ACE_TRACE ("ACE_SOCK::~ACE_SOCK");
00010 }

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.

References ACE_ERROR, ACE_LIB_TEXT, LM_ERROR, and open.

00119 {
00120   // ACE_TRACE ("ACE_SOCK::ACE_SOCK");
00121   if (this->open (type,
00122                   protocol_family, 
00123                   protocol,
00124                   reuse_addr) == -1)
00125     ACE_ERROR ((LM_ERROR,
00126                 ACE_LIB_TEXT ("%p\n"),
00127                 ACE_LIB_TEXT ("ACE_SOCK::ACE_SOCK")));
00128 }

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.

References ACE_ERROR, ACE_LIB_TEXT, ACE_SOCK_GROUP, LM_ERROR, and open.

00171 {
00172   // ACE_TRACE ("ACE_SOCK::ACE_SOCK");
00173   if (this->open (type,
00174                   protocol_family,
00175                   protocol,
00176                   protocolinfo,
00177                   g,
00178                   flags,
00179                   reuse_addr) == -1)
00180     ACE_ERROR ((LM_ERROR,
00181                 ACE_LIB_TEXT ("%p\n"),
00182                 ACE_LIB_TEXT ("ACE_SOCK::ACE_SOCK")));
00183 }

ACE_SOCK::ACE_SOCK void    [protected]
 

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

Definition at line 22 of file SOCK.cpp.

00023 {
00024   // ACE_TRACE ("ACE_SOCK::ACE_SOCK");
00025 }


Member Function Documentation

int ACE_SOCK::close void   
 

Close down the socket handle.

Reimplemented in ACE_MEM_Stream.

Definition at line 71 of file SOCK.cpp.

References ACE_TRACE, ACE_OS::closesocket, ACE_IPC_SAP::get_handle, and ACE_IPC_SAP::set_handle.

Referenced by ACE_SOCK_Stream::close, ACE_SOCK_Dgram_Bcast::close, ACE_SOCK_Acceptor::close, ACE_MEM_Stream::close, ACE_SOCK_CODgram::open, open, and ACE_SOCK_Dgram::shared_open.

00072 {
00073   ACE_TRACE ("ACE_SOCK::close");
00074   int result = 0;
00075 
00076   if (this->get_handle () != ACE_INVALID_HANDLE)
00077     {
00078       result = ACE_OS::closesocket (this->get_handle ());
00079       this->set_handle (ACE_INVALID_HANDLE);
00080     }
00081   return result;
00082 }

void ACE_SOCK::dump void    const
 

Dump the state of an object.

Reimplemented from ACE_IPC_SAP.

Reimplemented in ACE_LSOCK_Acceptor.

Definition at line 17 of file SOCK.cpp.

References ACE_TRACE.

00018 {
00019   ACE_TRACE ("ACE_SOCK::dump");
00020 }

int ACE_SOCK::get_local_addr ACE_Addr   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 50 of file SOCK.cpp.

References ACE_TRACE, ACE_Addr::get_addr, ACE_Addr::get_size, ACE_OS::getsockname, ACE_Addr::set_size, and ACE_Addr::set_type.

Referenced by ACE_MEM_Acceptor::accept, ACE_MEM_Connector::connect, ACE_MEM_Acceptor::get_local_addr, ACE_LSOCK_Stream::get_local_addr, ACE_Service_Manager::info, ACE_Pipe::open, ACE_SOCK_Dgram_Mcast::open_i, and ACE_Asynch_Acceptor::parse_address.

00051 {
00052   ACE_TRACE ("ACE_SOCK::get_local_addr");
00053 
00054   int len = sa.get_size ();
00055   sockaddr *addr = ACE_reinterpret_cast (sockaddr *,
00056                                          sa.get_addr ());
00057 
00058   if (ACE_OS::getsockname (this->get_handle (),
00059                            addr,
00060                            &len) == -1)
00061     return -1;
00062 
00063   sa.set_type (addr->sa_family);
00064   sa.set_size (len);
00065   return 0;
00066 }

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

Wrapper around the <getsockopt> system call.

Definition at line 26 of file SOCK.i.

References ACE_TRACE, and ACE_OS::getsockopt.

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

int ACE_SOCK::get_remote_addr ACE_Addr   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_LSOCK_Stream.

Definition at line 31 of file SOCK.cpp.

References ACE_TRACE, ACE_Addr::get_addr, ACE_Addr::get_size, ACE_OS::getpeername, ACE_Addr::set_size, and ACE_Addr::set_type.

Referenced by ACE_Service_Manager::handle_input, and ACE_Asynch_Acceptor::parse_address.

00032 {
00033   ACE_TRACE ("ACE_SOCK::get_remote_addr");
00034 
00035   int len = sa.get_size ();
00036   sockaddr *addr = ACE_reinterpret_cast (sockaddr *,
00037                                          sa.get_addr ());
00038 
00039   if (ACE_OS::getpeername (this->get_handle (),
00040                            addr,
00041                            &len) == -1)
00042     return -1;
00043   
00044   sa.set_size (len);
00045   sa.set_type (addr->sa_family);
00046   return 0;
00047 }

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.

References ACE_SOCK_GROUP, ACE_TRACE, close, ACE_IPC_SAP::get_handle, ACE_IPC_SAP::set_handle, set_option, and ACE_OS::socket.

00138 {
00139   ACE_TRACE ("ACE_SOCK::open");
00140 
00141   this->set_handle (ACE_OS::socket (protocol_family,
00142                                     type,
00143                                     protocol,
00144                                     protocolinfo,
00145                                     g,
00146                                     flags));
00147   int one = 1;
00148 
00149   if (this->get_handle () == ACE_INVALID_HANDLE)
00150     return -1;
00151   else if (reuse_addr 
00152            && this->set_option (SOL_SOCKET,
00153                                 SO_REUSEADDR,
00154                                 &one,
00155                                 sizeof one) == -1)
00156     {
00157       this->close ();
00158       return -1;
00159     }
00160   else
00161     return 0;
00162 }

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.

References ACE_TRACE, close, ACE_IPC_SAP::get_handle, ACE_IPC_SAP::set_handle, set_option, and ACE_OS::socket.

Referenced by ACE_SOCK, ACE_SOCK_Dgram_Mcast::open, ACE_SOCK_Dgram::open, ACE_SOCK_CODgram::open, ACE_SOCK_Acceptor::open, ACE_ATM_Stream::open, and ACE_SOCK_Connector::shared_open.

00089 {
00090   ACE_TRACE ("ACE_SOCK::open");
00091   int one = 1;
00092 
00093   this->set_handle (ACE_OS::socket (protocol_family,
00094                                     type,
00095                                     protocol));
00096 
00097   if (this->get_handle () == ACE_INVALID_HANDLE)
00098     return -1;
00099   else if (protocol_family != PF_UNIX 
00100            && reuse_addr 
00101            && this->set_option (SOL_SOCKET,
00102                                 SO_REUSEADDR,
00103                                 &one,
00104                                 sizeof one) == -1)
00105     {
00106       this->close ();
00107       return -1;
00108     }
00109   return 0;
00110 }

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

Wrapper around the <setsockopt> system call.

Definition at line 13 of file SOCK.i.

References ACE_TRACE, and ACE_OS::setsockopt.

Referenced by open, ACE_Pipe::open, ACE_SOCK_Dgram_Mcast::open_i, ACE_SOCK_Dgram::set_nic, ACE_SOCK_Dgram_Mcast::set_option, ACE_SOCK_Dgram_Mcast::subscribe_i, and ACE_SOCK_Dgram_Mcast::unsubscribe_i.

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


Member Data Documentation

ACE_SOCK::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented from ACE_IPC_SAP.

Reimplemented in ACE_LSOCK_Acceptor.

Definition at line 75 of file SOCK.h.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:56:15 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002