Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / UPIPE_Acceptor.cpp
blob686fad0c8119aea5b3e5d9a97c602387bce56c46
1 #include "ace/UPIPE_Acceptor.h"
3 #if defined (ACE_HAS_THREADS)
5 #include "ace/OS_NS_unistd.h"
7 #if !defined (__ACE_INLINE__)
8 #include "ace/UPIPE_Acceptor.inl"
9 #endif /* __ACE_INLINE__ */
11 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
13 ACE_ALLOC_HOOK_DEFINE(ACE_UPIPE_Acceptor)
15 void
16 ACE_UPIPE_Acceptor::dump () const
18 #if defined (ACE_HAS_DUMP)
19 ACE_TRACE ("ACE_UPIPE_Acceptor::dump");
20 #endif /* ACE_HAS_DUMP */
23 /* Do nothing routine for constructor. */
25 ACE_UPIPE_Acceptor::ACE_UPIPE_Acceptor ()
26 : mb_ (sizeof (ACE_UPIPE_Stream *))
28 ACE_TRACE ("ACE_UPIPE_Acceptor::ACE_UPIPE_Acceptor");
31 ACE_UPIPE_Acceptor::~ACE_UPIPE_Acceptor ()
33 ACE_TRACE ("ACE_UPIPE_Acceptor::~ACE_UPIPE_Acceptor");
36 // General purpose routine for performing server ACE_UPIPE.
37 int
38 ACE_UPIPE_Acceptor::open (const ACE_UPIPE_Addr &local_addr,
39 int reuse_addr)
41 ACE_TRACE ("ACE_UPIPE_Acceptor::open");
42 return this->ACE_SPIPE_Acceptor::open (local_addr, reuse_addr);
45 int
46 ACE_UPIPE_Acceptor::close ()
48 ACE_TRACE ("ACE_UPIPE_Acceptor::close");
49 return this->ACE_SPIPE_Acceptor::close ();
52 // General purpose routine for accepting new connections.
53 ACE_UPIPE_Acceptor::ACE_UPIPE_Acceptor (const ACE_UPIPE_Addr &local_addr,
54 int reuse_addr)
55 : mb_ (sizeof (ACE_UPIPE_Stream *))
57 ACE_TRACE ("ACE_UPIPE_Acceptor::ACE_UPIPE_Acceptor");
59 if (this->open (local_addr, reuse_addr) == -1)
60 ACELIB_ERROR ((LM_ERROR,
61 ACE_TEXT ("%p\n"),
62 ACE_TEXT ("ACE_UPIPE_Acceptor")));
65 int
66 ACE_UPIPE_Acceptor::accept (ACE_UPIPE_Stream &new_stream,
67 ACE_UPIPE_Addr *remote_addr,
68 ACE_Time_Value *timeout,
69 bool restart,
70 bool reset_new_handle)
72 ACE_TRACE ("ACE_UPIPE_Acceptor::accept");
73 ACE_UNUSED_ARG (reset_new_handle);
75 ACE_SPIPE_Stream new_io;
77 if (this->ACE_SPIPE_Acceptor::accept (new_io, remote_addr,
78 timeout, restart) == -1)
79 return -1;
80 else
82 ACE_UPIPE_Stream *remote_stream = 0;
84 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, new_stream.lock_, -1));
86 new_stream.set_handle (new_io.get_handle ());
87 new_stream.reference_count_++;
89 // Transfer address ownership.
90 new_io.get_local_addr (new_stream.local_addr_);
91 new_io.get_remote_addr (new_stream.remote_addr_);
93 // Now that we got the handle, we'll read the address of the
94 // connector-side ACE_UPIPE_Stream out of the pipe and link that
95 // ACE_UPIPE_Stream to our ACE_UPIPE_Stream.
97 if (ACE_OS::read (new_stream.get_handle (),
98 (char *) &remote_stream,
99 sizeof remote_stream) == -1)
100 ACELIB_ERROR ((LM_ERROR,
101 ACE_TEXT ("ACE_UPIPE_Acceptor: %p\n"),
102 ACE_TEXT ("read stream address failed")));
103 else if (new_stream.stream_.link (remote_stream->stream_) == -1)
104 ACELIB_ERROR ((LM_ERROR,
105 ACE_TEXT ("ACE_UPIPE_Acceptor: %p\n"),
106 ACE_TEXT ("link streams failed")));
107 // Send a message over the new streampipe to confirm acceptance.
108 else if (new_stream.send (&mb_, 0) == -1)
109 ACELIB_ERROR ((LM_ERROR,
110 ACE_TEXT ("ACE_UPIPE_Acceptor: %p\n"),
111 ACE_TEXT ("linked stream.put failed")));
113 // Close down the new_stream at this point in order to conserve
114 // handles. Note that we don't need the SPIPE connection
115 // anymore since we're now linked via the <Message_Queue>.
116 new_stream.ACE_SPIPE::close ();
117 return 0;
121 ACE_END_VERSIONED_NAMESPACE_DECL
123 #endif /* ACE_HAS_THREADS */