00001 #include "ace_pch.h"
00002
00003
00004
00005 #include "ace/SPIPE_Connector.h"
00006 #include "ace/Log_Msg.h"
00007
00008 #if defined (ACE_LACKS_INLINE_FUNCTIONS)
00009 #include "ace/SPIPE_Connector.i"
00010 #endif
00011
00012 ACE_RCSID(ace, SPIPE_Connector, "$Id: SPIPE_Connector.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:22 chad Exp $")
00013
00014 ACE_ALLOC_HOOK_DEFINE(ACE_SPIPE_Connector)
00015
00016
00017
00018 ACE_SPIPE_Connector::ACE_SPIPE_Connector (ACE_SPIPE_Stream &new_io,
00019 const ACE_SPIPE_Addr &remote_sap,
00020 ACE_Time_Value *timeout,
00021 const ACE_Addr & local_sap,
00022 int reuse_addr,
00023 int flags,
00024 int perms,
00025 LPSECURITY_ATTRIBUTES sa,
00026 int pipe_mode)
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 }
00035
00036 void
00037 ACE_SPIPE_Connector::dump (void) const
00038 {
00039 ACE_TRACE ("ACE_SPIPE_Connector::dump");
00040 }
00041
00042 ACE_SPIPE_Connector::ACE_SPIPE_Connector (void)
00043 {
00044 ACE_TRACE ("ACE_SPIPE_Connector::ACE_SPIPE_Connector");
00045 }
00046
00047 int
00048 ACE_SPIPE_Connector::connect (ACE_SPIPE_Stream &new_io,
00049 const ACE_SPIPE_Addr &remote_sap,
00050 ACE_Time_Value *timeout,
00051 const ACE_Addr & ,
00052 int ,
00053 int flags,
00054 int perms,
00055 LPSECURITY_ATTRIBUTES sa,
00056 int pipe_mode)
00057 {
00058 ACE_TRACE ("ACE_SPIPE_Connector::connect");
00059
00060 #if ! defined (ACE_PSOS_DIAB_MIPS)
00061 ACE_CLR_BITS (flags, O_CREAT);
00062 # endif
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
00070
00071 ACE_Time_Value absolute_time;
00072 if (timeout != 0)
00073 absolute_time = ACE_OS::gettimeofday () + *timeout;
00074
00075
00076 for (;;)
00077 {
00078 handle = ACE_OS::open (remote_sap.get_path_name(), flags, perms, sa);
00079 if (handle != ACE_INVALID_HANDLE)
00080
00081 break;
00082
00083
00084 if (::GetLastError() != ERROR_PIPE_BUSY)
00085
00086 break;
00087
00088
00089
00090 DWORD time_out_value;
00091
00092
00093 if (timeout == 0)
00094
00095 time_out_value = NMPWAIT_WAIT_FOREVER;
00096 else
00097 {
00098
00099 ACE_Time_Value relative_time (absolute_time - ACE_OS::gettimeofday ());
00100
00101 if (relative_time <= ACE_Time_Value::zero)
00102 {
00103
00104
00105 if (*timeout == ACE_Time_Value::zero)
00106 errno = EWOULDBLOCK;
00107 else
00108 errno = ETIMEDOUT;
00109
00110 break;
00111 }
00112
00113 time_out_value = relative_time.msec ();
00114
00115 }
00116
00117
00118 ACE_TEXT_WaitNamedPipe (remote_sap.get_path_name (),
00119 time_out_value);
00120
00121
00122
00123
00124 }
00125
00126
00127 if (handle != ACE_INVALID_HANDLE)
00128 {
00129
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
00139
00140 ACE_OS::close (handle);
00141 handle = ACE_INVALID_HANDLE;
00142 }
00143 }
00144 }
00145 #else
00146 handle = ACE_Handle_Ops::handle_timed_open (timeout,
00147 remote_sap.get_path_name (),
00148 flags, perms, sa);
00149 #endif
00150
00151 new_io.set_handle (handle);
00152 new_io.remote_addr_ = remote_sap;
00153
00154 return handle == ACE_INVALID_HANDLE ? -1 : 0;
00155 }