1 // $Id: UPIPE_Connector.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #include "ace/UPIPE_Connector.h"
5 ACE_RCSID(ace
, UPIPE_Connector
, "$Id: UPIPE_Connector.cpp 80826 2008-03-04 14:51:23Z wotte $")
7 #if defined (ACE_HAS_THREADS)
9 #include "ace/Handle_Ops.h"
10 #include "ace/OS_NS_unistd.h"
11 #include "ace/OS_NS_stropts.h"
13 #if !defined (__ACE_INLINE__)
14 #include "ace/UPIPE_Connector.inl"
15 #endif /* __ACE_INLINE__ */
17 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
19 ACE_ALLOC_HOOK_DEFINE(ACE_UPIPE_Connector
)
22 ACE_UPIPE_Connector::dump (void) const
24 #if defined (ACE_HAS_DUMP)
25 ACE_TRACE ("ACE_UPIPE_Connector::dump");
26 #endif /* ACE_HAS_DUMP */
29 ACE_UPIPE_Connector::ACE_UPIPE_Connector (void)
31 ACE_TRACE ("ACE_UPIPE_Connector::ACE_UPIPE_Connector");
35 ACE_UPIPE_Connector::connect (ACE_UPIPE_Stream
&new_stream
,
36 const ACE_UPIPE_Addr
&addr
,
37 ACE_Time_Value
*timeout
,
38 const ACE_Addr
& /* local_sap */,
43 ACE_TRACE ("ACE_UPIPE_Connector::connect");
44 ACE_ASSERT (new_stream
.get_handle () == ACE_INVALID_HANDLE
);
46 ACE_HANDLE handle
= ACE::handle_timed_open (timeout
,
47 addr
.get_path_name (),
50 if (handle
== ACE_INVALID_HANDLE
)
52 #if !defined (ACE_WIN32)
53 else if (ACE_OS::isastream (handle
) != 1)
56 else // We're connected!
58 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex
, ace_mon
, new_stream
.lock_
, -1));
60 ACE_UPIPE_Stream
*ustream
= &new_stream
;
62 new_stream
.set_handle (handle
);
63 new_stream
.remote_addr_
= addr
; // class copy.
64 new_stream
.reference_count_
++;
66 // Now send the address of our ACE_UPIPE_Stream over this pipe
67 // to our corresponding ACE_UPIPE_Acceptor, so he may link the
69 ssize_t result
= ACE_OS::write (handle
,
70 (const char *) &ustream
,
74 ACE_TEXT ("ACE_UPIPE_Connector %p\n"),
75 ACE_TEXT ("write to pipe failed")));
77 // Wait for confirmation of stream linking.
78 ACE_Message_Block
*mb_p
= 0;
80 // Our part is done, wait for server to confirm connection.
81 result
= new_stream
.recv (mb_p
, 0);
83 // Do *not* coalesce the following two checks for result == -1.
84 // They perform different checks and cannot be merged.
87 ACE_TEXT ("ACE_UPIPE_Connector %p\n"),
88 ACE_TEXT ("no confirmation from server")));
90 // Close down the new_stream at this point in order to
91 // conserve handles. Note that we don't need the SPIPE
92 // connection anymore since we're linked via the Message_Queue
94 new_stream
.ACE_SPIPE::close ();
95 return static_cast<int> (result
);
99 ACE_END_VERSIONED_NAMESPACE_DECL
101 #endif /* ACE_HAS_THREADS */