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 Member Functions

 ACE_SPIPE_Connector (void)
 Default constructor.
 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.
void dump (void) const
 Dump the state of an object.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


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 34 of file SPIPE_Connector.h.


Member Typedef Documentation

typedef ACE_SPIPE_Addr ACE_SPIPE_Connector::PEER_ADDR

Definition at line 101 of file SPIPE_Connector.h.

typedef ACE_SPIPE_Stream ACE_SPIPE_Connector::PEER_STREAM

Definition at line 102 of file SPIPE_Connector.h.


Constructor & Destructor Documentation

ACE_SPIPE_Connector::ACE_SPIPE_Connector ( void   ) 

Default constructor.

Definition at line 47 of file SPIPE_Connector.cpp.

References ACE_TRACE.

00048 {
00049   ACE_TRACE ("ACE_SPIPE_Connector::ACE_SPIPE_Connector");
00050 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL 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 21 of file SPIPE_Connector.cpp.

References ACE_ERROR, ACE_TEXT, ACE_TRACE, and LM_ERROR.

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


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 53 of file SPIPE_Connector.cpp.

References ACE_CLR_BITS, ACE_TRACE, ACE_OS::close(), ACE_SPIPE_Addr::get_path_name(), ACE_OS::gettimeofday(), ACE::handle_timed_open(), ACE_Time_Value::msec(), ACE_OS::open(), PIPE_READMODE_BYTE, PIPE_WAIT, ACE_SPIPE_Stream::remote_addr_, ACE_IPC_SAP::set_handle(), and ACE_Time_Value::zero.

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

void ACE_SPIPE_Connector::dump ( void   )  const

Dump the state of an object.

Definition at line 40 of file SPIPE_Connector.cpp.

References ACE_TRACE.

00041 {
00042 #if defined (ACE_HAS_DUMP)
00043   ACE_TRACE ("ACE_SPIPE_Connector::dump");
00044 #endif /* ACE_HAS_DUMP */
00045 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE_SPIPE_Connector::reset_new_handle ( ACE_HANDLE  handle  ) 

Resets any event associations on this handle.

Definition at line 8 of file SPIPE_Connector.inl.

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


Member Data Documentation

ACE_SPIPE_Connector::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

Definition at line 108 of file SPIPE_Connector.h.


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:39 2010 for ACE by  doxygen 1.4.7