@@ -127,8 +127,8 @@ TAO_Transport::TAO_Transport (CORBA::ULong tag,
127127 , tail_ (nullptr )
128128 , incoming_message_queue_ (orb_core)
129129 , current_deadline_ (ACE_Time_Value::zero)
130- , flush_timer_id_ (-1 )
131130 , transport_timer_ (this )
131+ , transport_idle_timer_ (this )
132132 , handler_lock_ (orb_core->resource_factory ()->create_cached_connection_lock ())
133133 , id_ ((size_t ) this)
134134 , purging_order_ (0 )
@@ -183,10 +183,12 @@ TAO_Transport::~TAO_Transport ()
183183{
184184 if (TAO_debug_level > 9 )
185185 {
186- TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT (" TAO (%P|%t) - Transport[%d]::~Transport\n " ),
186+ TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT (" TAO (%P|%t) - Transport[%d]::~Transport, start \n " ),
187187 this ->id_ ));
188188 }
189189
190+ this ->cancel_idle_timer ();
191+
190192 delete this ->messaging_object_ ;
191193
192194 delete this ->ws_ ;
@@ -217,6 +219,11 @@ TAO_Transport::~TAO_Transport ()
217219#if TAO_HAS_TRANSPORT_CURRENT == 1
218220 delete this ->stats_ ;
219221#endif /* TAO_HAS_TRANSPORT_CURRENT == 1 */
222+ if (TAO_debug_level > 9 )
223+ {
224+ TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT (" TAO (%P|%t) - Transport[%d]::~Transport, end\n " ),
225+ this ->id_ ));
226+ }
220227}
221228
222229void
@@ -324,6 +331,16 @@ TAO_Transport::register_if_necessary ()
324331void
325332TAO_Transport::close_connection ()
326333{
334+ if (TAO_debug_level > 4 )
335+ {
336+ TAOLIB_DEBUG ((LM_DEBUG,
337+ ACE_TEXT (" TAO (%P|%t) - Transport[%d]::close_connection\n " ),
338+ this ->id ()));
339+ }
340+
341+ // Cancel any pending timer
342+ this ->cancel_idle_timer ();
343+
327344 this ->connection_handler_i ()->close_connection ();
328345}
329346
@@ -375,8 +392,7 @@ TAO_Transport::register_handler ()
375392 this ->ws_ ->is_registered (true );
376393
377394 // Register the handler with the reactor
378- return r->register_handler (this ->event_handler_i (),
379- ACE_Event_Handler::READ_MASK);
395+ return r->register_handler (this ->event_handler_i (), ACE_Event_Handler::READ_MASK);
380396}
381397
382398int
@@ -547,12 +563,24 @@ TAO_Transport::make_idle ()
547563 this ->id ()));
548564 }
549565
550- return this ->transport_cache_manager ().make_idle (this ->cache_map_entry_ );
566+ int const result = this ->transport_cache_manager ().make_idle (this ->cache_map_entry_ );
567+ if (result == 0 )
568+ {
569+ this ->schedule_idle_timer ();
570+ }
571+ return result;
551572}
552573
553574int
554575TAO_Transport::update_transport ()
555576{
577+ if (TAO_debug_level > 3 )
578+ {
579+ TAOLIB_DEBUG ((LM_DEBUG,
580+ ACE_TEXT (" TAO (%P|%t) - Transport[%d]::update_transport\n " ),
581+ this ->id ()));
582+ }
583+
556584 return this ->transport_cache_manager ().update_entry (this ->cache_map_entry_ );
557585}
558586
@@ -852,7 +880,7 @@ TAO_Transport::schedule_output_i ()
852880 ACE_Event_Handler * const eh = this ->event_handler_i ();
853881 ACE_Reactor * const reactor = eh->reactor ();
854882
855- if (reactor == nullptr )
883+ if (! reactor)
856884 {
857885 if (TAO_debug_level > 1 )
858886 {
@@ -940,23 +968,63 @@ TAO_Transport::handle_timeout (const ACE_Time_Value & /* current_time */,
940968 // pending.
941969 this ->reset_flush_timer ();
942970
943- TAO_Flushing_Strategy *flushing_strategy =
944- this ->orb_core ()->flushing_strategy ();
971+ TAO_Flushing_Strategy *flushing_strategy = this ->orb_core ()->flushing_strategy ();
945972 int const result = flushing_strategy->schedule_output (this );
946973 if (result == TAO_Flushing_Strategy::MUST_FLUSH)
947974 {
948975 typedef ACE_Reverse_Lock<ACE_Lock> TAO_REVERSE_LOCK;
949976 TAO_REVERSE_LOCK reverse (*this ->handler_lock_ );
950977 ACE_GUARD_RETURN (TAO_REVERSE_LOCK, ace_mon, reverse, -1 );
951- if (flushing_strategy->flush_transport (this , nullptr ) == -1 ) {
952- return -1 ;
953- }
978+ if (flushing_strategy->flush_transport (this , nullptr ) == -1 )
979+ {
980+ return -1 ;
981+ }
954982 }
955983 }
956984
957985 return 0 ;
958986}
959987
988+ int
989+ TAO_Transport::handle_idle_timeout (const ACE_Time_Value & /* current_time */ , const void */*act*/)
990+ {
991+ if (TAO_debug_level > 6 )
992+ {
993+ TAOLIB_DEBUG ((LM_DEBUG,
994+ ACE_TEXT (" TAO (%P|%t) - Transport[%d]::handle_idle_timeout, " )
995+ ACE_TEXT (" idle timer expired, closing transport\n " ),
996+ this ->id ()));
997+ }
998+
999+ // Timer has expired, so setting the idle timer id back to -1
1000+ this ->idle_timer_id_ = -1 ;
1001+
1002+ if (this ->transport_cache_manager ().purge_entry_when_purgable (this ->cache_map_entry_ ) == -1 )
1003+ {
1004+ if (TAO_debug_level > 6 )
1005+ TAOLIB_DEBUG ((LM_DEBUG,
1006+ ACE_TEXT (" TAO (%P|%t) - Transport[%d]::handle_idle_timeout, " )
1007+ ACE_TEXT (" idle_timeout, transport is not purgable, don't close it, reschedule it\n " ),
1008+ this ->id ()));
1009+
1010+ this ->schedule_idle_timer ();
1011+ }
1012+ else
1013+ {
1014+ if (TAO_debug_level > 6 )
1015+ TAOLIB_DEBUG ((LM_DEBUG,
1016+ ACE_TEXT (" TAO (%P|%t) - Transport[%d]::handle_idle_timeout, " )
1017+ ACE_TEXT (" idle_timeout, transport purged due to idle timeout\n " ),
1018+ this ->id ()));
1019+
1020+ // Close the underlying socket.
1021+ // close_connection() is safe to call from the reactor thread.
1022+ (void ) this ->close_connection ();
1023+ }
1024+
1025+ return 0 ;
1026+ }
1027+
9601028TAO_Transport::Drain_Result
9611029TAO_Transport::drain_queue (TAO::Transport::Drain_Constraints const & dc)
9621030{
@@ -2729,8 +2797,7 @@ TAO_Transport::pre_close ()
27292797 // of the is_connected_ flag, so that during cache lookups the cache
27302798 // manager doesn't need to be burdened by the lock in is_connected().
27312799 this ->is_connected_ = false ;
2732- this ->transport_cache_manager ().mark_connected (this ->cache_map_entry_ ,
2733- false );
2800+ this ->transport_cache_manager ().mark_connected (this ->cache_map_entry_ , false );
27342801 this ->purge_entry ();
27352802 {
27362803 ACE_MT (ACE_GUARD (ACE_Lock, guard, *this ->handler_lock_ ));
@@ -2804,13 +2871,13 @@ TAO_Transport::post_open (size_t id)
28042871 ACE_TEXT (" , cache_map_entry_ is [%@]\n " ), this ->id_ , this ->cache_map_entry_ ));
28052872 }
28062873
2807- this ->transport_cache_manager ().mark_connected (this ->cache_map_entry_ ,
2808- true );
2874+ this ->transport_cache_manager ().mark_connected (this ->cache_map_entry_ , true );
28092875
28102876 // update transport cache to make this entry available
2811- this ->transport_cache_manager ().set_entry_state (
2812- this ->cache_map_entry_ ,
2813- TAO::ENTRY_IDLE_AND_PURGABLE);
2877+ this ->transport_cache_manager ().set_entry_state (this ->cache_map_entry_ , TAO::ENTRY_IDLE_AND_PURGABLE);
2878+
2879+ // this transport is just opened, so schedule it for the idle timer
2880+ this ->schedule_idle_timer ();
28142881
28152882 return true ;
28162883}
@@ -2874,4 +2941,56 @@ TAO_Transport::connection_closed_on_read () const
28742941 return connection_closed_on_read_;
28752942}
28762943
2944+ void
2945+ TAO_Transport::schedule_idle_timer ()
2946+ {
2947+ int const timeout_sec = this ->orb_core_ ->resource_factory ()->transport_idle_timeout ();
2948+ if (timeout_sec > 0 )
2949+ {
2950+ if (this ->idle_timer_id_ != -1 )
2951+ {
2952+ // The transport was marked as idle, but we have a timer running, cancel that old timer
2953+ // first
2954+ this ->cancel_idle_timer ();
2955+ }
2956+ ACE_Reactor *reactor = this ->orb_core_ ->reactor ();
2957+ if (reactor)
2958+ {
2959+ ACE_Time_Value const tv (static_cast <time_t > (timeout_sec));
2960+ this ->idle_timer_id_ = reactor->schedule_timer (std::addressof (this ->transport_idle_timer_ ), nullptr , tv);
2961+
2962+ if (TAO_debug_level > 6 )
2963+ {
2964+ TAOLIB_DEBUG ((LM_DEBUG,
2965+ ACE_TEXT (" TAO (%P|%t) - Transport[%d]::schedule_idle_timer, " )
2966+ ACE_TEXT (" schedule idle timer with id [%d] " )
2967+ ACE_TEXT (" in the reactor.\n " ),
2968+ this ->id (), this ->idle_timer_id_ ));
2969+ }
2970+ }
2971+ }
2972+ }
2973+
2974+ void
2975+ TAO_Transport::cancel_idle_timer ()
2976+ {
2977+ if (this ->idle_timer_id_ != -1 )
2978+ {
2979+ ACE_Reactor *reactor = this ->orb_core ()->reactor ();
2980+ if (reactor)
2981+ {
2982+ if (TAO_debug_level > 6 )
2983+ {
2984+ TAOLIB_DEBUG ((LM_DEBUG,
2985+ ACE_TEXT (" TAO (%P|%t) - Transport[%d]::cancel_idle_timer, " )
2986+ ACE_TEXT (" cancel idle timer with id [%d] " )
2987+ ACE_TEXT (" from the reactor.\n " ),
2988+ this ->id (), this ->idle_timer_id_ ));
2989+ }
2990+ reactor->cancel_timer (this ->idle_timer_id_ );
2991+ this ->idle_timer_id_ = -1 ;
2992+ }
2993+ }
2994+ }
2995+
28772996TAO_END_VERSIONED_NAMESPACE_DECL
0 commit comments