summaryrefslogtreecommitdiff
path: root/ACE/TAO/tao/Block_Flushing_Strategy.cpp
blob: ce17445599d4e8c8bc9826142fa544759fdcaafb (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
// $Id$

#include "tao/Block_Flushing_Strategy.h"
#include "tao/Transport.h"
#include "tao/Queued_Message.h"
#include "tao/Connection_Handler.h"
#include "ace/Countdown_Time.h"

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

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

int
TAO_Block_Flushing_Strategy::schedule_output (TAO_Transport *)
{
  return MUST_FLUSH;
}

int
TAO_Block_Flushing_Strategy::cancel_output (TAO_Transport *)
{
  return 0;
}

int
TAO_Block_Flushing_Strategy::call_handle_output (TAO_Transport *transport,
    const TAO::Transport::Drain_Constraints &dc)
{
  switch (transport->handle_output (dc).dre_)
    {
    case TAO_Transport::DR_ERROR: return -1;
    case TAO_Transport::DR_QUEUE_EMPTY: // won't happen, fall-through anyway
    case TAO_Transport::DR_OK: return 0;
    case TAO_Transport::DR_WOULDBLOCK:
      {
        ACE_Countdown_Time counter (dc.timeout ());
        TAO_Connection_Handler &ch = *transport->connection_handler ();
        if (ch.handle_write_ready (dc.timeout ()) == -1)
          {
            return -1;
          }
        return 0;
      }
    }
  return 0;
}

int
TAO_Block_Flushing_Strategy::flush_message (TAO_Transport *transport,
                                            TAO_Queued_Message *msg,
                                            ACE_Time_Value *max_wait_time)
{
  TAO::Transport::Drain_Constraints dc (max_wait_time, true);
  while (!msg->all_data_sent ())
    {
      if (this->call_handle_output (transport, dc) == -1)
        return -1;
    }
  return 0;
}

int
TAO_Block_Flushing_Strategy::flush_transport (TAO_Transport *transport,
                                              ACE_Time_Value *max_wait_time)
{
  TAO::Transport::Drain_Constraints dc (max_wait_time, true);
  while (!transport->queue_is_empty ())
    {
      if (this->call_handle_output (transport, dc) == -1)
        return -1;
    }
  return 0;
}

TAO_END_VERSIONED_NAMESPACE_DECL