#include <SOCK_CODgram.h>
Inheritance diagram for ACE_SOCK_CODgram:
Public Types | |
typedef ACE_INET_Addr | PEER_ADDR |
Public Member Functions | |
ACE_SOCK_CODgram (void) | |
Default constructor. | |
ACE_SOCK_CODgram (const ACE_Addr &remote_sap, const ACE_Addr &local_sap=ACE_Addr::sap_any, int protocol_family=ACE_PROTOCOL_FAMILY_INET, int protocol=0, int reuse_addr=0) | |
~ACE_SOCK_CODgram (void) | |
Default dtor. | |
int | open (const ACE_Addr &remote_sap, const ACE_Addr &local_sap=ACE_Addr::sap_any, int protocol_family=ACE_PROTOCOL_FAMILY_INET, int protocol=0, int reuse_addr=0) |
void | dump (void) const |
Dump the state of an object. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. |
Definition at line 36 of file SOCK_CODgram.h.
Definition at line 127 of file SOCK_CODgram.h.
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ACE_SOCK_CODgram::ACE_SOCK_CODgram | ( | void | ) |
Default constructor.
Definition at line 8 of file SOCK_CODgram.inl.
References ACE_TRACE.
00009 { 00010 ACE_TRACE ("ACE_SOCK_CODgram::ACE_SOCK_CODgram"); 00011 }
ACE_SOCK_CODgram::ACE_SOCK_CODgram | ( | const ACE_Addr & | remote_sap, | |
const ACE_Addr & | local_sap = ACE_Addr::sap_any , |
|||
int | protocol_family = ACE_PROTOCOL_FAMILY_INET , |
|||
int | protocol = 0 , |
|||
int | reuse_addr = 0 | |||
) |
Constructor with addresses specified. Calls open(). This constructor binds and/or connects to a specified address, optionally binding an unused port number.
remote_sap | The remote address. | |
local_sap | The local address. | |
protocol_family | The protocol family for the new socket. If either remote_sap or local_sap is specified (i.e., not ACE_Addr::sap_any) its address type is used instead of this value. If both addresses are specified, their address types must match. If neither address is specified, the platform's default IP address type is used. | |
protocol | Protocol value for the new socket. | |
reuse_addr | Reuse the local address or not. |
protocol_family
specifies PF_INET or PF_INET6, bind the local address to a randomly generated port number.Definition at line 27 of file SOCK_CODgram.cpp.
References ACE_ERROR, ACE_TEXT, ACE_TRACE, and LM_ERROR.
00032 { 00033 ACE_TRACE ("ACE_SOCK_CODgram::ACE_SOCK_CODgram"); 00034 if (this->open (remote, 00035 local, 00036 protocol_family, 00037 protocol, 00038 reuse_addr) == -1) 00039 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_SOCK_CODgram"))); 00040 }
ACE_INLINE ACE_SOCK_CODgram::~ACE_SOCK_CODgram | ( | void | ) |
Default dtor.
Definition at line 14 of file SOCK_CODgram.inl.
References ACE_TRACE.
00015 { 00016 ACE_TRACE ("ACE_SOCK_CODgram::~ACE_SOCK_CODgram"); 00017 }
ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_SOCK_CODgram::dump | ( | void | ) | const |
Dump the state of an object.
Reimplemented from ACE_SOCK_IO.
Reimplemented in ACE_LSOCK_CODgram.
Definition at line 18 of file SOCK_CODgram.cpp.
References ACE_TRACE.
Referenced by ACE_LSOCK_CODgram::dump().
00019 { 00020 #if defined (ACE_HAS_DUMP) 00021 ACE_TRACE ("ACE_SOCK_CODgram::dump"); 00022 #endif /* ACE_HAS_DUMP */ 00023 }
int ACE_SOCK_CODgram::open | ( | const ACE_Addr & | remote_sap, | |
const ACE_Addr & | local_sap = ACE_Addr::sap_any , |
|||
int | protocol_family = ACE_PROTOCOL_FAMILY_INET , |
|||
int | protocol = 0 , |
|||
int | reuse_addr = 0 | |||
) |
Initiate a connected datagram socket, optionally binding an unused port number.
remote_sap | The remote address. | |
local_sap | The local address. | |
protocol_family | The protocol family for the new socket. If either remote_sap or local_sap is specified (i.e., not ACE_Addr::sap_any) its address type is used instead of this value. If both addresses are specified, their address types must match. If neither address is specified, the platform's default IP address type is used. | |
protocol | Protocol value for the new socket. | |
reuse_addr | Reuse the local address or not. |
protocol_family
specifies PF_INET or PF_INET6, bind the local address to a randomly generated port number.Definition at line 64 of file SOCK_CODgram.cpp.
References ACE_TRACE, ACE_OS::bind(), ACE::bind_port(), ACE_SOCK::close(), ACE_OS::connect(), ACE_Addr::get_addr(), ACE_Addr::get_size(), ACE_Addr::get_type(), ACE_SOCK::open(), PF_INET, ACE_Addr::sap_any, ACE_IPC_SAP::set_handle(), and SOCK_DGRAM.
Referenced by ACE_LSOCK_CODgram::open().
00067 { 00068 ACE_TRACE ("ACE_SOCK_CODgram::open"); 00069 // Depending on the addresses passed as described above, figure out what 00070 // address family to specify for the new socket. If either address is 00071 // !ACE_Addr::sap_any, use that family. If they don't match, it's an error. 00072 if (remote != ACE_Addr::sap_any) 00073 { 00074 if (local == ACE_Addr::sap_any) 00075 protocol_family = remote.get_type (); 00076 else 00077 { // Both specified; family must match 00078 if (local.get_type () != remote.get_type ()) 00079 { 00080 errno = EAFNOSUPPORT; 00081 return -1; 00082 } 00083 protocol_family = remote.get_type (); 00084 } 00085 } 00086 else 00087 { 00088 if (local != ACE_Addr::sap_any) 00089 protocol_family = local.get_type (); 00090 } 00091 if (ACE_SOCK::open (SOCK_DGRAM, 00092 protocol_family, 00093 protocol, 00094 reuse_addr) == -1) 00095 return -1; 00096 else 00097 { 00098 int error = 0; 00099 00100 if (local == ACE_Addr::sap_any && remote == ACE_Addr::sap_any) 00101 { 00102 // Assign an arbitrary port number from the transient range!! 00103 if (protocol_family == PF_INET 00104 #if defined (ACE_HAS_IPV6) 00105 || protocol_family == PF_INET6 00106 #endif /* ACE_HAS_IPV6 */ 00107 && ACE::bind_port (this->get_handle ()) == -1) 00108 error = 1; 00109 } 00110 // We are binding just the local address. 00111 else if (local != ACE_Addr::sap_any && remote == ACE_Addr::sap_any) 00112 { 00113 if (ACE_OS::bind (this->get_handle (), 00114 (sockaddr *) local.get_addr (), 00115 local.get_size ()) == -1) 00116 error = 1; 00117 } 00118 // We are connecting to the remote address. 00119 else if (local == ACE_Addr::sap_any && remote != ACE_Addr::sap_any) 00120 { 00121 if (ACE_OS::connect (this->get_handle (), 00122 (sockaddr *) remote.get_addr (), 00123 remote.get_size ()) == -1) 00124 error = 1; 00125 } 00126 // We are binding to the local address and connecting to the 00127 // remote addresses. 00128 else 00129 { 00130 if (ACE_OS::bind (this->get_handle (), 00131 (sockaddr *) local.get_addr (), 00132 local.get_size ()) == -1 00133 || ACE_OS::connect (this->get_handle (), 00134 (sockaddr *) remote.get_addr (), 00135 remote.get_size ()) == -1) 00136 error = 1; 00137 } 00138 if (error) 00139 { 00140 this->close (); 00141 this->set_handle (ACE_INVALID_HANDLE); 00142 } 00143 return error ? -1 : 0; 00144 } 00145 }
Declare the dynamic allocation hooks.
Reimplemented from ACE_SOCK_IO.
Reimplemented in ACE_LSOCK_CODgram.
Definition at line 133 of file SOCK_CODgram.h.