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

ACE_ATM_Stream Class Reference

Defines the member functions for ACE_ATM_Stream abstraction. More...

#include <ATM_Stream.h>

Collaboration diagram for ACE_ATM_Stream:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_ATM_Addr PEER_ADDR

Public Methods

 ACE_ATM_Stream (void)
 Default constructor. More...

int open (ACE_ATM_Params params=ACE_ATM_Params())
 open the stream. More...

int close (void)
 Close down and release resources. More...

ACE_HANDLE get_handle (void) const
 Get the underlying handle. More...

ATM_Streamget_stream (void)
 Get the underlying stream. More...

char * get_peer_name (void) const
 Get the name of the connected host. More...

int get_vpi_vci (ACE_UINT16 &vpi, ACE_UINT16 &vci) const
 Get the VPI and VCI of the stream. More...

ssize_t recv (void *buf, size_t n, int *flags=0) const
 Recv an n byte buffer from the connected transport mechanism. More...

ssize_t send_n (const void *buf, size_t n, int flags) const
 Send exactly n bytes to the connected transport mechanism. More...

void dump (void) const
 Dump the state of an object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Private Attributes

ATM_Stream stream_
 Typedef'd to the appropriate stream mechanism above. More...


Detailed Description

Defines the member functions for ACE_ATM_Stream abstraction.

Definition at line 42 of file ATM_Stream.h.


Member Typedef Documentation

typedef ACE_ATM_Addr ACE_ATM_Stream::PEER_ADDR
 

Definition at line 80 of file ATM_Stream.h.


Constructor & Destructor Documentation

ACE_INLINE ACE_ATM_Stream::ACE_ATM_Stream void   
 

Default constructor.

Definition at line 8 of file ATM_Stream.i.

References ACE_TRACE.

00009 {
00010   ACE_TRACE ("ACE_ATM_Stream::ACE_ATM_Stream");
00011 }


Member Function Documentation

ACE_INLINE int ACE_ATM_Stream::close void   
 

Close down and release resources.

Definition at line 62 of file ATM_Stream.i.

References ACE_TRACE, ACE_SOCK_Stream::close, and stream_.

00063 {
00064   ACE_TRACE ("ACE_ATM_Stream::close");
00065 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2)
00066   return stream_.close ();
00067 #else
00068   return 0;
00069 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 */
00070 }

void ACE_ATM_Stream::dump void    const
 

Dump the state of an object.

Definition at line 17 of file ATM_Stream.cpp.

References ACE_TRACE.

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

ACE_HANDLE ACE_ATM_Stream::get_handle void    const
 

Get the underlying handle.

Definition at line 137 of file ATM_Stream.cpp.

References ACE_TRACE, ACE_IPC_SAP::get_handle, and stream_.

Referenced by ACE_ATM_Connector::add_leaf, ACE_ATM_Connector::connect, get_vpi_vci, and open.

00138 {
00139   ACE_TRACE ("ACE_ATM_Stream::get_handle");
00140 #if defined (ACE_HAS_FORE_ATM_XTI) || defined (ACE_HAS_FORE_ATM_WS2) || defined (ACE_HAS_LINUX_ATM) 
00141   return stream_.get_handle ();
00142 #else
00143   return 0;
00144 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
00145 }

char * ACE_ATM_Stream::get_peer_name void    const
 

Get the name of the connected host.

Definition at line 23 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_String::memset, ACE_OS::perror, REMOTENAME, ACE_OS_String::strcpy, ACE_OS_String::strlen, ACE_OS_String::strstr, ACE_OS_String::strtok_r, and ACE_OS_TLI::t_getname.

