1 #include "ace/UPIPE_Connector.h"
5 #if defined (ACE_HAS_THREADS)
7 #include "ace/Handle_Ops.h"
8 #include "ace/OS_NS_unistd.h"
9 #include "ace/OS_NS_stropts.h"
11 #if !defined (__ACE_INLINE__)
12 #include "ace/UPIPE_Connector.inl"
13 #endif /* __ACE_INLINE__ */
15 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
17 ACE_ALLOC_HOOK_DEFINE(ACE_UPIPE_Connector
)
20 ACE_UPIPE_Connector::dump (void) const
22 #if defined (ACE_HAS_DUMP)
23 ACE_TRACE ("ACE_UPIPE_Connector::dump");
24 #endif /* ACE_HAS_DUMP */
27 ACE_UPIPE_Connector::ACE_UPIPE_Connector (void)
29 ACE_TRACE ("ACE_UPIPE_Connector::ACE_UPIPE_Connector");
33 ACE_UPIPE_Connector::connect (ACE_UPIPE_Stream
&new_stream
,
34 const ACE_UPIPE_Addr
&addr
,
35 ACE_Time_Value
*timeout
,
36 const ACE_Addr
& /* local_sap */,
41 ACE_TRACE ("ACE_UPIPE_Connector::connect");
42 ACE_ASSERT (new_stream
.get_handle () == ACE_INVALID_HANDLE
);
44 ACE_HANDLE handle
= ACE::handle_timed_open (timeout
,
45 addr
.get_path_name (),
48 if (handle
== ACE_INVALID_HANDLE
)
50 #if !defined (ACE_WIN32)
51 else if (ACE_OS::isastream (handle
) != 1)
54 else // We're connected!
56 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex
, ace_mon
, new_stream
.lock_
, -1));
58 ACE_UPIPE_Stream
*ustream
= &new_stream
;
60 new_stream
.set_handle (handle
);
61 new_stream
.remote_addr_
= addr
; // class copy.
62 new_stream
.reference_count_
++;
64 // Now send the address of our ACE_UPIPE_Stream over this pipe
65 // to our corresponding ACE_UPIPE_Acceptor, so he may link the
67 ssize_t result
= ACE_OS::write (handle
,
68 (const char *) &ustream
,
71 ACELIB_ERROR ((LM_ERROR
,
72 ACE_TEXT ("ACE_UPIPE_Connector %p\n"),
73 ACE_TEXT ("write to pipe failed")));
75 // Wait for confirmation of stream linking.
76 ACE_Message_Block
*mb_p
= 0;
78 // Our part is done, wait for server to confirm connection.
79 result
= new_stream
.recv (mb_p
, 0);
81 // Do *not* coalesce the following two checks for result == -1.
82 // They perform different checks and cannot be merged.
84 ACELIB_ERROR ((LM_ERROR
,
85 ACE_TEXT ("ACE_UPIPE_Connector %p\n"),
86 ACE_TEXT ("no confirmation from server")));
88 // Close down the new_stream at this point in order to
89 // conserve handles. Note that we don't need the SPIPE
90 // connection anymore since we're linked via the Message_Queue
92 new_stream
.ACE_SPIPE::close ();
93 return static_cast<int> (result
);
97 ACE_END_VERSIONED_NAMESPACE_DECL
99 #endif /* ACE_HAS_THREADS */