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

ACE_SPIPE_Connector Class Reference

Defines an active connection factory for <ACE_SPIPE_Stream>. On Windows this is mapped to Named Pipes, whereas on UNIX it is mapped to STREAM pipes. More...

#include <SPIPE_Connector.h>

List of all members.

Public Types

typedef ACE_SPIPE_Addr PEER_ADDR
typedef ACE_SPIPE_Stream PEER_STREAM

Public Methods

 ACE_SPIPE_Connector (void)
 Default constructor. More...

 ACE_SPIPE_Connector (ACE_SPIPE_Stream &new_io, const ACE_SPIPE_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, LPSECURITY_ATTRIBUTES sa=0, int pipe_mode=PIPE_READMODE_MESSAGE|PIPE_WAIT)
int connect (ACE_SPIPE_Stream &new_io, const ACE_SPIPE_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, LPSECURITY_ATTRIBUTES sa=0, int pipe_mode=PIPE_READMODE_MESSAGE|PIPE_WAIT)
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 <ACE_SPIPE_Stream>. On Windows this is mapped to Named Pipes, whereas on UNIX it is mapped to STREAM pipes.

Definition at line 31 of file SPIPE_Connector.h.


Member Typedef Documentation

typedef ACE_SPIPE_Addr ACE_SPIPE_Connector::PEER_ADDR
 

Definition at line 98 of file SPIPE_Connector.h.

typedef ACE_SPIPE_Stream ACE_SPIPE_Connector::PEER_STREAM
 

Definition at line 99 of file SPIPE_Connector.h.


Constructor & Destructor Documentation

ACE_SPIPE_Connector::ACE_SPIPE_Connector void   
 

Default constructor.

Definition at line 42 of file SPIPE_Connector.cpp.

References ACE_TRACE.

00043 {
00044   ACE_TRACE ("ACE_SPIPE_Connector::ACE_SPIPE_Connector");
00045 }

ACE_SPIPE_Connector::ACE_SPIPE_Connector ACE_SPIPE_Stream   new_io,
const ACE_SPIPE_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,
LPSECURITY_ATTRIBUTES    sa = 0,
int    pipe_mode = PIPE_READMODE_MESSAGE|PIPE_WAIT
 

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. The <flags> and <perms> arguments are passed down to the <open> method. The <pipe_mode> argument is only used in NT and is used to establish the NT pipe mode.

Definition at line 18 of file SPIPE_Connector.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, connect, ETIME, EWOULDBLOCK, ACE_SPIPE_Addr::get_path_name, and LM_ERROR.

00027 {
00028   ACE_TRACE ("ACE_SPIPE_Connector::ACE_SPIPE_Connector");
00029   if (this->connect (new_io, remote_sap, timeout, local_sap,
00030                      reuse_addr, flags, perms, sa, pipe_mode) == -1
00031       && timeout != 0 && !(errno == EWOULDBLOCK || errno == ETIME))
00032     ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("address %s, %p\n"),
00033                remote_sap.get_path_name (), ACE_LIB_TEXT ("ACE_SPIPE_Connector")));
00034 }


Member Function Documentation

int ACE_SPIPE_Connector::connect ACE_SPIPE_Stream   new_io,
const ACE_SPIPE_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,
LPSECURITY_ATTRIBUTES    sa = 0,
int    pipe_mode = PIPE_READMODE_MESSAGE|PIPE_WAIT
 

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. The <flags> and <perms> arguments are passed down to the <open> method. The <pipe_mode> argument is only used in NT and is used to establish the NT pipe mode.

Definition at line 48 of file SPIPE_Connector.cpp.

References ACE_CLR_BITS, ACE_TRACE, ACE_OS::close, ETIMEDOUT, EWOULDBLOCK, ACE_SPIPE_Addr::get_path_name, ACE_OS::gettimeofday, ACE_Handle_Ops::handle_timed_open, ACE_Time_Value::msec, ACE_OS::open, ACE_SPIPE_Stream::remote_addr_, ACE_IPC_SAP::set_handle, and ACE_Time_Value::zero.

Referenced by ACE_SPIPE_Connector.