00024 {
00025   ACE_TRACE ("ACE_ATM_Stream::get_peer_name");
00026 #if defined (ACE_HAS_FORE_ATM_XTI) 
00027   //   // Use t_getprotaddr for XTI/ATM
00028   //   struct t_bind *localaddr 
00029   //     = (struct t_bind *) ACE_OS::t_alloc (get_handle (),
00030   //                                          T_BIND,
00031   //                                          T_ADDR);
00032   //   struct t_bind *peeraddr 
00033   //      = (struct t_bind *) ACE_OS::t_alloc (get_handle (),
00034   //                                           T_BIND,
00035   //                                           T_ADDR);
00036   //   ::t_getprotaddr (get_handle (),
00037   //                   localaddr,
00038   //                   peeraddr);
00039 
00040   //   char* connected_name = (char*) ACE_OS::malloc (peeraddr->addr.len + 1);
00041   //   ACE_OS::strcpy (connected_name,
00042   //                  peeraddr->addr.buf);
00043   //   ACE_OS::t_free ((char *) localaddr,
00044   //                   T_BIND);
00045   //   ACE_OS::t_free ((char *) peeraddr,
00046   //                   T_BIND);
00047   //   return (connected_name);
00048 
00049 #error "This doesn't seem to work. May need to jimmy-rig something with the"
00050 #error "/etc/xti_hosts file - Ugh!"
00051 
00052   ACE_ATM_Addr sa;
00053   struct netbuf name;
00054   name.maxlen = sa.get_size ();
00055   name.buf = (char *) sa.get_addr ();
00056   ACE_OS::t_getname (this->get_handle (), &name, REMOTENAME);
00057   //  ACE_OS::ioctl (this->get_handle (),
00058   //               TI_GETPEERNAME,
00059   //               &name);
00060   return (name.buf);
00061 
00062 #elif defined (ACE_HAS_FORE_ATM_WS2) 
00063   // Use getpeername for WinSock2.
00064   struct sockaddr_atm name;
00065   ACE_OS::memset (&name, 0, sizeof (name));
00066   int nameSize = sizeof (name);
00067 
00068   if (ACE_OS::getpeername (this->get_handle (),
00069  (struct sockaddr *) &name,
00070                           &nameSize) != 0) {
00071     return 0;
00072   }
00073 
00074   char buffer[256];
00075   for (unsigned int index = 0; index < ATM_ADDR_SIZE - 1; index++) {
00076     buffer[ index * 3 ] = '\0';
00077     sprintf (buffer, "%s%02x.", buffer, name.satm_number.Addr[ index ]);
00078   }
00079   buffer[ (ATM_ADDR_SIZE - 1) * 3 ] = '\0';
00080   sprintf (buffer, "%s%02x.", buffer, 0);
00081   buffer[ ATM_ADDR_SIZE * 3 - 1 ] = '\0';
00082   for (index = 0; index < ACE_OS::strlen (buffer); ++index) 
00083     buffer[index] = tolower (buffer[index]);
00084 
00085   ifstream atm_hosts ("C:/WINNT/atmhosts");
00086   assert (atm_hosts.is_open ());
00087 
00088   // Find the host address in the ATM hosts file and return the
00089   //  host name
00090   char line[256];
00091   char *host_ptr, *host_name = 0;
00092   ACE_NEW_RETURN (host_name, char[256], 0);
00093   while (!atm_hosts.eof ()) {
00094     atm_hosts.getline (line, 256);
00095     // Convert the line to lower case to ease comparison
00096     for (index = 0; index < ACE_OS::strlen (line); ++index) 
00097       line[index] = tolower (line[index]);
00098     if (ACE_OS::strstr (line, buffer) != 0) 
00099       {
00100         char *strtok_p;
00101         // Grab the second token which is the host name
00102         ACE_OS::strtok_r (line, " \t", &strtok_p);
00103         host_ptr = strtok (0, " \t", &strtok_p);
00104         ACE_OS::strcpy (host_name, host_ptr);
00105         break;
00106       }
00107   }
00108 
00109   return host_name;
00110 #elif defined (ACE_HAS_LINUX_ATM) 
00111   ATM_Addr name;
00112   int nameSize = sizeof (name.sockaddratmsvc);
00113 
00114   if (ACE_OS::getpeername (this->get_handle (),
00115  (struct sockaddr *) & (name.sockaddratmsvc),
00116                           &nameSize) < 0) {
00117     ACE_OS::perror ("ACE_ATM_Stream (get_peer_name) : ");
00118     return 0;
00119   }
00120 
00121   static ACE_TCHAR buffer[MAX_ATM_ADDR_LEN + 1];
00122   int total_len;
00123   if ((total_len = atm2text (buffer,sizeof buffer,
00124  (struct sockaddr *) & (name.sockaddratmsvc), 
00125                             A2T_PRETTY|A2T_NAME)) < 0) {
00126     ACE_DEBUG ((LM_DEBUG,ACE_LIB_TEXT ("ACE_ATM_Stream (get_peer_name) :%d"),errno));
00127     return 0;
00128   }
00129 
00130   return (char*) buffer;
00131 #else
00132   return 0;
00133 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
00134 }

