Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tao / Strategies / SCIOP_Transport.cpp
blobaadbe366401caceef000682b378a25a441241d2a
1 #include "tao/Strategies/SCIOP_Transport.h"
3 #if TAO_HAS_SCIOP == 1
5 #include "tao/Strategies/SCIOP_Connection_Handler.h"
6 #include "tao/Strategies/SCIOP_Acceptor.h"
7 #include "tao/Strategies/SCIOP_Profile.h"
8 #include "tao/Acceptor_Registry.h"
9 #include "tao/Thread_Lane_Resources.h"
10 #include "tao/operation_details.h"
11 #include "tao/Timeprobe.h"
12 #include "tao/CDR.h"
13 #include "tao/Transport_Mux_Strategy.h"
14 #include "tao/Wait_Strategy.h"
15 #include "tao/Stub.h"
16 #include "tao/ORB_Core.h"
17 #include "tao/debug.h"
18 #include "tao/GIOP_Message_Base.h"
19 #include "tao/Protocols_Hooks.h"
20 #include "tao/Adapter.h"
22 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
24 TAO_SCIOP_Transport::TAO_SCIOP_Transport (TAO_SCIOP_Connection_Handler *handler,
25 TAO_ORB_Core *orb_core)
26 : TAO_Transport (TAO_TAG_SCIOP_PROFILE,
27 orb_core)
28 , connection_handler_ (handler)
32 TAO_SCIOP_Transport::~TAO_SCIOP_Transport ()
36 ACE_Event_Handler *
37 TAO_SCIOP_Transport::event_handler_i ()
39 return this->connection_handler_;
42 TAO_Connection_Handler *
43 TAO_SCIOP_Transport::connection_handler_i ()
45 return this->connection_handler_;
48 ssize_t
49 TAO_SCIOP_Transport::send (iovec *iov, int iovcnt,
50 size_t &bytes_transferred,
51 const ACE_Time_Value *max_wait_time)
53 ssize_t retval = this->connection_handler_->peer ().sendv (iov, iovcnt,
54 max_wait_time);
55 if (retval > 0)
56 bytes_transferred = retval;
58 return retval;
61 ssize_t
62 TAO_SCIOP_Transport::recv (char *buf,
63 size_t len,
64 const ACE_Time_Value *max_wait_time)
66 ssize_t n = this->connection_handler_->peer ().recv (buf,
67 len,
68 max_wait_time);
70 // Do not print the error message if it is a timeout, which could
71 // occur in thread-per-connection.
72 if (n == -1 &&
73 TAO_debug_level > 4 &&
74 errno != ETIME)
76 TAOLIB_DEBUG ((LM_DEBUG,
77 ACE_TEXT ("TAO (%P|%t) - SCIOP_Transport[%d]::recv, ")
78 ACE_TEXT ("read failure - %m\n"),
79 this->id ()));
82 // Error handling
83 if (n == -1)
85 if (errno == EWOULDBLOCK)
86 return 0;
89 return -1;
92 // Most of the errors handling is common for
93 // Now the message has been read
95 // @@ What are the other error handling here??
96 else if (n == 0)
98 return -1;
101 return n;
105 TAO_SCIOP_Transport::send_request (TAO_Stub *stub,
106 TAO_ORB_Core *orb_core,
107 TAO_OutputCDR &stream,
108 TAO_Message_Semantics message_semantics,
109 ACE_Time_Value *max_wait_time)
111 if (this->ws_->sending_request (orb_core,
112 message_semantics) == -1)
114 return -1;
116 if (this->send_message (stream,
117 stub,
119 message_semantics,
120 max_wait_time) == -1)
121 return -1;
123 this->first_request_sent();
125 return 0;
129 TAO_SCIOP_Transport::send_message (TAO_OutputCDR &stream,
130 TAO_Stub *stub,
131 TAO_ServerRequest *request,
132 TAO_Message_Semantics message_semantics,
133 ACE_Time_Value *max_wait_time)
135 // Format the message in the stream first
136 if (this->messaging_object ()->format_message (stream, stub, request) != 0)
138 return -1;
141 // This guarantees to send all data (bytes) or return an error.
142 ssize_t n = this->send_message_shared (stub,
143 message_semantics,
144 stream.begin (),
145 max_wait_time);
147 if (n == -1)
149 if (TAO_debug_level)
150 TAOLIB_ERROR ((LM_ERROR,
151 ACE_TEXT ("TAO (%P|%t) - SCIOP_Transport[%d]::send_message, ")
152 ACE_TEXT (" write failure - %m\n"),
153 this->id ()));
154 return -1;
157 return 1;
161 TAO_SCIOP_Transport::tear_listen_point_list (TAO_InputCDR &cdr)
163 CORBA::Boolean byte_order;
164 if ((cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
165 return -1;
167 cdr.reset_byte_order (static_cast<int> (byte_order));
169 IIOP::ListenPointList listen_list;
170 if (!(cdr >> listen_list))
171 return -1;
173 // As we have received a bidirectional information, set the flag to
174 // 1 (i.e., non-originating side)
175 this->bidirectional_flag (0);
177 return this->connection_handler_->process_listen_point_list (listen_list);
180 void
181 TAO_SCIOP_Transport::set_bidir_context_info (TAO_Operation_Details &opdetails)
183 // Get a handle to the acceptor registry
184 TAO_Acceptor_Registry &ar =
185 this->orb_core ()->lane_resources ().acceptor_registry ();
187 // Get the first acceptor in the registry
188 TAO_AcceptorSetIterator acceptor = ar.begin ();
190 IIOP::ListenPointList listen_point_list;
192 for (;
193 acceptor != ar.end ();
194 acceptor++)
196 // Check whether it is a SCIOP acceptor
197 if ((*acceptor)->tag () == this->tag ())
199 if (this->get_listen_point (listen_point_list,
200 *acceptor) == -1)
202 TAOLIB_ERROR ((LM_ERROR,
203 "TAO (%P|%t) - SCIOP_Transport::set_bidir_info, "
204 "error getting listen_point\n"));
206 return;
211 // We have the ListenPointList at this point. Create a output CDR
212 // stream at this point
213 TAO_OutputCDR cdr;
215 // Marshall the information into the stream
216 if ((cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER) == 0)
217 || (cdr << listen_point_list) == 0)
218 return;
220 // Add this info in to the svc_list
221 opdetails.request_service_context ().set_context (IOP::BI_DIR_IIOP, cdr);
225 TAO_SCIOP_Transport::get_listen_point (
226 IIOP::ListenPointList &listen_point_list,
227 TAO_Acceptor *acceptor)
229 TAO_SCIOP_Acceptor *sciop_acceptor =
230 dynamic_cast<TAO_SCIOP_Acceptor *> (acceptor );
232 // Get the array of endpoints serviced by TAO_SCIOP_Acceptor
233 const ACE_INET_Addr *endpoint_addr =
234 sciop_acceptor->endpoints ();
236 // Get the endpoint count
237 size_t count =
238 sciop_acceptor->endpoint_count ();
240 // Get the local address of the connection
241 ACE_INET_Addr local_addr;
243 if (this->connection_handler_->peer ().get_local_addr (local_addr) == -1)
245 TAOLIB_ERROR_RETURN ((LM_ERROR,
246 ACE_TEXT ("(%P|%t) Could not resolve local ")
247 ACE_TEXT ("host address in ")
248 ACE_TEXT ("get_listen_point()\n")),
249 -1);
252 // Note: Looks like there is no point in sending the list of
253 // endpoints on interfaces on which this connection has not
254 // been established. If this is wrong, please correct me.
255 CORBA::String_var local_interface;
257 // Get the hostname for the local address
258 if (sciop_acceptor->hostname (this->orb_core_,
259 local_addr,
260 local_interface.out ()) == -1)
262 TAOLIB_ERROR_RETURN ((LM_ERROR,
263 ACE_TEXT ("(%P|%t) Could not resolve local host")
264 ACE_TEXT (" name\n")),
265 -1);
268 for (size_t index = 0; index != count; index++)
270 if (local_addr.get_ip_address() == endpoint_addr[index].get_ip_address())
272 // Get the count of the number of elements
273 CORBA::ULong const len = listen_point_list.length ();
275 // Increase the length by 1
276 listen_point_list.length (len + 1);
278 // We have the connection and the acceptor endpoint on the
279 // same interface
280 IIOP::ListenPoint &point = listen_point_list[len];
281 point.host = CORBA::string_dup (local_interface.in ());
282 point.port = endpoint_addr[index].get_port_number ();
286 return 1;
289 TAO_END_VERSIONED_NAMESPACE_DECL
291 #endif /* TAO_HAS_SCIOP == 1 */