1 #include "tao/Strategies/SCIOP_Transport.h"
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"
13 #include "tao/Transport_Mux_Strategy.h"
14 #include "tao/Wait_Strategy.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
,
28 , connection_handler_ (handler
)
32 TAO_SCIOP_Transport::~TAO_SCIOP_Transport ()
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_
;
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
,
56 bytes_transferred
= retval
;
62 TAO_SCIOP_Transport::recv (char *buf
,
64 const ACE_Time_Value
*max_wait_time
)
66 ssize_t n
= this->connection_handler_
->peer ().recv (buf
,
70 // Do not print the error message if it is a timeout, which could
71 // occur in thread-per-connection.
73 TAO_debug_level
> 4 &&
76 TAOLIB_DEBUG ((LM_DEBUG
,
77 ACE_TEXT ("TAO (%P|%t) - SCIOP_Transport[%d]::recv, ")
78 ACE_TEXT ("read failure - %m\n"),
85 if (errno
== EWOULDBLOCK
)
92 // Most of the errors handling is common for
93 // Now the message has been read
95 // @@ What are the other error handling here??
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)
116 if (this->send_message (stream
,
120 max_wait_time
) == -1)
123 this->first_request_sent();
129 TAO_SCIOP_Transport::send_message (TAO_OutputCDR
&stream
,
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)
141 // This guarantees to send all data (bytes) or return an error.
142 ssize_t n
= this->send_message_shared (stub
,
150 TAOLIB_ERROR ((LM_ERROR
,
151 ACE_TEXT ("TAO (%P|%t) - SCIOP_Transport[%d]::send_message, ")
152 ACE_TEXT (" write failure - %m\n"),
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)
167 cdr
.reset_byte_order (static_cast<int> (byte_order
));
169 IIOP::ListenPointList listen_list
;
170 if (!(cdr
>> listen_list
))
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
);
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
;
193 acceptor
!= ar
.end ();
196 // Check whether it is a SCIOP acceptor
197 if ((*acceptor
)->tag () == this->tag ())
199 if (this->get_listen_point (listen_point_list
,
202 TAOLIB_ERROR ((LM_ERROR
,
203 "TAO (%P|%t) - SCIOP_Transport::set_bidir_info, "
204 "error getting listen_point\n"));
211 // We have the ListenPointList at this point. Create a output CDR
212 // stream at this point
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)
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
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")),
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_
,
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")),
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
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 ();
289 TAO_END_VERSIONED_NAMESPACE_DECL
291 #endif /* TAO_HAS_SCIOP == 1 */