Defines the member functions for the ACE_SOCK connected datagram abstraction. More...
#include <SOCK_CODgram.h>


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. | |
Defines the member functions for the ACE_SOCK connected datagram abstraction.
Definition at line 36 of file SOCK_CODgram.h.
Definition at line 127 of file SOCK_CODgram.h.
| ACE_SOCK_CODgram::ACE_SOCK_CODgram | ( | void | ) |
Default constructor.
Definition at line 8 of file SOCK_CODgram.inl.
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. |
There are four possible combinations of remote_sap and local_sap. The behavior in these combinations is:
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.
| ACE_SOCK_CODgram::~ACE_SOCK_CODgram | ( | void | ) |
Default dtor.
Definition at line 14 of file SOCK_CODgram.inl.
00015 { 00016 ACE_TRACE ("ACE_SOCK_CODgram::~ACE_SOCK_CODgram"); 00017 }
| 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.
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. |
There are four possible combinations of remote_sap and local_sap. The behavior in these combinations is:
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.
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 { 00090 protocol_family = local.get_type (); 00091 } 00092 } 00093 if (ACE_SOCK::open (SOCK_DGRAM, 00094 protocol_family, 00095 protocol, 00096 reuse_addr) == -1) 00097 { 00098 return -1; 00099 } 00100 else 00101 { 00102 bool error = false; 00103 00104 if (local == ACE_Addr::sap_any && remote == ACE_Addr::sap_any) 00105 { 00106 // Assign an arbitrary port number from the transient range!! 00107 if ((protocol_family == PF_INET 00108 #if defined (ACE_HAS_IPV6) 00109 || protocol_family == PF_INET6 00110 #endif /* ACE_HAS_IPV6 */ 00111 ) && ACE::bind_port (this->get_handle ()) == -1) 00112 error = true; 00113 } 00114 // We are binding just the local address. 00115 else if (local != ACE_Addr::sap_any && remote == ACE_Addr::sap_any) 00116 { 00117 if (ACE_OS::bind (this->get_handle (), 00118 (sockaddr *) local.get_addr (), 00119 local.get_size ()) == -1) 00120 error = true; 00121 } 00122 // We are connecting to the remote address. 00123 else if (local == ACE_Addr::sap_any && remote != ACE_Addr::sap_any) 00124 { 00125 if (ACE_OS::connect (this->get_handle (), 00126 (sockaddr *) remote.get_addr (), 00127 remote.get_size ()) == -1) 00128 error = true; 00129 } 00130 // We are binding to the local address and connecting to the 00131 // remote addresses. 00132 else 00133 { 00134 if (ACE_OS::bind (this->get_handle (), 00135 (sockaddr *) local.get_addr (), 00136 local.get_size ()) == -1 00137 || ACE_OS::connect (this->get_handle (), 00138 (sockaddr *) remote.get_addr (), 00139 remote.get_size ()) == -1) 00140 error = true; 00141 } 00142 if (error) 00143 { 00144 this->close (); 00145 this->set_handle (ACE_INVALID_HANDLE); 00146 } 00147 return error ? -1 : 0; 00148 } 00149 }
Declare the dynamic allocation hooks.
Reimplemented from ACE_SOCK_IO.
Reimplemented in ACE_LSOCK_CODgram.
Definition at line 133 of file SOCK_CODgram.h.
1.6.1