#include <ATM_Stream.h>
Public Types | |
typedef ACE_ATM_Addr | PEER_ADDR |
Public Member Functions | |
ACE_ATM_Stream (void) | |
Default constructor. | |
int | open (ACE_ATM_Params params=ACE_ATM_Params()) |
open the stream. | |
int | close (void) |
Close down and release resources. | |
ACE_HANDLE | get_handle (void) const |
Get the underlying handle. | |
ATM_Stream & | get_stream (void) |
Get the underlying stream. | |
char * | get_peer_name (void) const |
Get the name of the connected host. | |
int | get_vpi_vci (ACE_UINT16 &vpi, ACE_UINT16 &vci) const |
Get the VPI and VCI of the stream. | |
ssize_t | recv (void *buf, size_t n, int *flags=0) const |
Recv an n byte buffer from the connected transport mechanism. | |
ssize_t | send_n (const void *buf, size_t n, int flags) const |
Send exactly n bytes to the connected transport mechanism. | |
void | dump (void) const |
Dump the state of an object. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Private Attributes | |
ATM_Stream | stream_ |
Typedef'd to the appropriate stream mechanism above. |
Definition at line 48 of file ATM_Stream.h.
|
Definition at line 86 of file ATM_Stream.h. |
|
Default constructor.
Definition at line 16 of file ATM_Stream.inl. References ACE_TRACE.
00017 { 00018 ACE_TRACE ("ACE_ATM_Stream::ACE_ATM_Stream"); 00019 } |
|
Close down and release resources.
Definition at line 70 of file ATM_Stream.inl. References ACE_TRACE, and stream_.
|
|
Dump the state of an object.
Definition at line 8 of file ATM_Stream.inl. References ACE_TRACE.
00009 { 00010 #if defined (ACE_HAS_DUMP) 00011 ACE_TRACE ("ACE_ATM_Stream::dump"); 00012 #endif /* ACE_HAS_DUMP */ 00013 } |
|
Get the underlying handle.
Definition at line 132 of file ATM_Stream.cpp. References ACE_TRACE, and stream_. Referenced by ACE_ATM_Connector::add_leaf(), ACE_ATM_Connector::connect(), get_vpi_vci(), and open().
00133 { 00134 ACE_TRACE ("ACE_ATM_Stream::get_handle"); 00135 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2) || defined (ACE_HAS_LINUX_ATM) 00136 return stream_.get_handle (); 00137 #else 00138 return 0; 00139 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */ 00140 } |
|
Get the name of the connected host.
Definition at line 18 of file ATM_Stream.cpp. References ACE_DEBUG, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_TCHAR, ACE_TRACE, ATM_Addr, ACE_ATM_Addr::get_addr(), ACE_Addr::get_size(), ACE_OS::getpeername(), LM_DEBUG, ACE_OS::memset(), ACE_OS::perror(), ACE_OS::strcpy(), ACE_OS::strlen(), ACE_OS::strstr(), ACE_OS::strtok_r(), and ACE_OS::t_getname().
00019 { 00020 ACE_TRACE ("ACE_ATM_Stream::get_peer_name"); 00021 #if defined (ACE_HAS_FORE_ATM_XTI) 00022 // // Use t_getprotaddr for XTI/ATM 00023 // struct t_bind *localaddr 00024 // = (struct t_bind *) ACE_OS::t_alloc (get_handle (), 00025 // T_BIND, 00026 // T_ADDR); 00027 // struct t_bind *peeraddr 00028 // = (struct t_bind *) ACE_OS::t_alloc (get_handle (), 00029 // T_BIND, 00030 // T_ADDR); 00031 // ::t_getprotaddr (get_handle (), 00032 // localaddr, 00033 // peeraddr); 00034 00035 // char* connected_name = (char*) ACE_OS::malloc (peeraddr->addr.len + 1); 00036 // ACE_OS::strcpy (connected_name, 00037 // peeraddr->addr.buf); 00038 // ACE_OS::t_free ((char *) localaddr, 00039 // T_BIND); 00040 // ACE_OS::t_free ((char *) peeraddr, 00041 // T_BIND); 00042 // return (connected_name); 00043 00044 #error "This doesn't seem to work. May need to jimmy-rig something with the" 00045 #error "/etc/xti_hosts file - Ugh!" 00046 00047 ACE_ATM_Addr sa; 00048 struct netbuf name; 00049 name.maxlen = sa.get_size (); 00050 name.buf = (char *) sa.get_addr (); 00051 ACE_OS::t_getname (this->get_handle (), &name, REMOTENAME); 00052 // ACE_OS::ioctl (this->get_handle (), 00053 // TI_GETPEERNAME, 00054 // &name); 00055 return (name.buf); 00056 00057 #elif defined (ACE_HAS_FORE_ATM_WS2) 00058 // Use getpeername for WinSock2. 00059 struct sockaddr_atm name; 00060 ACE_OS::memset (&name, 0, sizeof (name)); 00061 int nameSize = sizeof (name); 00062 00063 if (ACE_OS::getpeername (this->get_handle (), 00064 (struct sockaddr *) &name, 00065 &nameSize) != 0) { 00066 return 0; 00067 } 00068 00069 char buffer[256]; 00070 for (unsigned int index = 0; index < ATM_ADDR_SIZE - 1; index++) { 00071 buffer[ index * 3 ] = '\0'; 00072 sprintf (buffer, "%s%02x.", buffer, name.satm_number.Addr[ index ]); 00073 } 00074 buffer[ (ATM_ADDR_SIZE - 1) * 3 ] = '\0'; 00075 sprintf (buffer, "%s%02x.", buffer, 0); 00076 buffer[ ATM_ADDR_SIZE * 3 - 1 ] = '\0'; 00077 for (index = 0; index < ACE_OS::strlen (buffer); ++index) 00078 buffer[index] = tolower (buffer[index]); 00079 00080 ifstream atm_hosts ("C:/WINNT/atmhosts"); 00081 assert (atm_hosts.is_open ()); 00082 00083 // Find the host address in the ATM hosts file and return the 00084 // host name 00085 char line[256]; 00086 char *host_ptr, *host_name = 0; 00087 ACE_NEW_RETURN (host_name, char[256], 0); 00088 while (!atm_hosts.eof ()) { 00089 atm_hosts.getline (line, 256); 00090 // Convert the line to lower case to ease comparison 00091 for (index = 0; index < ACE_OS::strlen (line); ++index) 00092 line[index] = tolower (line[index]); 00093 if (ACE_OS::strstr (line, buffer) != 0) 00094 { 00095 char *strtok_p; 00096 // Grab the second token which is the host name 00097 ACE_OS::strtok_r (line, " \t", &strtok_p); 00098 host_ptr = strtok (0, " \t", &strtok_p); 00099 ACE_OS::strcpy (host_name, host_ptr); 00100 break; 00101 } 00102 } 00103 00104 return host_name; 00105 #elif defined (ACE_HAS_LINUX_ATM) 00106 ATM_Addr name; 00107 int nameSize = sizeof (name.sockaddratmsvc); 00108 00109 if (ACE_OS::getpeername (this->get_handle (), 00110 (struct sockaddr *) & (name.sockaddratmsvc), 00111 &nameSize) < 0) { 00112 ACE_OS::perror ("ACE_ATM_Stream (get_peer_name) : "); 00113 return 0; 00114 } 00115 00116 static ACE_TCHAR buffer[MAX_ATM_ADDR_LEN + 1]; 00117 int total_len; 00118 if ((total_len = atm2text (buffer,sizeof buffer, 00119 (struct sockaddr *) & (name.sockaddratmsvc), 00120 A2T_PRETTY|A2T_NAME)) < 0) { 00121 ACE_DEBUG ((LM_DEBUG,ACE_LIB_TEXT ("ACE_ATM_Stream (get_peer_name) :%d"),errno)); 00122 return 0; 00123 } 00124 00125 return (char*) buffer; 00126 #else 00127 return 0; 00128 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */ 00129 } |
|
Get the underlying stream.
Definition at line 82 of file ATM_Stream.inl. References ACE_TRACE, and stream_. Referenced by ACE_ATM_Acceptor::accept(), ACE_ATM_Connector::add_leaf(), ACE_ATM_Connector::complete(), and ACE_ATM_Connector::connect().
|
|
Get the VPI and VCI of the stream.
Definition at line 143 of file ATM_Stream.cpp. References ACE_DEBUG, ACE_LIB_TEXT, ACE_TRACE, ACE_OS::fprintf(), ACE_OS::free(), get_handle(), ACE_OS::getsockopt(), LM_DEBUG, ACE_OS::malloc(), ACE_OS::memcpy(), ACE_OS::memset(), ACE_OS::printf(), stream_, ACE_OS::t_error(), ACE_OS::t_getinfo(), ACE_OS::t_optmgmt(), and t_optmgmt().
00145 { 00146 ACE_TRACE ("ACE_ATM_Stream::get_vpi_vci"); 00147 #if defined (ACE_HAS_FORE_ATM_XTI) 00148 struct t_atm_conn_prop conn_prop; 00149 char* connect_opts = (char *) &conn_prop; 00150 int opt_size = sizeof (t_atm_conn_prop); 00151 struct t_info info; 00152 struct t_optmgmt opt_req, opt_ret; 00153 00154 if (ACE_OS::t_getinfo (stream_.get_handle (), 00155 &info) < 0) 00156 { 00157 ACE_OS::t_error ("t_getinfo"); 00158 return -1; 00159 } 00160 00161 char *buf_req = (char *) ACE_OS::malloc (info.options); 00162 if (buf_req == 0) 00163 { 00164 ACE_OS::fprintf (stderr, 00165 "Unable to allocate %ld bytes for options\n", 00166 info.options); 00167 return -1; 00168 } 00169 00170 char *buf_ret = (char *) ACE_OS::malloc (info.options); 00171 if (buf_ret == 0) 00172 { 00173 ACE_OS::fprintf (stderr, 00174 "Unable to allocate %ld bytes for options\n", 00175 info.options); 00176 return -1; 00177 } 00178 00179 ACE_OS::memset (&opt_req, 0, sizeof (opt_req)); 00180 ACE_OS::memset (&opt_ret, 0, sizeof (opt_ret)); 00181 00182 struct t_opthdr *popt = (struct t_opthdr *) buf_req; 00183 struct t_opthdr *popt_ret = (struct t_opthdr *) buf_ret; 00184 00185 popt->len= sizeof (struct t_opthdr) + opt_size; 00186 00187 // We are only concerned with SVCs so no other check or values are needed 00188 // here. 00189 popt->level = T_ATM_SIGNALING; 00190 popt->name = T_ATM_CONN_PROP; 00191 popt->status = 0; 00192 00193 opt_req.opt.len = popt->len; 00194 opt_req.opt.buf = (char *) popt; 00195 opt_req.flags = T_CURRENT; 00196 00197 popt = T_OPT_NEXTHDR (buf_req, 00198 info.options, 00199 popt); 00200 opt_ret.opt.maxlen = info.options; 00201 opt_ret.opt.buf = (char *) popt_ret; 00202 00203 if (ACE_OS::t_optmgmt (stream_.get_handle (), 00204 &opt_req, 00205 &opt_ret) < 0) { 00206 ACE_OS::t_error ("t_optmgmt"); 00207 return -1; 00208 } 00209 00210 ACE_OS::memcpy (connect_opts, 00211 (char *) popt_ret + sizeof (struct t_opthdr), 00212 opt_size); 00213 00214 ACE_OS::free (buf_ret); 00215 ACE_OS::free (buf_req); 00216 00217 vpi = conn_prop.vpi; 00218 vci = conn_prop.vci; 00219 return (0); 00220 #elif defined (ACE_HAS_FORE_ATM_WS2) 00221 ATM_CONNECTION_ID connID; 00222 DWORD bytes = 0; 00223 00224 if (::WSAIoctl ((int) this -> get_handle (), 00225 SIO_GET_ATM_CONNECTION_ID, 00226 0, 00227 0, 00228 (LPVOID) &connID, 00229 sizeof (ATM_CONNECTION_ID), 00230 &bytes, 00231 0, 00232 0) 00233 == SOCKET_ERROR) { 00234 ACE_OS::printf ("Error: WSAIoctl %d\n", WSAGetLastError ()); 00235 } 00236 00237 vpi = (ACE_UINT16) connID.VPI; 00238 vci = (ACE_UINT16) connID.VCI; 00239 00240 return 0; 00241 #elif defined (ACE_HAS_LINUX_ATM) 00242 #if defined (SO_ATMPVC) /* atm version>=0.62 */ 00243 struct sockaddr_atmpvc mypvcaddr; 00244 int addrpvclen = sizeof (mypvcaddr); 00245 if (ACE_OS::getsockopt (stream_.get_handle (), 00246 SOL_ATM, 00247 SO_ATMPVC, 00248 reinterpret_cast<char*> (&mypvcaddr), 00249 &addrpvclen) < 0) { 00250 ACE_DEBUG (LM_DEBUG, 00251 ACE_LIB_TEXT ("ACE_ATM_Stream::get_vpi_vci: getsockopt %d\n"), 00252 errno); 00253 return -1; 00254 } 00255 vpi = (ACE_UINT16) mypvcaddr.sap_addr.vpi; 00256 vci = (ACE_UINT16) mypvcaddr.sap_addr.vci; 00257 00258 return 0; 00259 #elif defined (SO_VCID) /* patch for atm version 0.59 */ 00260 struct atm_vcid mypvcid; 00261 int pvcidlen = sizeof (mypvcid); 00262 if (ACE_OS::getsockopt (stream_.get_handle (), 00263 SOL_ATM,SO_VCID, 00264 reinterpret_cast<char*> (&mypvcid), 00265 &pvcidlen) < 0) { 00266 ACE_DEBUG (LM_DEBUG, 00267 ACE_LIB_TEXT ("ACE_ATM_Stream::get_vpi_vci: getsockopt %d\n"), 00268 errno); 00269 return -1; 00270 } 00271 vpi = (ACE_UINT16) mypvcid.vpi; 00272 vci = (ACE_UINT16) mypvcid.vci; 00273 00274 return 0; 00275 #else 00276 ACE_DEBUG (LM_DEBUG, 00277 ACE_LIB_TEXT ("ACE_ATM_Stream::get_vpi_vci: Not implemented in this ATM version. Update to >= 0.62\n Or patch 0.59")); 00278 ACE_UNUSED_ARG (vci); 00279 ACE_UNUSED_ARG (vpi); 00280 00281 return (-1); 00282 #endif /* SO_ATMPVC || SO_VCID */ 00283 #else 00284 return (-1); 00285 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */ 00286 } |
|
open the stream.
Definition at line 23 of file ATM_Stream.inl. References ACE_FLAG_MULTIPOINT_C_ROOT, ACE_FLAG_MULTIPOINT_D_ROOT, ACE_TRACE, ACE_OS::bind(), ACE_ATM_Params::get_device(), ACE_ATM_Params::get_flags(), get_handle(), ACE_ATM_Params::get_info(), ACE_ATM_Params::get_oflag(), ACE_ATM_Params::get_protocol(), ACE_ATM_Params::get_protocol_family(), ACE_ATM_Params::get_protocol_info(), ACE_ATM_Params::get_reuse_addr(), ACE_ATM_Params::get_sock_group(), ACE_ATM_Params::get_type(), ACE_OS::memset(), ACE_OS::printf(), ACE_ATM_Params::set_flags(), and stream_.
00024 { 00025 ACE_TRACE ("ACE_ATM_Stream::open"); 00026 #if defined (ACE_HAS_FORE_ATM_XTI) 00027 ACE_HANDLE handle = stream_.open (params.get_device(), 00028 params.get_oflag(), 00029 params.get_info()); 00030 return (handle == ACE_INVALID_HANDLE ? -1 : 0); 00031 #elif defined (ACE_HAS_FORE_ATM_WS2) 00032 params.set_flags( ACE_FLAG_MULTIPOINT_C_ROOT | ACE_FLAG_MULTIPOINT_D_ROOT ); 00033 00034 int retval = stream_.open (params.get_type(), 00035 params.get_protocol_family(), 00036 params.get_protocol(), 00037 params.get_protocol_info(), 00038 params.get_sock_group(), 00039 params.get_flags(), 00040 params.get_reuse_addr()); 00041 if (retval == -1) 00042 return -1; 00043 00044 struct sockaddr_atm sock_addr; 00045 00046 ACE_OS::memset(&sock_addr, 0, sizeof(struct sockaddr_atm)); 00047 sock_addr.satm_family = AF_ATM; 00048 sock_addr.satm_number.AddressType=ADDR_ANY; 00049 sock_addr.satm_number.NumofDigits = ATM_ADDR_SIZE; 00050 sock_addr.satm_blli.Layer2Protocol = SAP_FIELD_ABSENT; 00051 sock_addr.satm_blli.Layer3Protocol = SAP_FIELD_ABSENT; 00052 sock_addr.satm_bhli.HighLayerInfoType = SAP_FIELD_ABSENT; 00053 if (ACE_OS::bind(get_handle(), 00054 (struct sockaddr FAR *)&sock_addr, 00055 sizeof(struct sockaddr_atm)) < 0) 00056 { 00057 ACE_OS::printf("Error binding local address: %d",WSAGetLastError()); 00058 return -1; 00059 } 00060 00061 return 0; 00062 #else 00063 ACE_UNUSED_ARG(params); 00064 return 0; 00065 #endif /* ACE_HAS_FORE_ATM_XTI */ 00066 } |
|
Recv an n byte buffer from the connected transport mechanism.
Definition at line 90 of file ATM_Stream.inl. References ACE_TRACE, and stream_.
00093 { 00094 ACE_TRACE ("ACE_ATM_Stream::recv"); 00095 #if defined (ACE_HAS_FORE_ATM_XTI) 00096 return stream_.recv (buf, 00097 n, 00098 flags); 00099 #elif defined (ACE_HAS_FORE_ATM_WS2) 00100 return stream_.recv (buf, 00101 n); 00102 #else 00103 ACE_UNUSED_ARG(buf); 00104 ACE_UNUSED_ARG(n); 00105 ACE_UNUSED_ARG(flags); 00106 return (0); 00107 #endif /* ACE_HAS_FORE_ATM_XTI */ 00108 } |
|
Send exactly n bytes to the connected transport mechanism.
Definition at line 112 of file ATM_Stream.inl. References ACE_TRACE, and stream_.
00115 { 00116 ACE_TRACE ("ACE_ATM_Stream::send_n"); 00117 #if defined (ACE_HAS_FORE_ATM_XTI) 00118 return stream_.send_n (buf, 00119 n, 00120 flags); 00121 #elif defined (ACE_HAS_FORE_ATM_WS2) 00122 return stream_.send_n (buf, 00123 n, 00124 flags); 00125 #else 00126 ACE_UNUSED_ARG(buf); 00127 ACE_UNUSED_ARG(n); 00128 ACE_UNUSED_ARG(flags); 00129 return (0); 00130 #endif /* ACE_HAS_FORE_ATM_XTI */ 00131 } |
|
Declare the dynamic allocation hooks.
Definition at line 92 of file ATM_Stream.h. |
|
Typedef'd to the appropriate stream mechanism above.
Definition at line 96 of file ATM_Stream.h. Referenced by close(), get_handle(), get_stream(), get_vpi_vci(), open(), recv(), and send_n(). |