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

#include "Asynch_Queued_Message.h"

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

TAO_Asynch_Queued_Message::
    TAO_Asynch_Queued_Message (const ACE_Message_Block *contents)
  : offset_ (0)
{
  this->size_ = contents->total_length ();
  // @@ Use a pool for these guys!!
  ACE_NEW (this->buffer_, char[this->size_]);

  size_t copy_offset = 0;
  for (const ACE_Message_Block *i = contents;
       i != 0;
       i = i->cont ())
    {
      ACE_OS::memcpy (this->buffer_ + copy_offset,
                      i->rd_ptr (),
                      i->length ());
      copy_offset += i->length ();
    }
}

TAO_Asynch_Queued_Message::~TAO_Asynch_Queued_Message (void)
{
  // @@ Use a pool for these guys!
  delete[] this->buffer_;
}

size_t
TAO_Asynch_Queued_Message::message_length (void) const
{
  return this->size_ - this->offset_;
}

int
TAO_Asynch_Queued_Message::all_data_sent (void) const
{
  return this->size_ == this->offset_;
}

void
TAO_Asynch_Queued_Message::fill_iov (int iovcnt_max,
                                     int &iovcnt,
                                     iovec iov[]) const
{
  ACE_ASSERT (iovcnt_max > iovcnt);

  iov[iovcnt].iov_base = this->buffer_ + this->offset_;
  iov[iovcnt].iov_len  = this->size_ - this->offset_;
  iovcnt++;
}

void
TAO_Asynch_Queued_Message::bytes_transferred (size_t &byte_count)
{
  size_t remaining_bytes = this->size_ - this->offset_;
  if (byte_count > remaining_bytes)
    {
      this->offset_ = this->size_;
      byte_count -= remaining_bytes;
      return;
    }
  this->offset_ += byte_count;
  byte_count = 0;
}

void
TAO_Asynch_Queued_Message::destroy (void)
{
  // @@ Maybe it comes from a pool, we should do something about it.
  delete this;
}