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

ACE_TLI_Connector Class Reference

Defines an active connection factory for the ACE_TLI C++ wrappers. More...

#include <TLI_Connector.h>

Inheritance diagram for ACE_TLI_Connector:

Inheritance graph
[legend]
List of all members.

Public Types

typedef ACE_INET_Addr PEER_ADDR
typedef ACE_TLI_Stream PEER_STREAM

Public Methods

 ACE_TLI_Connector (void)
 Default constructor. More...

 ACE_TLI_Connector (ACE_TLI_Stream &new_stream, const ACE_Addr &remote_sap, ACE_Time_Value *timeout=0, const ACE_Addr &local_sap=ACE_Addr::sap_any, int reuse_addr=0, int flags=O_RDWR, int perms=0, const char device[]=ACE_TLI_TCP_DEVICE, struct t_info *info=0, int rw_flag=1, struct netbuf *udata=0, struct netbuf *opt=0)
int connect (ACE_TLI_Stream &new_stream, const ACE_Addr &remote_sap, ACE_Time_Value *timeout=0, const ACE_Addr &local_sap=ACE_Addr::sap_any, int reuse_addr=0, int flags=O_RDWR, int perms=0, const char device[]=ACE_TLI_TCP_DEVICE, struct t_info *info=0, int rw_flag=1, struct netbuf *udata=0, struct netbuf *opt=0)
int complete (ACE_TLI_Stream &new_stream, ACE_Addr *remote_sap, ACE_Time_Value *tv)
int reset_new_handle (ACE_HANDLE handle)
 Resets any event associations on this handle. More...

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


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Detailed Description

Defines an active connection factory for the ACE_TLI C++ wrappers.

Definition at line 33 of file TLI_Connector.h.


Member Typedef Documentation

typedef ACE_INET_Addr ACE_TLI_Connector::PEER_ADDR
 

Reimplemented in ACE_XTI_ATM_Mcast.

Definition at line 110 of file TLI_Connector.h.

typedef ACE_TLI_Stream ACE_TLI_Connector::PEER_STREAM
 

Reimplemented in ACE_XTI_ATM_Mcast.

Definition at line 111 of file TLI_Connector.h.


Constructor & Destructor Documentation

ACE_TLI_Connector::ACE_TLI_Connector void   
 

Default constructor.

Definition at line 25 of file TLI_Connector.cpp.

References ACE_TRACE.

00026 {
00027   ACE_TRACE ("ACE_TLI_Connector::ACE_TLI_Connector");
00028 }

ACE_INLINE ACE_TLI_Connector::ACE_TLI_Connector ACE_TLI_Stream   new_stream,
const ACE_Addr   remote_sap,
ACE_Time_Value   timeout = 0,
const ACE_Addr   local_sap = ACE_Addr::sap_any,
int    reuse_addr = 0,
int    flags = O_RDWR,
int    perms = 0,
const char    device[] = ACE_TLI_TCP_DEVICE,
struct t_info *    info = 0,
int    rw_flag = 1,
struct netbuf *    udata = 0,
struct netbuf *    opt = 0
 

Actively connect and produce a <new_stream> if things go well. The <remote_sap> is the address that we are trying to connect with. The <timeout> is the amount of time to wait to connect. If it's 0 then we block indefinitely. If *timeout == {0, 0} then the connection is done using non-blocking mode. In this case, if the connection can't be made immediately the value of -1 is returned with <errno == EWOULDBLOCK>. If *timeout > {0, 0} then this is the maximum amount of time to wait before timing out. If the time expires before the connection is made <errno == ETIME>. The <local_sap> is the value of local address to bind to. If it's the default value of <ACE_Addr::sap_any> then the user is letting the OS do the binding. If <reuse_addr> == 1 then the <local_addr> is reused, even if it hasn't been cleanedup yet.

Definition at line 7 of file TLI_Connector.i.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, connect, ETIME, EWOULDBLOCK, and LM_ERROR.

