Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / ace / UPIPE_Connector.cpp
blob144c1502a33a4a02958238e0d43931a153c362a3
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)
19 void
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");
32 int
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 */,
37 int /* reuse_addr */,
38 int flags,
39 int perms)
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 (),
46 flags, perms);
48 if (handle == ACE_INVALID_HANDLE)
49 return -1;
50 #if !defined (ACE_WIN32)
51 else if (ACE_OS::isastream (handle) != 1)
52 return -1;
53 #endif
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
66 // two streams.
67 ssize_t result = ACE_OS::write (handle,
68 (const char *) &ustream,
69 sizeof ustream);
70 if (result == -1)
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.
83 if (result == -1)
84 ACELIB_ERROR ((LM_ERROR,
85 ACE_TEXT ("ACE_UPIPE_Connector %p\n"),
86 ACE_TEXT ("no confirmation from server")));
87 else
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
91 // now.
92 new_stream.ACE_SPIPE::close ();
93 return static_cast<int> (result);
97 ACE_END_VERSIONED_NAMESPACE_DECL
99 #endif /* ACE_HAS_THREADS */