summaryrefslogtreecommitdiff
path: root/TAO/tao/Queued_Message.cpp
blob: 94ad78e16627dc2107d58e21b3f3d3cd8965d8b1 (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
// -*- C++ -*-
// $Id$

#include "Queued_Message.h"
#include "Message_Sent_Callback.h"

#if !defined (__ACE_INLINE__)
# include "Queued_Message.inl"
#endif /* __ACE_INLINE__ */

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

TAO_Queued_Message::TAO_Queued_Message (ACE_Message_Block *contents,
                                        int own_contents,
                                        TAO_Message_Sent_Callback *callback)
  : contents_ (contents)
  , own_contents_ (own_contents)
  , callback_ (callback)
  , current_block_ (contents)
  , next_ (0)
  , prev_ (0)
{
}

TAO_Queued_Message::~TAO_Queued_Message (void)
{
  if (this->own_contents_)
    {
      ACE_Message_Block *i = this->contents_;
      while (i != 0)
        {
          ACE_Message_Block *cont = i->cont (); i->cont (0);
          ACE_Message_Block::release (i);
          i = cont;
        }
    }
}

void
TAO_Queued_Message::connection_closed (void)
{
  if (this->callback_ != 0)
    {
      if (this->done ())
        {
          this->callback_->connection_closed ();
        }
      else
        {
          this->callback_->send_failed ();
        }
    }
}

void
TAO_Queued_Message::destroy (void)
{
  delete this;
}

void
TAO_Queued_Message::bytes_transferred (size_t byte_count)
{
  while (!this->done () && byte_count > 0)
    {
      size_t l = this->current_block_->length ();
      if (byte_count < l)
        {
          this->current_block_->rd_ptr (byte_count);
          return;
        }
      byte_count -= l;
      this->current_block_ = this->current_block_->cont ();
    }
}

void
TAO_Queued_Message::remove_from_list (TAO_Queued_Message *&head,
                                      TAO_Queued_Message *&tail)
{
  if (this->prev_ != 0)
    this->prev_->next_ = this->next_;
  else
    head = this->next_;

  if (this->next_ != 0)
    this->next_->prev_ = this->prev_;
  else
    tail = this->prev_;

  this->next_ = 0;
  this->prev_ = 0;
}

void
TAO_Queued_Message::push_back (TAO_Queued_Message *&head,
                               TAO_Queued_Message *&tail)
{
  if (tail == 0)
    {
      tail = this;
      head = this;
      this->next_ = 0;
      this->prev_ = 0;
      return;
    }

  tail->next_ = this;
  this->prev_ = tail;
  this->next_ = 0;
  tail = this;
}