00057 {
00058   ACE_TRACE ("ACE_SPIPE_Connector::connect");
00059   // Make darn sure that the O_CREAT flag is not set!
00060 #if ! defined (ACE_PSOS_DIAB_MIPS)
00061   ACE_CLR_BITS (flags, O_CREAT);
00062 # endif /* !ACE_PSOS_DIAB_MIPS */
00063 
00064   ACE_HANDLE handle;
00065 
00066   ACE_UNUSED_ARG (pipe_mode);
00067 #if defined (ACE_WIN32) && \
00068    !defined (ACE_HAS_PHARLAP) && !defined (ACE_HAS_WINCE)
00069   // We need to allow for more than one attempt to connect,
00070   // calculate the absolute time at which we give up.
00071   ACE_Time_Value absolute_time;
00072   if (timeout != 0)
00073     absolute_time = ACE_OS::gettimeofday () + *timeout;
00074 
00075   // Loop until success or failure.
00076   for (;;)
00077     {
00078       handle = ACE_OS::open (remote_sap.get_path_name(), flags, perms, sa);
00079       if (handle != ACE_INVALID_HANDLE)
00080         // Success!
00081         break;
00082 
00083       // Check if we have a busy pipe condition.
00084       if (::GetLastError() != ERROR_PIPE_BUSY)
00085         // Nope, this is a failure condition.
00086         break;
00087 
00088       // This will hold the time out value used in the ::WaitNamedPipe
00089       // call.
00090       DWORD time_out_value;
00091 
00092       // Check if we are to block until we connect.
00093       if (timeout == 0)
00094         // Wait for as long as it takes.
00095         time_out_value = NMPWAIT_WAIT_FOREVER;
00096       else
00097         {
00098           // Calculate the amount of time left to wait.
00099           ACE_Time_Value relative_time (absolute_time - ACE_OS::gettimeofday ());
00100           // Check if we have run out of time.
00101           if (relative_time <= ACE_Time_Value::zero)
00102             {
00103               // Mimick the errno value returned by
00104               // ACE_Handle_Ops::handle_timed_open.
00105               if (*timeout == ACE_Time_Value::zero)
00106                 errno = EWOULDBLOCK;
00107               else
00108                 errno = ETIMEDOUT;
00109               // Exit the connect loop with the failure.
00110               break;
00111             }
00112           // Get the amount of time remaining for ::WaitNamedPipe.
00113           time_out_value = relative_time.msec ();
00114 
00115         }
00116 
00117       // Wait for the named pipe to become available.
00118       ACE_TEXT_WaitNamedPipe (remote_sap.get_path_name (),
00119                               time_out_value);
00120 
00121       // Regardless of the return value, we'll do one more attempt to
00122       // connect to see if it is now available and to return
00123       // consistent error values.
00124     }
00125 
00126   // Set named pipe mode if we have a valid handle.
00127   if (handle != ACE_INVALID_HANDLE)
00128     {
00129       // Check if we are changing the pipe mode from the default.
00130       if (pipe_mode != (PIPE_READMODE_BYTE | PIPE_WAIT))
00131         {
00132           DWORD dword_pipe_mode = pipe_mode;
00133           if (!::SetNamedPipeHandleState (handle,
00134                                           &dword_pipe_mode,
00135                                           0,
00136                                           0))
00137             {
00138               // We were not able to put the pipe into the requested
00139               // mode.
00140               ACE_OS::close (handle);
00141               handle = ACE_INVALID_HANDLE;
00142             }
00143         }
00144     }
00145 #else /* ACE_WIN32 && !ACE_HAS_PHARLAP */
00146   handle = ACE_Handle_Ops::handle_timed_open (timeout,
00147                                               remote_sap.get_path_name (),
00148                                               flags, perms, sa);
00149 #endif /* !ACE_WIN32 || ACE_HAS_PHARLAP || ACE_HAS_WINCE */
00150 
00151   new_io.set_handle (handle);
00152   new_io.remote_addr_ = remote_sap; // class copy.
00153 
00154   return handle == ACE_INVALID_HANDLE ? -1 : 0;
00155 }

void ACE_SPIPE_Connector::dump void    const
 

Dump the state of an object.

Definition at line 37 of file SPIPE_Connector.cpp.

References ACE_TRACE.

00038 {
00039   ACE_TRACE ("ACE_SPIPE_Connector::dump");
00040 }

ASYS_INLINE int ACE_SPIPE_Connector::reset_new_handle ACE_HANDLE    handle
 

Resets any event associations on this handle.

Definition at line 7 of file SPIPE_Connector.i.

00008 {
00009   ACE_UNUSED_ARG (handle);
00010   // Nothing to do here since the handle is not a socket
00011   return 0;
00012 }


Member Data Documentation

ACE_SPIPE_Connector::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 105 of file SPIPE_Connector.h.


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