summaryrefslogtreecommitdiff
path: root/TAO/tao/Messaging/Asynch_Timeout_Handler.cpp
blob: f72a1d46d859bf56d0da5d14cac4b32b3dab5226 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// $Id$


#include "tao/Messaging/Asynch_Timeout_Handler.h"

#include "tao/Messaging/Asynch_Reply_Dispatcher.h"
#include "tao/Transport_Mux_Strategy.h"
#include "ace/Reactor.h"

ACE_RCSID (Messaging,
           Asynch_Timeout_Handler,
           "$Id$")

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_Asynch_Timeout_Handler::TAO_Asynch_Timeout_Handler (
  TAO_Asynch_Reply_Dispatcher_Base *rd,
  ACE_Reactor *reactor)
  : rd_ (rd),
    tms_ (0),
    request_id_ (0),
    reactor_ (reactor)
{
  // Enable reference counting on the event handler.
  this->reference_counting_policy ().value (
    ACE_Event_Handler::Reference_Counting_Policy::ENABLED);

  // We own a reference
  (void) this->rd_->incr_refcount ();
}

TAO_Asynch_Timeout_Handler::~TAO_Asynch_Timeout_Handler ()
{
  // Forget rd's reference
  (void) this->rd_->decr_refcount ();
}


long
TAO_Asynch_Timeout_Handler::schedule_timer (TAO_Transport_Mux_Strategy *tms,
                                            CORBA::ULong request_id,
                                            const ACE_Time_Value &max_wait_time)
{
  // Remember them for later.
  this->tms_ = tms;
  this->request_id_ = request_id;

  return this->reactor_->schedule_timer (this,          // handler
                                         0,             // arg
                                         max_wait_time);
}

int
TAO_Asynch_Timeout_Handler::handle_timeout (const ACE_Time_Value &,
                                            const void *)
{
  this->tms_->unbind_dispatcher (request_id_);

  this->rd_->reply_timed_out ();

  // reset any possible timeout errno
  errno = 0;

  // we are unregistered anyway
  return 0;
}

void
TAO_Asynch_Timeout_Handler::cancel ()
{
  // The tms_ is only set if we got scheduled.
  if (this->tms_)
    {
      this->reactor_->cancel_timer (this);
    }
}

TAO_END_VERSIONED_NAMESPACE_DECL