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

ATM_Acceptor.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // $Id: ATM_Acceptor.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:20 chad Exp $
00003 
00004 #include "ace/ATM_Acceptor.h"
00005 
00006 ACE_RCSID(ace, ATM_Acceptor, "$Id: ATM_Acceptor.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:20 chad Exp $")
00007 
00008 #if defined (ACE_HAS_ATM)
00009 
00010 #if defined (ACE_HAS_LINUX_ATM)
00011 #include /**/ "linux/atmdev.h"
00012 #endif /* ACE_HAS_LINUX_ATM */
00013 
00014 #if !defined (__ACE_INLINE__)
00015 #include "ace/ATM_Acceptor.i"
00016 #endif /* __ACE_INLINE__ */
00017 
00018 // Put the actual definitions of the ACE_ATM_Request and
00019 // ACE_ATM_Request_Queue classes here to hide them from clients...
00020 
00021 ACE_ALLOC_HOOK_DEFINE(ACE_ATM_Acceptor)
00022 
00023 void
00024 ACE_ATM_Acceptor::dump (void) const
00025 {
00026   ACE_TRACE ("ACE_ATM_Acceptor::dump");
00027 }
00028 
00029 ACE_ATM_Acceptor::ACE_ATM_Acceptor (void)
00030 {
00031   ACE_TRACE ("ACE_ATM_Acceptor::ACE_ATM_Acceptor");
00032 }
00033 
00034 ACE_ATM_Acceptor::~ACE_ATM_Acceptor (void)
00035 {
00036   ACE_TRACE ("ACE_ATM_Acceptor::~ACE_ATM_Acceptor");
00037 }
00038 
00039 int 
00040 ACE_ATM_Acceptor::get_local_addr (ACE_ATM_Addr &local_addr)
00041 {
00042   ACE_TRACE ("ACE_ATM_Acceptor::get_local_addr");
00043 
00044 #if defined (ACE_HAS_FORE_ATM_WS2)
00045   unsigned long ret = 0;
00046   DWORD deviceID = 0;
00047   ATM_ADDRESS addr;
00048   struct sockaddr_atm *laddr;
00049 
00050   if (::WSAIoctl ((int) ((ACE_SOCK_Acceptor *)this) -> get_handle (), 
00051                 SIO_GET_ATM_ADDRESS, 
00052  (LPVOID) &deviceID, 
00053                 sizeof (DWORD), 
00054  (LPVOID)&addr,
00055                 sizeof (ATM_ADDRESS),
00056                 &ret,
00057                 0,
00058                 0) == SOCKET_ERROR) {
00059     ACE_OS::printf ("ATM_Acceptor (get_local_addr): WSIoctl: %d\n", 
00060                     ::WSAGetLastError ());
00061     return -1;
00062   }
00063 
00064   laddr = (struct sockaddr_atm *)local_addr.get_addr ();
00065   ACE_OS::memcpy ((void *)& (laddr -> satm_number), 
00066  (void *)&addr, 
00067                  ATM_ADDR_SIZE - 1);
00068 
00069   return 0;
00070 #elif defined (ACE_HAS_FORE_ATM_XTI)
00071   ACE_UNUSED_ARG (local_addr);
00072   
00073   return 0;
00074 #elif defined (ACE_HAS_LINUX_ATM)
00075   ATM_Addr *myaddr = (ATM_Addr *)local_addr.get_addr ();
00076   int addrlen = sizeof (myaddr->sockaddratmsvc);
00077   
00078   if (ACE_OS::getsockname (acceptor_.get_handle (),
00079  (struct sockaddr *) & (myaddr->sockaddratmsvc),
00080                           &addrlen) < 0) {
00081     ACE_DEBUG ((LM_DEBUG,
00082                ACE_LIB_TEXT ("ATM_Acceptor (get_local_addr): ioctl: %d\n"),
00083                errno));
00084     return -1;
00085   }
00086 
00087   return (0);
00088 #else
00089   ACE_UNUSED_ARG (local_addr);
00090 
00091   return 0;
00092 #endif /* ACE_HAS_FORE_ATM_WS2 && ACE_HAS_FORE_ATM_XTI */
00093 }
00094 
00095 ACE_HANDLE
00096 ACE_ATM_Acceptor::open (const ACE_Addr &remote_sap,
00097                         int backlog,
00098                         ACE_ATM_Params params)
00099 {
00100   ACE_TRACE ("ACE_ATM_Acceptor::open");
00101 #if defined (ACE_HAS_FORE_ATM_XTI)
00102   ACE_HANDLE handle = acceptor_.open (remote_sap,
00103                                       params.get_reuse_addr (),
00104                                       params.get_oflag (),
00105                                       params.get_info (),
00106                                       backlog,
00107                                       params.get_device ());
00108   return (handle == ACE_INVALID_HANDLE ? -1 : 0);
00109 #elif defined (ACE_HAS_FORE_ATM_WS2)
00110   struct sockaddr_atm local_atm_addr;
00111   ACE_HANDLE ret;
00112   DWORD flags = 0;
00113 
00114   /* Create a local endpoint of communication */
00115 
00116   // Only leaves can listen.
00117   flags = ACE_FLAG_MULTIPOINT_C_LEAF | ACE_FLAG_MULTIPOINT_D_LEAF;
00118 
00119   if ((ret = ACE_OS::socket (AF_ATM,
00120                              SOCK_RAW,
00121                              ATMPROTO_AAL5,
00122                              0,
00123                              0,
00124                              flags))
00125       == ACE_INVALID_HANDLE) {
00126     ACE_OS::printf ("Acceptor (open): socket %d\n",
00127                     ::WSAGetLastError ());
00128     return (ret);
00129   }
00130 
00131  ((ACE_SOCK_Acceptor *)this) -> set_handle (ret);
00132 
00133   /* Set up the address information to become a server */
00134   ACE_OS::memset ((void *) &local_atm_addr, 0, sizeof local_atm_addr);
00135   local_atm_addr.satm_family = AF_ATM;
00136   local_atm_addr.satm_number.AddressType = SAP_FIELD_ANY_AESA_REST;
00137   local_atm_addr.satm_number.Addr[ ATM_ADDR_SIZE - 1 ] 
00138     = ((ACE_ATM_Addr *)&remote_sap) -> get_selector ();
00139   local_atm_addr.satm_blli.Layer2Protocol = SAP_FIELD_ANY;
00140   local_atm_addr.satm_blli.Layer3Protocol = SAP_FIELD_ABSENT;
00141   local_atm_addr.satm_bhli.HighLayerInfoType = SAP_FIELD_ABSENT;
00142 
00143   /* Associate address with endpoint */
00144   if (ACE_OS::bind (( (ACE_SOCK_Acceptor *)this) -> get_handle (),
00145                     ACE_reinterpret_cast (struct sockaddr *, &local_atm_addr),
00146                     sizeof local_atm_addr) == -1) {
00147     ACE_OS::printf ("Acceptor (open): bind %d\n", ::WSAGetLastError ()); 
00148     return (ACE_INVALID_HANDLE);
00149   }
00150 
00151   /* Make endpoint listen for service requests */
00152   if (ACE_OS::listen (( (ACE_SOCK_Acceptor *)this) -> get_handle (), 
00153                       backlog) 
00154                     == -1) {
00155     ACE_OS::printf ("Acceptor (open): listen %d\n", ::WSAGetLastError ());
00156     return (ACE_INVALID_HANDLE);
00157   }
00158 
00159   return 0;
00160 #elif defined (ACE_HAS_LINUX_ATM)
00161   //we need to set the qos before binding to the socket
00162   //use remote_sap as local_sap
00163 
00164   ACE_ATM_Addr local_sap;
00165   ATM_Addr *local_sap_addr = (ATM_Addr*)local_sap.get_addr ();
00166   ACE_ATM_QoS def_qos;
00167   ATM_QoS qos = def_qos.get_qos ();
00168 
00169   ACE_HANDLE handle;
00170   if ((handle = ACE_OS::socket (params.get_protocol_family (), 
00171                                 params.get_type (), 
00172                                 params.get_protocol (), 
00173                                 params.get_protocol_info (), 
00174                                 params.get_sock_group (), 
00175                                 params.get_flags () 
00176                                ))
00177       == ACE_INVALID_HANDLE) {
00178     ACE_DEBUG (LM_DEBUG,
00179               ACE_LIB_TEXT ("Acceptor (socket): socket %d\n"),
00180               errno);
00181     return (ACE_INVALID_HANDLE);
00182   }
00183    
00184  ((ACE_SOCK_Acceptor *)this) -> set_handle (handle);
00185   if (ACE_OS::setsockopt (handle,
00186                          SOL_ATM,
00187                          SO_ATMQOS,
00188                          ACE_reinterpret_cast (char*, &qos),
00189                          sizeof (qos)) < 0) {
00190     ACE_OS::printf ("Acceptor (setsockopt): setsockopt:%d\n",
00191                    errno);
00192   }
00193 
00194   struct atmif_sioc req;
00195   struct sockaddr_atmsvc aux_addr[1024];
00196 
00197   req.number = 0;
00198   req.arg = aux_addr;
00199   req.length = sizeof (aux_addr);
00200   if (ACE_OS::ioctl (handle,
00201                     ATM_GETADDR,
00202                     &req) < 0) {
00203     ACE_OS::perror ("Acceptor (setsockopt): ioctl:");
00204   }
00205   else {
00206     local_sap_addr->sockaddratmsvc = aux_addr[0];
00207   }
00208   local_sap.set_selector (( (ACE_ATM_Addr*)&remote_sap)->get_selector ());
00209 
00210   if (ACE_OS::bind (handle,
00211                     ACE_reinterpret_cast (struct sockaddr *,
00212                                          & (local_sap_addr->sockaddratmsvc)),
00213                     sizeof (local_sap_addr->sockaddratmsvc)
00214                    ) == -1) {
00215     ACE_DEBUG (LM_DEBUG,
00216               ACE_LIB_TEXT ("Acceptor (open): bind %d\n"),
00217               errno);
00218     return -1;
00219   }
00220   // Make endpoint listen for service requests
00221   if (ACE_OS::listen (handle,
00222                       backlog) 
00223       == -1) {
00224     ACE_DEBUG (LM_DEBUG,
00225               ACE_LIB_TEXT ("Acceptor (listen): listen %d\n"),
00226               errno);
00227     return -1;
00228   }
00229 
00230   return 0;
00231 #else
00232   ACE_UNUSED_ARG (remote_sap);
00233   ACE_UNUSED_ARG (backlog);
00234   ACE_UNUSED_ARG (params);
00235 #endif /* ACE_HAS_FORE_ATM_XTI/ACE_HAS_FORE_ATM_WS2/ACE_HAS_LINUX_ATM */
00236 }
00237 
00238 int
00239 ACE_ATM_Acceptor::accept (ACE_ATM_Stream &new_sap,
00240                           ACE_Addr *remote_addr,
00241                           ACE_Time_Value *timeout,
00242                           int restart,
00243                           int reset_new_handle,
00244                           ACE_ATM_Params params,
00245                           ACE_ATM_QoS qos)
00246 {
00247   ACE_TRACE ("ACE_ATM_Acceptor::accept");
00248 #if defined (ACE_HAS_FORE_ATM_XTI)
00249   ATM_QoS optbuf = qos.get_qos ();
00250 
00251   return (acceptor_.accept (new_sap.get_stream (),
00252                            remote_addr,
00253                            timeout,
00254                            restart,
00255                            reset_new_handle,
00256                            params.get_rw_flag (),
00257                            params.get_user_data (),
00258                            &optbuf));
00259 #elif defined (ACE_HAS_FORE_ATM_WS2)
00260   ACE_HANDLE n_handle;
00261   ACE_HANDLE s_handle = ((ACE_SOCK_Acceptor *) this) -> get_handle ();
00262   struct sockaddr_atm *cli_addr 
00263     = (struct sockaddr_atm *)remote_addr -> get_addr ();
00264   int caddr_len = sizeof (struct sockaddr_atm); 
00265 
00266   do {
00267     n_handle = ACE_OS::accept (s_handle,
00268                               ACE_reinterpret_cast (struct sockaddr *,
00269                                                    cli_addr),
00270                               &caddr_len);
00271   } while (n_handle == ACE_INVALID_HANDLE && errno == EINTR);
00272 
00273  ((ACE_ATM_Addr *)remote_addr) -> set (cli_addr,
00274  ((ACE_ATM_Addr *)remote_addr) -> get_selector ());
00275  ((ACE_IPC_SAP *)&new_sap) -> set_handle (n_handle);
00276 
00277   return 0;
00278 #elif defined (ACE_HAS_LINUX_ATM)
00279   ACE_UNUSED_ARG (params);
00280 
00281   ACE_HANDLE s_handle = ((ACE_SOCK_Acceptor *) this) -> get_handle ();
00282   struct atm_qos accept_qos = qos.get_qos ();
00283 
00284   if (ACE_OS::setsockopt (s_handle,
00285                          SOL_ATM,
00286                          SO_ATMQOS,
00287                          ACE_reinterpret_cast (char*,
00288                                               &accept_qos),
00289                          sizeof (accept_qos)) < 0) {
00290     ACE_OS::printf ("Acceptor (accept): error setting Qos"); 
00291   }
00292 
00293   return (acceptor_.accept (new_sap.get_stream (),
00294                           remote_addr,
00295                           timeout,
00296                           restart,
00297                           reset_new_handle));
00298 #else
00299   ACE_UNUSED_ARG (new_sap);
00300   ACE_UNUSED_ARG (remote_addr);
00301   ACE_UNUSED_ARG (timeout);
00302   ACE_UNUSED_ARG (restart);
00303   ACE_UNUSED_ARG (reset_new_handle);
00304   ACE_UNUSED_ARG (params);
00305   ACE_UNUSED_ARG (qos);
00306   return (0);
00307 #endif /* ACE_HAS_FORE_ATM_XTI */
00308 }
00309 
00310 #endif /* ACE_HAS_ATM */

Generated on Mon Jun 16 11:19:08 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002