1 // author : Boris Kolpackov <boris@kolpackov.net>
13 Fragment (Parameters
const& params
)
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
)
34 m
->add (Profile_ptr (new SN (sn
)));
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;
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
)));