00019 {
00020   ACE_TRACE ("ACE_TLI_Connector::ACE_TLI_Connector");
00021   if (this->connect (new_stream,
00022                      remote_sap,
00023                      timeout,
00024                      local_sap,
00025                      reuse_addr,
00026                      flags,
00027                      perms,
00028                      device,
00029                      info,
00030                      rw_flag,
00031                      udata,
00032                      opt) == -1
00033       && timeout != 0 && !(errno == EWOULDBLOCK || errno == ETIME))
00034     ACE_ERROR ((LM_ERROR,
00035                 ACE_LIB_TEXT ("%p\n"),
00036                 ACE_LIB_TEXT ("ACE_TLI_Stream::ACE_TLI_Stream")));
00037 }


Member Function Documentation

int ACE_TLI_Connector::complete ACE_TLI_Stream   new_stream,
ACE_Addr   remote_sap,
ACE_Time_Value   tv
 

Try to complete a non-blocking connection. If connection completion is successful then <new_stream> contains the connected ACE_SOCK_Stream. If <remote_sap> is non-NULL then it will contain the address of the connected peer.

Definition at line 195 of file TLI_Connector.cpp.

References ACE_NONBLOCK, ACE_TRACE, ACE_TLI_Stream::close, ACE_IPC_SAP::disable, ACE_Addr::get_addr, ACE_IPC_SAP::get_handle, ACE_Addr::get_size, ACE::handle_timed_complete, ACE_OS::ioctl, ACE_Time_Value::msec, ACE_OS_TLI::t_look, and t_rcvconnect.

Referenced by ACE_XTI_ATM_Mcast::add_leaf, and connect.

00198 {
00199   ACE_TRACE ("ACE_TLI_Connector::complete");
00200 #if defined (ACE_WIN32)
00201    if (WaitForSingleObject (new_stream.get_handle(), tv->msec()) == WAIT_OBJECT_0)
00202     {
00203       if (ACE_OS::t_look (new_stream.get_handle()) == T_CONNECT)
00204         return t_rcvconnect (new_stream.get_handle(), 0);
00205       else
00206         return -1;
00207     }
00208   else
00209     return -1;
00210 #else
00211   ACE_HANDLE h = ACE::handle_timed_complete (new_stream.get_handle (),
00212                                              tv,
00213                                              1);
00214   if (h == ACE_INVALID_HANDLE)
00215     {
00216       new_stream.close ();
00217       return -1;
00218     }
00219   else    // We've successfully connected!
00220     {
00221       if (remote_sap != 0)
00222         {
00223 #if defined (ACE_HAS_SVR4_TLI)
00224           struct netbuf name;
00225 
00226           name.maxlen = remote_sap->get_size ();
00227           name.buf    = (char *) remote_sap->get_addr ();
00228 
00229           if (ACE_OS::ioctl (new_stream.get_handle (),
00230                              TI_GETPEERNAME,
00231                              &name) == -1)
00232 #else /* SunOS4 */
00233           if (0)
00234 #endif /* ACE_HAS_SVR4_TLI */
00235             {
00236               new_stream.close ();
00237               return -1;
00238             }
00239         }
00240 
00241       // Start out with non-blocking disabled on the <new_stream>.
00242       new_stream.disable (ACE_NONBLOCK);
00243 
00244       return 0;
00245     }
00246 #endif /* ACE_WIN32 */
00247 }

int ACE_TLI_Connector::connect ACE_TLI_Stream   new_stream,
const ACE_Addr   remote_sap,
ACE_Time_Value   timeout = 0,
const ACE_Addr   local_sap = ACE_Addr::sap_any,
int    reuse_addr = 0,
int    flags = O_RDWR,
int    perms = 0,
const char    device[] = ACE_TLI_TCP_DEVICE,
struct t_info *    info = 0,
int    rw_flag = 1,
struct netbuf *    udata = 0,
struct netbuf *    opt = 0
 