ACE_INLINE ATM_Stream & ACE_ATM_Stream::get_stream void   
 

Get the underlying stream.

Definition at line 74 of file ATM_Stream.i.

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.

00075 {
00076   ACE_TRACE ("ACE_ATM_Stream::get_stream");
00077   return stream_;
00078 }

int ACE_ATM_Stream::get_vpi_vci ACE_UINT16 &    vpi,
ACE_UINT16 &    vci
const
 

Get the VPI and VCI of the stream.

Definition at line 148 of file ATM_Stream.cpp.

References ACE_DEBUG, ACE_LIB_TEXT, ACE_TRACE, ACE_OS::fprintf, ACE_OS_Memory::free, get_handle, ACE_IPC_SAP::get_handle, ACE_OS::getsockopt, LM_DEBUG, ACE_OS_Memory::malloc, ACE_OS_String::memcpy, ACE_OS_String::memset, ACE_OS::printf, stream_, ACE_OS_TLI::t_error, ACE_OS_TLI::t_getinfo, ACE_OS_TLI::t_optmgmt, and t_optmgmt.

00150 {
00151   ACE_TRACE ("ACE_ATM_Stream::get_vpi_vci");
00152 #if defined (ACE_HAS_FORE_ATM_XTI) 
00153   struct t_atm_conn_prop conn_prop;
00154   char* connect_opts = (char *) &conn_prop;
00155   int opt_size = sizeof (t_atm_conn_prop);
00156   struct t_info info;
00157   struct t_optmgmt opt_req, opt_ret;
00158 
00159   if (ACE_OS::t_getinfo (stream_.get_handle (),
00160                         &info) < 0) 
00161     {
00162       ACE_OS::t_error ("t_getinfo");
00163       return -1;
00164     }
00165 
00166   char *buf_req = (char *) ACE_OS::malloc (info.options);
00167   if (buf_req == 0) 
00168     {
00169       ACE_OS::fprintf (stderr,
00170                       "Unable to allocate %ld bytes for options\n",
00171                       info.options);
00172       return -1;
00173     }
00174 
00175   char *buf_ret = (char *) ACE_OS::malloc (info.options);
00176   if (buf_ret == 0) 
00177     {
00178       ACE_OS::fprintf (stderr,
00179                       "Unable to allocate %ld bytes for options\n",
00180                       info.options);
00181       return -1;
00182     }
00183 
00184   ACE_OS::memset (&opt_req, 0, sizeof (opt_req));
00185   ACE_OS::memset (&opt_ret, 0, sizeof (opt_ret));
00186 
00187   struct t_opthdr *popt = (struct t_opthdr *) buf_req;
00188   struct t_opthdr *popt_ret = (struct t_opthdr *) buf_ret;
00189 
00190   popt->len= sizeof (struct t_opthdr) + opt_size;
00191 
00192   // We are only concerned with SVCs so no other check or values are needed
00193   //  here.
00194   popt->level = T_ATM_SIGNALING;
00195   popt->name = T_ATM_CONN_PROP;
00196   popt->status = 0;
00197 
00198   opt_req.opt.len = popt->len;
00199   opt_req.opt.buf = (char *) popt;
00200   opt_req.flags = T_CURRENT;
00201 
00202   popt = T_OPT_NEXTHDR (buf_req,
00203                        info.options,
00204                        popt);
00205   opt_ret.opt.maxlen  = info.options;
00206   opt_ret.opt.buf = (char *) popt_ret;
00207 
00208   if (ACE_OS::t_optmgmt (stream_.get_handle (),
00209                         &opt_req,
00210                         &opt_ret) < 0) {
00211     ACE_OS::t_error ("t_optmgmt");
00212     return -1;
00213   }
00214 
00215   ACE_OS::memcpy (connect_opts,
00216  (char *) popt_ret + sizeof (struct t_opthdr),
00217                  opt_size);
00218 
00219   ACE_OS::free (buf_ret);
00220   ACE_OS::free (buf_req);
00221 
00222   vpi = conn_prop.vpi;
00223   vci = conn_prop.vci;
00224   return (0);
00225 #elif defined (ACE_HAS_FORE_ATM_WS2) 
00226   ATM_CONNECTION_ID connID;
00227   DWORD bytes = 0;
00228   
00229   if (::WSAIoctl ((int) this -> get_handle (), 
00230                   SIO_GET_ATM_CONNECTION_ID, 
00231                   0, 
00232                   0, 
00233  (LPVOID) &connID, 
00234                   sizeof (ATM_CONNECTION_ID), 
00235                   &bytes, 
00236                   0, 
00237                   0) 
00238        == SOCKET_ERROR) {
00239     ACE_OS::printf ("Error: WSAIoctl %d\n", WSAGetLastError ());
00240   }
00241 
00242   vpi = (ACE_UINT16) connID.VPI;
00243   vci = (ACE_UINT16) connID.VCI;
00244 
00245   return 0;
00246 #elif defined (ACE_HAS_LINUX_ATM) 
00247 #if defined (SO_ATMPVC) /* atm version>=0.62 */
00248   struct sockaddr_atmpvc mypvcaddr;
00249   int addrpvclen = sizeof (mypvcaddr);
00250   if (ACE_OS::getsockopt (stream_.get_handle (),
00251                          SOL_ATM,
00252                          SO_ATMPVC, 
00253                          ACE_reinterpret_cast (char*,&mypvcaddr),
00254                          &addrpvclen) < 0) {
00255     ACE_DEBUG (LM_DEBUG,
00256               ACE_LIB_TEXT ("ACE_ATM_Stream::get_vpi_vci: getsockopt %d\n"),
00257               errno);
00258     return -1;
00259   }
00260   vpi = (ACE_UINT16) mypvcaddr.sap_addr.vpi;
00261   vci = (ACE_UINT16) mypvcaddr.sap_addr.vci;
00262 
00263   return 0;
00264 #elif defined (SO_VCID) /* patch for atm version 0.59 */
00265   struct atm_vcid mypvcid; 
00266   int pvcidlen = sizeof (mypvcid);
00267   if (ACE_OS::getsockopt (stream_.get_handle (),
00268                          SOL_ATM,SO_VCID,
00269                          ACE_reinterpret_cast (char*,&mypvcid),
00270                          &pvcidlen) < 0) {
00271     ACE_DEBUG (LM_DEBUG,
00272               ACE_LIB_TEXT ("ACE_ATM_Stream::get_vpi_vci: getsockopt %d\n"),
00273               errno);
00274     return -1;
00275   }
00276   vpi = (ACE_UINT16) mypvcid.vpi;
00277   vci = (ACE_UINT16) mypvcid.vci;
00278 
00279   return 0;
00280 #else
00281   ACE_DEBUG (LM_DEBUG,
00282             ACE_LIB_TEXT ("ACE_ATM_Stream::get_vpi_vci: Not implemented in this ATM version. Update to >= 0.62\n Or patch 0.59"));
00283   ACE_UNUSED_ARG (vci);
00284   ACE_UNUSED_ARG (vpi);
00285 
00286   return (-1);
00287 #endif /* SO_ATMPVC || SO_VCID */
00288 #else
00289   return (-1);
00290 #endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
00291 }

