void Retransmit::send (Message_ptr m) { if (m->find (Data::id) != 0) { SN const* sn = static_cast<SN const*> (m->find (SN::id)); Lock l (mutex_); queue_.bind (sn->num (), Descr (m->clone ())); } out_->send (m); }
void Acknowledge:: track_queue (Address const& addr, Queue& q, Messages& msgs) { unsigned short max_payload_size ( params_.max_packet_size () - max_service_size); u32 max_elem (NAK::max_count (max_payload_size)); u32 count (0); Queue::iterator i (q.begin ()), e (q.end ()); // Track existing losses. // while (i != e) { auto_ptr<NAK> nak (new NAK (addr)); // Inner loop that fills NAK profile with up to max_elem elements. // for (; i != e && nak->count () < max_elem; ++i) { u64 sn ((*i).ext_id_); Descr& d = (*i).int_id_; if (d.lost ()) { d.timer (d.timer () - 1); if (d.timer () == 0) { //@@ Need exp fallback. // d.nak_count (d.nak_count () + 1); d.timer ((d.nak_count () + 1) * params_.nak_timeout ()); nak->add (sn); ++count; // cerr << 6 << "NAK # " << d.nak_count () << ": " // << addr << " " << sn << endl; } } } // Send this NAK. // if (nak->count ()) { // cerr << 5 << "NAK: " << addr << " " << nak->count () << " sns" // << endl; Message_ptr m (new Message); m->add (Profile_ptr (nak.release ())); msgs.push_back (m); } } // Detect and record new losses. // for (u64 sn (q.sn () + 1), end (q.max_sn ()); sn < end; ++sn) { if (q.find (sn) == -1) { q.bind (sn, Descr (1)); } } }
void Acknowledge::recv (Message_ptr m) { // Handle NRTM. There could be some nasty interaction with code // that handles data below (like missing message and NAK). This // is why I hold the lock at the beginning (which may be not very // efficient). // Lock l (mutex_); if (NRTM const* nrtm = static_cast<NRTM const*> (m->find (NRTM::id))) { for (Map::iterator i (hold_.begin ()), e (hold_.end ()); i != e; ++i) { u64 sn (nrtm->find ((*i).ext_id_)); if (sn != 0) { Queue& q = (*i).int_id_; u64 old (q.max_sn ()); if (old < sn) { // Mark as lost. // q.bind (sn, Descr (1)); } } } } if (m->find (Data::id) || m->find (NoData::id)) { Address from ( static_cast<From const*> (m->find (From::id))->address ()); u64 sn (static_cast<SN const*> (m->find (SN::id))->num ()); Map::ENTRY* e = 0; if (hold_.find (from, e) == -1) { // First message from this source. // hold_.bind (from, Queue (sn)); in_->recv (m); } else { Queue& q = e->int_id_; if (sn <= q.sn ()) { // Duplicate. // //cerr << 6 << "DUP " << from << " " << q.sn () << " >= " << sn // << endl; } else if (sn == q.sn () + 1) { // Next message. // q.rebind (sn, Descr (m)); collapse (q); } else { // Some messages are missing. Insert this one into the queue. // q.rebind (sn, Descr (m)); } } } else { l.release (); // Just forward it up. // in_->recv (m); } }
void tst_QBoxLayout::testLayoutEngine_data() { // (int min, int sh, int max = -1, bool exp= false, int _stretch = 0, bool _empty = false) QTest::addColumn<DescrList>("itemDescriptions"); QTest::addColumn<int>("size"); QTest::addColumn<int>("spacing"); QTest::addColumn<PosList>("expectedPositions"); QTest::addColumn<SizeList>("expectedSizes"); QTest::newRow("Just one") << (DescrList() << Descr(0, 100)) << 200 << 0 << (PosList() << 0) << (SizeList() << 200); QTest::newRow("Two non-exp") << (DescrList() << Descr(0, 100) << Descr(0,100)) << 400 << 0 << (PosList() << 0 << 200) << (SizeList() << 200 << 200); QTest::newRow("Exp + non-exp") << (DescrList() << Descr(0, 100, -1, true) << Descr(0,100)) << 400 << 0 << (PosList() << 0 << 300) << (SizeList() << 300 << 100); QTest::newRow("Stretch") << (DescrList() << Descr(0, 100, -1, false, 1) << Descr(0,100, -1, false, 2)) << 300 << 0 << (PosList() << 0 << 100) << (SizeList() << 100 << 200); QTest::newRow("Spacing") << (DescrList() << Descr(0, 100) << Descr(0,100)) << 400 << 10 << (PosList() << 0 << 205) << (SizeList() << 195 << 195); QTest::newRow("Less than minimum") << (DescrList() << Descr(100, 100, 100, false) << Descr(50, 100, 100, false)) << 100 << 0 << (PosList() << 0 << 50) << (SizeList() << 50 << 50); QTest::newRow("Less than sizehint") << (DescrList() << Descr(100, 200, 100, false) << Descr(50, 200, 100, false)) << 200 << 0 << (PosList() << 0 << 100) << (SizeList() << 100 << 100); QTest::newRow("Too much space") << (DescrList() << Descr(0, 100, 100, false) << Descr(0, 100, 100, false)) << 500 << 0 << (PosList() << 100 << 300) << (SizeList() << 100 << 100); QTest::newRow("Empty") << (DescrList() << Descr(0, 100, 100) << Descr(0,0,-1, false, 0, true) << Descr(0, 100, 100) ) << 500 << 0 << (PosList() << 100 << 300 << 300) << (SizeList() << 100 << 0 << 100); QTest::newRow("QTBUG-33104") << (DescrList() << Descr(11, 75, 75, true) << Descr(75, 75)) << 200 << 0 << (PosList() << 0 << 75) << (SizeList() << 75 << 125); QTest::newRow("Expanding with maximumSize") << (DescrList() << Descr(11, 75, 100, true) << Descr(75, 75)) << 200 << 0 << (PosList() << 0 << 100) << (SizeList() << 100 << 100); QTest::newRow("Stretch with maximumSize") << (DescrList() << Descr(11, 75, 100, false, 1) << Descr(75, 75)) << 200 << 0 << (PosList() << 0 << 100) << (SizeList() << 100 << 100); QTest::newRow("Stretch with maximumSize last") << (DescrList() << Descr(75, 75) << Descr(11, 75, 100, false, 1)) << 200 << 0 << (PosList() << 0 << 100) << (SizeList() << 100 << 100); }