Actively connect and produce a <new_stream> if things go well. The <remote_sap> is the address that we are trying to connect with. The <timeout> is the amount of time to wait to connect. If it's 0 then we block indefinitely. If *timeout == {0, 0} then the connection is done using non-blocking mode. In this case, if the connection can't be made immediately the value of -1 is returned with <errno == EWOULDBLOCK>. If *timeout > {0, 0} then this is the maximum amount of time to wait before timing out. If the time expires before the connection is made <errno == ETIME>. The <local_sap> is the value of local address to bind to. If it's the default value of <ACE_Addr::sap_any> then the user is letting the OS do the binding. If <reuse_addr> == 1 then the <local_addr> is reused, even if it hasn't been cleanedup yet.

Reimplemented in ACE_XTI_ATM_Mcast.

Definition at line 35 of file TLI_Connector.cpp.

References ACE_NONBLOCK, ACE_TRACE, ACE_TLI_Stream::close, complete, ACE_IPC_SAP::enable, ETIME, EWOULDBLOCK, ACE_Addr::get_addr, ACE_IPC_SAP::get_handle, ACE_TLI_Stream::get_rwflag, ACE_Addr::get_size, ACE_OS::ioctl, ACE_TLI::look, ACE_OS_String::memcpy, ACE_TLI::open, ACE_TLI::rcvdis, ACE_Addr::sap_any, ACE_Time_Value::sec, ACE_IPC_SAP::set_handle, ACE_TLI::set_option, ACE_TLI_Stream::set_rwflag, t_alloc, ACE_OS_TLI::t_bind, t_bind, ACE_OS_TLI::t_connect, ACE_OS_TLI::t_free, and ACE_Time_Value::usec.

Referenced by ACE_TLI_Connector, and ACE_XTI_ATM_Mcast::connect.

