本文整理汇总了C++中Datagram::Pull32方法的典型用法代码示例。如果您正苦于以下问题:C++ Datagram::Pull32方法的具体用法?C++ Datagram::Pull32怎么用?C++ Datagram::Pull32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datagram
的用法示例。
在下文中一共展示了Datagram::Pull32方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eprintf
void Channel::OnAck (Datagram& dgram) {
bin64_t ackd_pos = dgram.Pull32();
tint peer_time = dgram.Pull64(); // FIXME 32
// FIXME FIXME: wrap around here
if (ackd_pos==bin64_t::NONE)
return; // likely, brocken packet / insufficient hashes
if (file().size() && ackd_pos.base_offset()>=file().packet_size()) {
eprintf("invalid ack: %s\n",ackd_pos.str());
return;
}
ack_in_.set(ackd_pos);
int di = 0, ri = 0;
// find an entry for the send (data out) event
while ( di<data_out_.size() && ( data_out_[di]==tintbin() ||
!data_out_[di].bin.within(ackd_pos) ) )
di++;
// FUTURE: delayed acks
// rule out retransmits
while ( ri<data_out_tmo_.size() && !data_out_tmo_[ri].bin.within(ackd_pos) )
ri++;
dprintf("%s #%u %cack %s %lli\n",tintstr(),id_,
di==data_out_.size()?'?':'-',ackd_pos.str(),peer_time);
if (di!=data_out_.size() && ri==data_out_tmo_.size()) { // not a retransmit
// round trip time calculations
tint rtt = NOW-data_out_[di].time;
rtt_avg_ = (rtt_avg_*7 + rtt) >> 3;
dev_avg_ = ( dev_avg_*3 + abs(rtt-rtt_avg_) ) >> 2;
assert(data_out_[di].time!=TINT_NEVER);
// one-way delay calculations
tint owd = peer_time - data_out_[di].time;
owd_cur_bin_ = 0;//(owd_cur_bin_+1) & 3;
owd_current_[owd_cur_bin_] = owd;
if ( owd_min_bin_start_+TINT_SEC*30 < NOW ) {
owd_min_bin_start_ = NOW;
owd_min_bin_ = (owd_min_bin_+1) & 3;
owd_min_bins_[owd_min_bin_] = TINT_NEVER;
}
if (owd_min_bins_[owd_min_bin_]>owd)
owd_min_bins_[owd_min_bin_] = owd;
dprintf("%s #%u sendctrl rtt %lli dev %lli based on %s\n",
tintstr(),id_,rtt_avg_,dev_avg_,data_out_[di].bin.str());
ack_rcvd_recent_++;
// early loss detection by packet reordering
for (int re=0; re<di-MAX_REORDERING; re++) {
if (data_out_[re]==tintbin())
continue;
ack_not_rcvd_recent_++;
data_out_tmo_.push_back(data_out_[re].bin);
dprintf("%s #%u Rdata %s\n",tintstr(),id_,data_out_.front().bin.str());
data_out_cap_ = bin64_t::ALL;
data_out_[re] = tintbin();
}
}
示例2: OnData
bin64_t Channel::OnData (Datagram& dgram) { // TODO: HAVE NONE for corrupted data
bin64_t pos = dgram.Pull32();
uint8_t *data;
int length = dgram.Pull(&data,1024);
bool ok = (pos==bin64_t::NONE) || file().OfferData(pos, (char*)data, length) ;
dprintf("%s #%u %cdata %s\n",tintstr(),id_,ok?'-':'!',pos.str());
data_in_ = tintbin(NOW,bin64_t::NONE);
if (!ok)
return bin64_t::NONE;
for(int i=0; i<transfer().cb_installed; i++)
transfer().callbacks[i](transfer().fd(),pos); // FIXME FIXME FIXME
data_in_.bin = pos;
if (pos!=bin64_t::NONE) {
if (last_data_in_time_) {
tint dip = NOW - last_data_in_time_;
dip_avg_ = ( dip_avg_*3 + dip ) >> 2;
}
last_data_in_time_ = NOW;
}
CleanHintOut(pos);
return pos;
}
示例3: file
void Channel::OnHash (Datagram& dgram) {
bin64_t pos = dgram.Pull32();
Sha1Hash hash = dgram.PullHash();
file().OfferHash(pos,hash);
dprintf("%s #%u -hash %s\n",tintstr(),id_,pos.str());
}