Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / ace / UPIPE_Acceptor.cpp
blob708c5037fe674b4eb6abe81146730bffb14589cf
1 #include "ace/UPIPE_Acceptor.h"
5 #if defined (ACE_HAS_THREADS)
7 #include "ace/OS_NS_unistd.h"
9 #if !defined (__ACE_INLINE__)
10 #include "ace/UPIPE_Acceptor.inl"
11 #endif /* __ACE_INLINE__ */
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
15 ACE_ALLOC_HOOK_DEFINE(ACE_UPIPE_Acceptor)
17 void
18 ACE_UPIPE_Acceptor::dump (void) const
20 #if defined (ACE_HAS_DUMP)
21 ACE_TRACE ("ACE_UPIPE_Acceptor::dump");
22 #endif /* ACE_HAS_DUMP */
25 /* Do nothing routine for constructor. */
27 ACE_UPIPE_Acceptor::ACE_UPIPE_Acceptor (void)
28 : mb_ (sizeof (ACE_UPIPE_Stream *))
30 ACE_TRACE ("ACE_UPIPE_Acceptor::ACE_UPIPE_Acceptor");
33 ACE_UPIPE_Acceptor::~ACE_UPIPE_Acceptor (void)
35 ACE_TRACE ("ACE_UPIPE_Acceptor::~ACE_UPIPE_Acceptor");
38 // General purpose routine for performing server ACE_UPIPE.
40 int
41 ACE_UPIPE_Acceptor::open (const ACE_UPIPE_Addr &local_addr,
42 int reuse_addr)
44 ACE_TRACE ("ACE_UPIPE_Acceptor::open");
45 return this->ACE_SPIPE_Acceptor::open (local_addr, reuse_addr);
48 int
49 ACE_UPIPE_Acceptor::close (void)
51 ACE_TRACE ("ACE_UPIPE_Acceptor::close");
52 return this->ACE_SPIPE_Acceptor::close ();
55 // General purpose routine for accepting new connections.
57 ACE_UPIPE_Acceptor::ACE_UPIPE_Acceptor (const ACE_UPIPE_Addr &local_addr,
58 int reuse_addr)
59 : mb_ (sizeof (ACE_UPIPE_Stream *))
61 ACE_TRACE ("ACE_UPIPE_Acceptor::ACE_UPIPE_Acceptor");
63 if (this->open (local_addr, reuse_addr) == -1)
64 ACELIB_ERROR ((LM_ERROR,
65 ACE_TEXT ("%p\n"),
66 ACE_TEXT ("ACE_UPIPE_Acceptor")));
69 int
70 ACE_UPIPE_Acceptor::accept (ACE_UPIPE_Stream &new_stream,
71 ACE_UPIPE_Addr *remote_addr,
72 ACE_Time_Value *timeout,
73 bool restart,
74 bool reset_new_handle)
76 ACE_TRACE ("ACE_UPIPE_Acceptor::accept");
77 ACE_UNUSED_ARG (reset_new_handle);
79 ACE_SPIPE_Stream new_io;
81 if (this->ACE_SPIPE_Acceptor::accept (new_io, remote_addr,
82 timeout, restart) == -1)
83 return -1;
84 else
86 ACE_UPIPE_Stream *remote_stream = 0;
88 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, new_stream.lock_, -1));
90 new_stream.set_handle (new_io.get_handle ());
91 new_stream.reference_count_++;
93 // Transfer address ownership.
94 new_io.get_local_addr (new_stream.local_addr_);
95 new_io.get_remote_addr (new_stream.remote_addr_);
97 // Now that we got the handle, we'll read the address of the
98 // connector-side ACE_UPIPE_Stream out of the pipe and link that
99 // ACE_UPIPE_Stream to our ACE_UPIPE_Stream.
101 if (ACE_OS::read (new_stream.get_handle (),
102 (char *) &remote_stream,
103 sizeof remote_stream) == -1)
104 ACELIB_ERROR ((LM_ERROR,
105 ACE_TEXT ("ACE_UPIPE_Acceptor: %p\n"),
106 ACE_TEXT ("read stream address failed")));
107 else if (new_stream.stream_.link (remote_stream->stream_) == -1)
108 ACELIB_ERROR ((LM_ERROR,
109 ACE_TEXT ("ACE_UPIPE_Acceptor: %p\n"),
110 ACE_TEXT ("link streams failed")));
111 // Send a message over the new streampipe to confirm acceptance.
112 else if (new_stream.send (&mb_, 0) == -1)
113 ACELIB_ERROR ((LM_ERROR,
114 ACE_TEXT ("ACE_UPIPE_Acceptor: %p\n"),
115 ACE_TEXT ("linked stream.put failed")));
117 // Close down the new_stream at this point in order to conserve
118 // handles. Note that we don't need the SPIPE connection
119 // anymore since we're now linked via the <Message_Queue>.
120 new_stream.ACE_SPIPE::close ();
121 return 0;
125 ACE_END_VERSIONED_NAMESPACE_DECL
127 #endif /* ACE_HAS_THREADS */