[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / UPIPE_Connector.cpp
blob9b9bfcd38783dfaccad613ac9055d9493a2a2323
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)
21 void
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");
34 int
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 */,
39 int /* reuse_addr */,
40 int flags,
41 int perms)
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 (),
48 flags, perms);
50 if (handle == ACE_INVALID_HANDLE)
51 return -1;
52 #if !defined (ACE_WIN32)
53 else if (ACE_OS::isastream (handle) != 1)
54 return -1;
55 #endif
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
68 // two streams.
69 ssize_t result = ACE_OS::write (handle,
70 (const char *) &ustream,
71 sizeof ustream);
72 if (result == -1)
73 ACE_ERROR ((LM_ERROR,
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.
85 if (result == -1)
86 ACE_ERROR ((LM_ERROR,
87 ACE_TEXT ("ACE_UPIPE_Connector %p\n"),
88 ACE_TEXT ("no confirmation from server")));
89 else
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
93 // now.
94 new_stream.ACE_SPIPE::close ();
95 return static_cast<int> (result);
99 ACE_END_VERSIONED_NAMESPACE_DECL
101 #endif /* ACE_HAS_THREADS */