ACE_INLINE int ACE_ATM_Stream::open ACE_ATM_Params    params = ACE_ATM_Params()
 

open the stream.

Definition at line 15 of file ATM_Stream.i.

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_String::memset, ACE_SOCK::open, ACE_OS::printf, ACE_ATM_Params::set_flags, and stream_.

00016 {
00017   ACE_TRACE ("ACE_ATM_Stream::open");
00018 #if defined (ACE_HAS_FORE_ATM_XTI)
00019   ACE_HANDLE handle = stream_.open (params.get_device(),
00020                                     params.get_oflag(),
00021                                     params.get_info());
00022   return (handle == ACE_INVALID_HANDLE ? -1 : 0);
00023 #elif defined (ACE_HAS_FORE_ATM_WS2)
00024   params.set_flags( ACE_FLAG_MULTIPOINT_C_ROOT | ACE_FLAG_MULTIPOINT_D_ROOT );
00025 
00026   int retval = stream_.open (params.get_type(),
00027                              params.get_protocol_family(),
00028                              params.get_protocol(),
00029                              params.get_protocol_info(),
00030                              params.get_sock_group(),
00031                              params.get_flags(),
00032                              params.get_reuse_addr());
00033   if (retval == -1)
00034     return -1;
00035 
00036   struct sockaddr_atm sock_addr;
00037 
00038   ACE_OS::memset(&sock_addr, 0, sizeof(struct sockaddr_atm));
00039   sock_addr.satm_family = AF_ATM;
00040   sock_addr.satm_number.AddressType=ADDR_ANY;
00041   sock_addr.satm_number.NumofDigits = ATM_ADDR_SIZE;
00042   sock_addr.satm_blli.Layer2Protocol = SAP_FIELD_ABSENT;
00043   sock_addr.satm_blli.Layer3Protocol = SAP_FIELD_ABSENT;
00044   sock_addr.satm_bhli.HighLayerInfoType = SAP_FIELD_ABSENT;
00045   if (ACE_OS::bind(get_handle(),
00046                    (struct sockaddr FAR *)&sock_addr,
00047                    sizeof(struct sockaddr_atm)) < 0)
00048     {
00049       ACE_OS::printf("Error binding local address: %d",WSAGetLastError());
00050       return -1;
00051     }
00052 
00053   return 0;
00054 #else
00055   ACE_UNUSED_ARG(params);
00056   return 0;
00057 #endif /* ACE_HAS_FORE_ATM_XTI */
00058 }

