diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:30 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:30 +0000 |
commit | c44379cc7d9c7aa113989237ab0f56db12aa5219 (patch) | |
tree | 66a84b20d47f2269d8bdc6e0323f338763424d3a /ACE/protocols/ace/RMCast/Fragment.cpp | |
parent | 3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (diff) | |
download | ATCD-c44379cc7d9c7aa113989237ab0f56db12aa5219.tar.gz |
Repo restructuring
Diffstat (limited to 'ACE/protocols/ace/RMCast/Fragment.cpp')
-rw-r--r-- | ACE/protocols/ace/RMCast/Fragment.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/ACE/protocols/ace/RMCast/Fragment.cpp b/ACE/protocols/ace/RMCast/Fragment.cpp new file mode 100644 index 00000000000..27247f0e3f9 --- /dev/null +++ b/ACE/protocols/ace/RMCast/Fragment.cpp @@ -0,0 +1,78 @@ +// file : ace/RMCast/Fragment.cpp +// author : Boris Kolpackov <boris@kolpackov.net> +// cvs-id : $Id$ + +#include "Fragment.h" + +/* +#include <iostream> +using std::cerr; +using std::endl; +*/ + +namespace ACE_RMCast +{ + Fragment:: + Fragment (Parameters const& params) + : params_ (params), + sn_ (1) + { + } + + void Fragment:: + send (Message_ptr m) + { + if (Data const* data = static_cast<Data const*> (m->find (Data::id))) + { + size_t max_payload_size ( + params_.max_packet_size () - max_service_size); + + if (data->size () <= max_payload_size) + { + u64 sn; + { + Lock l (mutex_); + sn = sn_++; + } + + m->add (Profile_ptr (new SN (sn))); + + out_->send (m); + return; + } + + char const* p = data->buf (); + size_t size (data->size ()); + + // Need fragmentation. + // + u32 packets (size / max_payload_size + (size % max_payload_size ? 1 : 0)); + + // cerr << "size : " << size << endl + // << "packs: " << packets << endl; + + for (u32 i (1); i <= packets; ++i) + { + Message_ptr part (new Message); + + size_t s (i == packets ? size % max_payload_size : max_payload_size); + + // cerr << "pack: " << s << endl; + + u64 sn; + { + Lock l (mutex_); + sn = sn_++; + } + + part->add (Profile_ptr (new SN (sn))); + part->add (Profile_ptr (new Part (i, packets, size))); + part->add (Profile_ptr (new Data (p, s))); + + out_->send (part); + + p += s; + } + } + } +} |