summaryrefslogtreecommitdiff
path: root/TAO/tao/Wait_On_Reactor.cpp
blob: deba786785b2f5bdb75671e97f3b8640b4832fab (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// $Id$

#include "tao/Wait_On_Reactor.h"
#include "tao/ORB_Core.h"
#include "tao/Transport.h"
#include "tao/Synch_Reply_Dispatcher.h"

#include "ace/Reactor.h"

ACE_RCSID (tao,
           Wait_On_Reactor,
           "$Id$")

TAO_Wait_On_Reactor::TAO_Wait_On_Reactor (TAO_Transport *transport)
  : TAO_Wait_Strategy (transport)
{
}

TAO_Wait_On_Reactor::~TAO_Wait_On_Reactor (void)
{
}

int
TAO_Wait_On_Reactor::wait (ACE_Time_Value *max_wait_time,
                           TAO_Synch_Reply_Dispatcher &rd)
{
  // Start the count down timer to account for the time spent in this
  // method.
  ACE_Countdown_Time countdown (max_wait_time);

  // Reactor does not change inside the loop.
  ACE_Reactor* reactor =
    this->transport_->orb_core ()->reactor ();

  // Do the event loop, till we fully receive a reply.
  int result = 0;

  while (1)
    {
      // Run the event loop.
      result = reactor->handle_events (max_wait_time);

      // If we got our reply, no need to run the event loop any
      // further.
      if (!rd.keep_waiting ())
        {
          break;
        }

      // Did we timeout? If so, stop running the loop.
      if (result == 0
          && max_wait_time != 0
          && *max_wait_time == ACE_Time_Value::zero)
        {
          break;
        }

      // Other errors? If so, stop running the loop.
      if (result == -1)
        {
          break;
        }

      // Otherwise, keep going...
    }

  if (result == -1 || rd.error_detected ())
    {
      return -1;
    }

  // Return an error if there was a problem receiving the reply.
  if (max_wait_time != 0)
    {
      if (rd.successful () && *max_wait_time == ACE_Time_Value::zero)
        {
          result = -1;
          errno = ETIME;
        }
    }
  else
    {
      result = 0;

      if (rd.error_detected ())
        {
          result = -1;
        }
    }

  return result;
}

// Register the handler with the Reactor.
int
TAO_Wait_On_Reactor::register_handler (void)
{
  if (this->is_registered_ == 0)
    {
      return this->transport_->register_handler ();
    }

  return 1;
}

bool
TAO_Wait_On_Reactor::non_blocking (void) const
{
  return true;
}

bool
TAO_Wait_On_Reactor::can_process_upcalls (void) const
{
  return true;
}