@@ -175,39 +175,16 @@ int RelayHandler::handle_output(ACE_HANDLE)
175
175
176
176
if (!outgoing_.empty ()) {
177
177
const auto & out = outgoing_.front ();
178
+ size_t total_bytes;
178
179
179
- const int BUFFERS_SIZE = 2 ;
180
- iovec buffers[BUFFERS_SIZE];
181
- size_t total_bytes = 0 ;
182
-
183
- int idx = 0 ;
184
- for (ACE_Message_Block* block = out.message_block .get (); block && idx < BUFFERS_SIZE; block = block->cont (), ++idx) {
185
- buffers[idx].iov_base = block->rd_ptr ();
186
- #ifdef _MSC_VER
187
- #pragma warning(push)
188
- // iov_len is 32-bit on 64-bit VC++, but we don't want a cast here
189
- // since on other platforms iov_len is 64-bit
190
- #pragma warning(disable : 4267)
191
- #endif
192
- buffers[idx].iov_len = block->length ();
193
- total_bytes += buffers[idx].iov_len ;
194
- #ifdef _MSC_VER
195
- #pragma warning(pop)
196
- #endif
197
- }
198
-
199
- const auto bytes = socket_.send (buffers, idx, out.address , 0 );
200
-
201
- if (bytes < 0 ) {
180
+ if (send_i (out, total_bytes) < 0 ) {
202
181
HANDLER_ERROR ((LM_ERROR, " (%P|%t) ERROR: RelayHandler::handle_output %C failed to send to %C: %m\n " ,
203
182
name_.c_str (), OpenDDS::DCPS::LogAddr (out.address ).c_str ()));
204
183
const auto new_now = OpenDDS::DCPS::MonotonicTimePoint::now ();
205
- stats_reporter_.dropped_message (
206
- total_bytes, new_now - now, new_now - out.timestamp , now, out.type );
184
+ stats_reporter_.dropped_message (total_bytes, new_now - now, new_now - out.timestamp , now, out.type );
207
185
} else {
208
186
const auto new_now = OpenDDS::DCPS::MonotonicTimePoint::now ();
209
- stats_reporter_.output_message (
210
- total_bytes, new_now - now, new_now - out.timestamp , now, out.type );
187
+ stats_reporter_.output_message (total_bytes, new_now - now, new_now - out.timestamp , now, out.type );
211
188
}
212
189
213
190
outgoing_.pop ();
@@ -225,15 +202,55 @@ void RelayHandler::enqueue_message(const ACE_INET_Addr& addr,
225
202
const OpenDDS::DCPS::MonotonicTimePoint& now,
226
203
MessageType type)
227
204
{
228
- ACE_GUARD (ACE_Thread_Mutex, g, outgoing_mutex_);
205
+ const Element out (addr, msg, now, type);
206
+ if (config_.synchronous_output ()) {
207
+ size_t total_bytes;
208
+
209
+ if (send_i (out, total_bytes) < 0 ) {
210
+ HANDLER_ERROR ((LM_ERROR, " (%P|%t) ERROR: RelayHandler::enqueue_message %C failed to send to %C: %m\n " ,
211
+ name_.c_str (), OpenDDS::DCPS::LogAddr (out.address ).c_str ()));
212
+ stats_reporter_.dropped_message (total_bytes, OpenDDS::DCPS::TimeDuration::zero_value, OpenDDS::DCPS::TimeDuration::zero_value, now, out.type );
213
+ } else {
214
+ stats_reporter_.output_message (total_bytes, OpenDDS::DCPS::TimeDuration::zero_value, OpenDDS::DCPS::TimeDuration::zero_value, now, out.type );
215
+ }
216
+
217
+ } else {
218
+ ACE_GUARD (ACE_Thread_Mutex, g, outgoing_mutex_);
219
+
220
+ const auto empty = outgoing_.empty ();
221
+
222
+ outgoing_.push (out);
223
+ stats_reporter_.max_queue_size (outgoing_.size (), now);
224
+ if (empty) {
225
+ reactor ()->register_handler (this , WRITE_MASK);
226
+ }
227
+ }
228
+ }
229
229
230
- const auto empty = outgoing_.empty ();
230
+ ssize_t RelayHandler::send_i (const Element& out,
231
+ size_t & total_bytes)
232
+ {
233
+ const int BUFFERS_SIZE = 2 ;
234
+ iovec buffers[BUFFERS_SIZE];
235
+ total_bytes = 0 ;
231
236
232
- outgoing_.push (Element (addr, msg, now, type));
233
- stats_reporter_.max_queue_size (outgoing_.size (), now);
234
- if (empty) {
235
- reactor ()->register_handler (this , WRITE_MASK);
237
+ int idx = 0 ;
238
+ for (ACE_Message_Block* block = out.message_block .get (); block && idx < BUFFERS_SIZE; block = block->cont (), ++idx) {
239
+ buffers[idx].iov_base = block->rd_ptr ();
240
+ #ifdef _MSC_VER
241
+ #pragma warning(push)
242
+ // iov_len is 32-bit on 64-bit VC++, but we don't want a cast here
243
+ // since on other platforms iov_len is 64-bit
244
+ #pragma warning(disable : 4267)
245
+ #endif
246
+ buffers[idx].iov_len = block->length ();
247
+ total_bytes += buffers[idx].iov_len ;
248
+ #ifdef _MSC_VER
249
+ #pragma warning(pop)
250
+ #endif
236
251
}
252
+
253
+ return socket_.send (buffers, idx, out.address , 0 );
237
254
}
238
255
239
256
VerticalHandler::VerticalHandler (const Config& config,
@@ -595,7 +612,7 @@ CORBA::ULong VerticalHandler::send(GuidAddrSet::Proxy& proxy,
595
612
CORBA::ULong sent = 0 ;
596
613
for (const auto & addr : address_set) {
597
614
if (addr != horizontal_address_) {
598
- horizontal_handler_->enqueue_message (addr, to_partitions, to_guids, msg, now);
615
+ horizontal_handler_->enqueue_or_send_message (addr, to_partitions, to_guids, msg, now);
599
616
++sent;
600
617
} else {
601
618
// Local recipients.
@@ -641,8 +658,6 @@ size_t VerticalHandler::send(const ACE_INET_Addr& addr,
641
658
message.block = block.get ();
642
659
serializer << message;
643
660
RelayHandler::enqueue_message (addr, block, now, type);
644
- const auto new_now = OpenDDS::DCPS::MonotonicTimePoint::now ();
645
- stats_reporter_.output_message (length, new_now - now, new_now - now, now, type);
646
661
return length;
647
662
}
648
663
@@ -663,11 +678,11 @@ HorizontalHandler::HorizontalHandler(const Config& config,
663
678
, vertical_handler_(nullptr )
664
679
{}
665
680
666
- void HorizontalHandler::enqueue_message (const ACE_INET_Addr& addr,
667
- const StringSet& to_partitions,
668
- const GuidSet& to_guids,
669
- const OpenDDS::DCPS::Lockable_Message_Block_Ptr& msg,
670
- const OpenDDS::DCPS::MonotonicTimePoint& now)
681
+ void HorizontalHandler::enqueue_or_send_message (const ACE_INET_Addr& addr,
682
+ const StringSet& to_partitions,
683
+ const GuidSet& to_guids,
684
+ const OpenDDS::DCPS::Lockable_Message_Block_Ptr& msg,
685
+ const OpenDDS::DCPS::MonotonicTimePoint& now)
671
686
{
672
687
using namespace OpenDDS ::DCPS;
673
688
@@ -984,7 +999,7 @@ int SpdpHandler::handle_exception(ACE_HANDLE /*fd*/)
984
999
const auto pos = proxy.find (fan_in_from_guid);
985
1000
if (pos != proxy.end () && pos->second .spdp_message ) {
986
1001
// Send the SPDP message horizontally. We may be sending to ourselves which is okay.
987
- horizontal_handler_->enqueue_message (fan_in_replay_address, StringSet (), fan_in_to_guid_set, pos->second .spdp_message , now);
1002
+ horizontal_handler_->enqueue_or_send_message (fan_in_replay_address, StringSet (), fan_in_to_guid_set, pos->second .spdp_message , now);
988
1003
}
989
1004
}
990
1005
0 commit comments