ACE_INLINE ssize_t ACE_ATM_Stream::recv void *    buf,
size_t    n,
int *    flags = 0
const
 

Recv an n byte buffer from the connected transport mechanism.

Definition at line 82 of file ATM_Stream.i.

References ACE_TRACE, ACE_SOCK_IO::recv, and stream_.

00085 {
00086   ACE_TRACE ("ACE_ATM_Stream::recv");
00087 #if defined (ACE_HAS_FORE_ATM_XTI)
00088   return stream_.recv (buf,
00089                        n,
00090                        flags);
00091 #elif defined (ACE_HAS_FORE_ATM_WS2)
00092   return stream_.recv (buf,
00093                        n);
00094 #else
00095   ACE_UNUSED_ARG(buf);
00096   ACE_UNUSED_ARG(n);
00097   ACE_UNUSED_ARG(flags);
00098   return (0);
00099 #endif /* ACE_HAS_FORE_ATM_XTI */
00100 }

ACE_INLINE ssize_t ACE_ATM_Stream::send_n const void *    buf,
size_t    n,
int    flags
const
 

Send exactly n bytes to the connected transport mechanism.

Definition at line 104 of file ATM_Stream.i.

References ACE_TRACE, ACE_SOCK_Stream::send_n, and stream_.

00107 {
00108   ACE_TRACE ("ACE_ATM_Stream::send_n");
00109 #if defined (ACE_HAS_FORE_ATM_XTI)
00110   return stream_.send_n (buf,
00111                          n,
00112                          flags);
00113 #elif defined (ACE_HAS_FORE_ATM_WS2)
00114   return stream_.send_n (buf,
00115                          n,
00116                          flags);
00117 #else
00118   ACE_UNUSED_ARG(buf);
00119   ACE_UNUSED_ARG(n);
00120   ACE_UNUSED_ARG(flags);
00121   return (0);
00122 #endif /* ACE_HAS_FORE_ATM_XTI */
00123 }


Member Data Documentation

ACE_ATM_Stream::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 86 of file ATM_Stream.h.

ATM_Stream ACE_ATM_Stream::stream_ [private]
 

Typedef'd to the appropriate stream mechanism above.

Definition at line 90 of file ATM_Stream.h.

Referenced by close, get_handle, get_stream, get_vpi_vci, open, recv, and send_n.


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