00047 {
00048   ACE_TRACE ("ACE_TLI_Connector::connect");
00049   int result = 0;
00050 
00051   // Only open a new endpoint if we don't already have a valid handle.
00052 
00053   if (new_stream.get_handle () == ACE_INVALID_HANDLE
00054       && new_stream.open (device, flags, info) == ACE_INVALID_HANDLE)
00055     return -1;
00056 
00057   if (local_sap != ACE_Addr::sap_any)
00058     {
00059       // Bind the local endpoint to a specific addr.
00060 
00061       struct t_bind *localaddr;
00062 
00063       localaddr = (struct t_bind *)
00064         ACE_OS::t_alloc (new_stream.get_handle (), T_BIND, T_ADDR);
00065 
00066       if (localaddr == 0)
00067         result = -1;
00068       else
00069         {
00070           int one = 1;
00071 #if !defined (ACE_HAS_FORE_ATM_XTI)
00072           // Reusing the address causes problems with FORE's API. The
00073           // issue may be that t_optmgmt isn't fully supported by
00074           // FORE. t_errno is TBADOPT after the t_optmgmt call so
00075           // maybe options are configured differently for XTI than for
00076           // TLI (at least for FORE's implementation - XTI is supposed
00077           // to be a superset of TLI).
00078           if (reuse_addr
00079               && new_stream.set_option (SOL_SOCKET,
00080                                         SO_REUSEADDR,
00081                                         &one,
00082                                         sizeof one) == -1)
00083             result = -1;
00084           else
00085 #endif /* ACE_HAS_FORE_ATM_XTI */
00086             {
00087               void *addr_buf = local_sap.get_addr ();
00088               localaddr->addr.len = local_sap.get_size ();
00089               ACE_OS::memcpy(localaddr->addr.buf,
00090                              addr_buf,
00091                              localaddr->addr.len);
00092 
00093               if (ACE_OS::t_bind (new_stream.get_handle (),
00094                                   localaddr,
00095                                   localaddr) == -1)
00096                 result = -1;
00097 
00098               ACE_OS::t_free ((char *) localaddr,
00099                               T_BIND);
00100             }
00101         }
00102 
00103       if (result == -1)
00104         {
00105           new_stream.close ();
00106           return -1;
00107         }
00108     }
00109   // Let TLI select the local endpoint addr.
00110   else if (ACE_OS::t_bind (new_stream.get_handle (), 0, 0) == -1)
00111     return -1;
00112 
00113   struct t_call *callptr = 0;
00114 
00115   callptr = (struct t_call *)
00116     ACE_OS::t_alloc (new_stream.get_handle (), T_CALL, T_ADDR);
00117 
00118   if (callptr == 0)
00119     {
00120       new_stream.close ();
00121       return -1;
00122     }
00123 
00124   void *addr_buf = remote_sap.get_addr ();
00125   callptr->addr.len = remote_sap.get_size ();
00126   ACE_OS::memcpy (callptr->addr.buf,
00127                   addr_buf,
00128                   callptr->addr.len);
00129   //callptr->addr.buf = (char *) remote_sap.get_addr ();
00130 
00131   if (udata != 0)
00132     ACE_OS::memcpy ((void *) &callptr->udata, (void *) udata, sizeof *udata);
00133   if (opt != 0)
00134     ACE_OS::memcpy ((void *) &callptr->opt, (void *) opt, sizeof *opt);
00135 
00136   // Connect to remote endpoint.
00137 #if defined (ACE_HAS_FORE_ATM_XTI)
00138   // FORE's XTI/ATM driver has problems with ioctl/fcntl calls so (at least
00139   // for now) always have blocking calls.
00140   timeout = 0;
00141 #endif /* ACE_HAS_FORE_ATM_XTI */
00142 
00143   if (timeout != 0)   // Enable non-blocking, if required.
00144     {
00145       if (new_stream.enable (ACE_NONBLOCK) == -1)
00146         result = -1;
00147 
00148       // Do a non-blocking connect.
00149       if (ACE_OS::t_connect (new_stream.get_handle (), callptr, 0) == -1)
00150         {
00151           result = -1;
00152 
00153           // Check to see if we simply haven't connected yet on a
00154           // non-blocking handle or whether there's really an error.
00155           if (t_errno == TNODATA)
00156             {
00157               if (timeout->sec () == 0 && timeout->usec () == 0)
00158                 errno = EWOULDBLOCK;
00159               else
00160                 result = this->complete (new_stream, 0, timeout);
00161             }
00162           else if (t_errno == TLOOK && new_stream.look () == T_DISCONNECT)
00163             new_stream.rcvdis ();
00164         }
00165     }
00166   // Do a blocking connect to the server.
00167   else if (ACE_OS::t_connect (new_stream.get_handle (), callptr, 0) == -1)
00168     result = -1;
00169 
00170   if (result != -1)
00171     {
00172       new_stream.set_rwflag (rwf);
00173 #if defined (I_PUSH) && !defined (ACE_HAS_FORE_ATM_XTI)
00174       if (new_stream.get_rwflag ())
00175         result = ACE_OS::ioctl (new_stream.get_handle (),
00176                                 I_PUSH,
00177                                 ACE_const_cast (char *, "tirdwr"));
00178 #endif /* I_PUSH */
00179     }
00180   else if (!(errno == EWOULDBLOCK || errno == ETIME))
00181     {
00182       // If things have gone wrong, close down and return an error.
00183       new_stream.close ();
00184       new_stream.set_handle (ACE_INVALID_HANDLE);
00185     }
00186 
00187   if (ACE_OS::t_free ((char *) callptr, T_CALL) == -1)
00188     return -1;
00189   return result;
00190 }

void ACE_TLI_Connector::dump void    const
 

Dump the state of an object.

Reimplemented in ACE_XTI_ATM_Mcast.

Definition at line 20 of file TLI_Connector.cpp.

References ACE_TRACE.

00021 {
00022   ACE_TRACE ("ACE_TLI_Connector::dump");
00023 }

ACE_INLINE int ACE_TLI_Connector::reset_new_handle ACE_HANDLE    handle
 

Resets any event associations on this handle.

Definition at line 41 of file TLI_Connector.i.

00042 {
00043   ACE_UNUSED_ARG (handle);
00044   // Nothing to do here since the handle is not a socket
00045   return 0;
00046 }


Member Data Documentation

ACE_TLI_Connector::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented in ACE_XTI_ATM_Mcast.

Definition at line 117 of file TLI_Connector.h.


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