Cleanup ACE_HAS_PTHREAD_SIGMASK_PROTOTYPE, all platforms support it so far as I can...
[ACE_TAO.git] / ACE / protocols / ace / RMCast / Fragment.cpp
blobde774d3e1c61329f647757ebead23ff30e60bb57
1 // author : Boris Kolpackov <boris@kolpackov.net>
2 #include "Fragment.h"
4 /*
5 #include <iostream>
6 using std::cerr;
7 using std::endl;
8 */
10 namespace ACE_RMCast
12 Fragment::
13 Fragment (Parameters const& params)
14 : params_ (params),
15 sn_ (1)
19 void Fragment::send (Message_ptr m)
21 if (Data const* data = static_cast<Data const*> (m->find (Data::id)))
23 size_t max_payload_size (
24 params_.max_packet_size () - max_service_size);
26 if (data->size () <= max_payload_size)
28 u64 sn;
30 Lock l (mutex_);
31 sn = sn_++;
34 m->add (Profile_ptr (new SN (sn)));
36 out_->send (m);
37 return;
40 char const* p = data->buf ();
41 size_t size (data->size ());
43 // Need fragmentation.
45 u32 packets (size / max_payload_size + (size % max_payload_size ? 1 : 0));
47 // cerr << "size : " << size << endl
48 // << "packs: " << packets << endl;
50 for (u32 i (1); i <= packets; ++i)
52 Message_ptr part (new Message);
54 size_t s (i == packets ? size % max_payload_size : max_payload_size);
56 // cerr << "pack: " << s << endl;
58 u64 sn;
60 Lock l (mutex_);
61 sn = sn_++;
64 part->add (Profile_ptr (new SN (sn)));
65 part->add (Profile_ptr (new Part (i, packets, size)));
66 part->add (Profile_ptr (new Data (p, s)));
68 out_->send (part);
70 p += s;