1 #include "tao/Strategies/DIOP_Transport.h"
3 #if defined (TAO_HAS_DIOP) && (TAO_HAS_DIOP != 0)
5 #include "tao/Strategies/DIOP_Connection_Handler.h"
6 #include "tao/Strategies/DIOP_Acceptor.h"
7 #include "tao/Strategies/DIOP_Profile.h"
8 #include "tao/Acceptor_Registry.h"
9 #include "tao/operation_details.h"
10 #include "tao/Timeprobe.h"
12 #include "tao/Transport_Mux_Strategy.h"
13 #include "tao/Wait_Strategy.h"
15 #include "tao/ORB_Core.h"
16 #include "tao/debug.h"
17 #include "tao/Resume_Handle.h"
18 #include "tao/GIOP_Message_Base.h"
20 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
22 TAO_DIOP_Transport::TAO_DIOP_Transport (TAO_DIOP_Connection_Handler
*handler
,
23 TAO_ORB_Core
*orb_core
)
24 : TAO_Transport (TAO_TAG_DIOP_PROFILE
,
27 , connection_handler_ (handler
)
32 TAO_DIOP_Transport::event_handler_i ()
34 return this->connection_handler_
;
37 TAO_Connection_Handler
*
38 TAO_DIOP_Transport::connection_handler_i ()
40 return this->connection_handler_
;
44 TAO_DIOP_Transport::send (iovec
*iov
, int iovcnt
,
45 size_t &bytes_transferred
,
46 const ACE_Time_Value
*)
48 const ACE_INET_Addr
&addr
= this->connection_handler_
->addr ();
50 ssize_t bytes_to_send
= 0;
51 for (int i
= 0; i
< iovcnt
; i
++)
52 bytes_to_send
+= iov
[i
].iov_len
;
54 this->connection_handler_
->peer ().send (iov
, iovcnt
, addr
);
57 // Always return a positive number of bytes sent, as we do
58 // not handle sending errors in DIOP.
60 bytes_transferred
= bytes_to_send
;
66 TAO_DIOP_Transport::recv (char *buf
,
68 const ACE_Time_Value
* /* max_wait_time */)
70 ACE_INET_Addr from_addr
;
72 ssize_t
const n
= this->connection_handler_
->peer ().recv (buf
, len
, from_addr
);
74 if (TAO_debug_level
> 0)
76 TAOLIB_DEBUG ((LM_DEBUG
,
77 "TAO (%P|%t) - DIOP_Transport::recv, received %d bytes from %C:%d %d\n",
79 from_addr
.get_host_name (),
80 from_addr
.get_port_number (),
84 // Most of the errors handling is common for
85 // Now the message has been read
86 if (n
== -1 && TAO_debug_level
> 4)
88 TAOLIB_DEBUG ((LM_DEBUG
,
89 ACE_TEXT ("TAO (%P|%t) - DIOP_Transport::recv, %p\n"),
90 ACE_TEXT ("TAO - read message failure ")
91 ACE_TEXT ("recv ()\n")));
97 if (errno
== EWOULDBLOCK
)
102 // @@ What are the other error handling here??
108 // Remember the from addr to eventually use it as remote
109 // addr for the reply.
110 this->connection_handler_
->addr (from_addr
);
116 TAO_DIOP_Transport::handle_input (TAO_Resume_Handle
&rh
,
117 ACE_Time_Value
*max_wait_time
)
119 // If there are no messages then we can go ahead to read from the
120 // handle for further reading..
122 // The buffer on the stack which will be used to hold the input
124 char buf
[ACE_MAX_DGRAM_SIZE
+ ACE_CDR::MAX_ALIGNMENT
];
126 #if defined (ACE_INITIALIZE_MEMORY_BEFORE_USE)
127 (void) ACE_OS::memset (buf
,
130 #endif /* ACE_INITIALIZE_MEMORY_BEFORE_USE */
132 // Create a data block
133 ACE_Data_Block
db (sizeof (buf
),
134 ACE_Message_Block::MB_DATA
,
136 this->orb_core_
->input_cdr_buffer_allocator (),
137 this->orb_core_
->locking_strategy (),
138 ACE_Message_Block::DONT_DELETE
,
139 this->orb_core_
->input_cdr_dblock_allocator ());
141 // Create a message block
142 ACE_Message_Block
message_block (&db
,
143 ACE_Message_Block::DONT_DELETE
,
144 this->orb_core_
->input_cdr_msgblock_allocator ());
147 // Align the message block
148 ACE_CDR::mb_align (&message_block
);
151 // Read the message into the message block that we have created on
153 ssize_t n
= this->recv (message_block
.rd_ptr (),
154 message_block
.space (),
157 // If there is an error return to the reactor..
162 this->tms_
->connection_closed ();
165 return static_cast<int> (n
);
168 // Set the write pointer in the stack buffer
169 message_block
.wr_ptr (n
);
171 // Make a node of the message block..
172 TAO_Queued_Data
qd (&message_block
);
173 size_t mesg_length
= 0;
175 // Parse the incoming message for validity. The check needs to be
176 // performed by the messaging objects.
177 if (this->messaging_object ()->parse_next_message (qd
, mesg_length
) == -1)
180 if (qd
.missing_data () == TAO_MISSING_DATA_UNDEFINED
)
182 // parse/marshal error
186 if (message_block
.length () > mesg_length
)
188 // we read too much data
192 // NOTE: We are not performing any queueing nor any checking for
193 // missing data. We are assuming that ALL the data would be got in a
196 // Process the message
197 return this->process_parsed_messages (&qd
, rh
);
202 TAO_DIOP_Transport::register_handler ()
206 // We do never register register the handler with the reactor
207 // as we never need to be informed about any incoming data,
208 // assuming we only use one-ways.
209 // If we would register and ICMP Messages would arrive, e.g
210 // due to a not reachable server, we would get informed - as this
211 // disturbs the general DIOP assumptions of not being
212 // interested in any network failures, we ignore ICMP messages.
218 TAO_DIOP_Transport::send_request (TAO_Stub
*stub
,
219 TAO_ORB_Core
*orb_core
,
220 TAO_OutputCDR
&stream
,
221 TAO_Message_Semantics message_semantics
,
222 ACE_Time_Value
*max_wait_time
)
224 if (this->ws_
->sending_request (orb_core
, message_semantics
) == -1)
229 if (this->send_message (stream
,
233 max_wait_time
) == -1)
238 this->first_request_sent ();
244 TAO_DIOP_Transport::send_message (TAO_OutputCDR
&stream
,
246 TAO_ServerRequest
*request
,
247 TAO_Message_Semantics message_semantics
,
248 ACE_Time_Value
*max_wait_time
)
250 // Format the message in the stream first
251 if (this->messaging_object ()->format_message (stream
, stub
, request
) != 0)
256 // Strictly speaking, should not need to loop here because the
257 // socket never gets set to a nonblocking mode ... some Linux
258 // versions seem to need it though. Leaving it costs little.
260 // This guarantees to send all data (bytes) or return an error.
261 ssize_t
const n
= this->send_message_shared (stub
,
269 TAOLIB_DEBUG ((LM_DEBUG
,
270 ACE_TEXT ("TAO (%P|%t) - DIOP_Transport::send_message, ")
271 ACE_TEXT ("closing transport %d after fault %p\n"),
273 ACE_TEXT ("send_message ()\n")));
281 TAO_END_VERSIONED_NAMESPACE_DECL
283 #endif /* TAO_HAS_DIOP && TAO_HAS_DIOP != 0 */