socklen_t addrlen = sizeof(struct sockaddr_in);
offset = 0;
length = recvfrom (sock, (char *)buf, MAXDGRAMSZ, 0,
- (struct sockaddr*)&(addr), &addrlen);
+ (struct sockaddr*)&(addr.addr), &addrlen);
if (length<0) {
length = 0;
print_error("error on recv");
}
-KeepAliveController::KeepAliveController (Channel* ch) : SendController(ch), delay_(ch->rtt_avg_) {
+KeepAliveController::KeepAliveController (Channel* ch) :
+SendController(ch), delay_(ch->rtt_avg_) {
}
void CwndController::OnDataSent(bin64_t b) {
- if ( (b==bin64_t::ALL || b==bin64_t::NONE) && MaySendData() ) { // no more data (no hints?)
+ if ( (b==bin64_t::ALL || b==bin64_t::NONE) && MaySendData() ) {// no more data (no hints?)
Schedule(NOW+ch_->rtt_avg_); // soft pause; nothing to send yet
if (ch_->last_send_data_time_ < NOW-ch_->rtt_avg_)
Swap(new KeepAliveController(this)); // really, nothing to send
{
fd_ = open(filename,OPENFLAGS,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if (fd_<0) {
+ fd_ = 0;
print_error("cannot open the file");
return;
}
strcpy(hfn,hash_filename);
hash_fd_ = open(hfn,OPENFLAGS,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if (hash_fd_<0) {
+ hash_fd_ = 0;
print_error("cannot open hash file");
return;
}
void HashTree::Submit () {
size_ = file_size(fd_);
- sizek_ = (size_>>10) + ((size_&1023) ? 1 : 0);
+ sizek_ = (size_ + 1023) >> 10;
peak_count_ = bin64_t::peaks(sizek_,peaks_);
int hashes_size = Sha1Hash::SIZE*sizek_*2;
file_resize(hash_fd_,hashes_size);
for some optimizations. */
void HashTree::RecoverProgress () {
size_t size = file_size(fd_);
- size_t sizek = (size>>10) + ((size&1023) ? 1 : 0);
+ size_t sizek = (size + 1023) >> 10;
bin64_t peaks[64];
int peak_count = bin64_t::peaks(sizek,peaks);
for(int i=0; i<peak_count; i++) {
size_ = sizek_<<10;
completek_ = complete_ = 0;
- sizek_ = (size_>>10) + ((size_&1023) ? 1 : 0);
+ sizek_ = (size_ + 1023) >> 10;
size_t cur_size = file_size(fd_);
if ( cur_size<=(sizek_-1)<<10 || cur_size>sizek_<<10 )
memory_unmap(hash_fd_, hashes_, sizek_*2*sizeof(Sha1Hash));
if (fd_)
close(fd_);
+ if (hash_fd_)
+ close(hash_fd_);
}
hint_in_.pop_front();
if (time < NOW-TINT_SEC*3/2 ) //NOW-8*rtt_avg_)
continue;
+ // Totally flawed:
+ // a. May empty the queue when you least expect
+ // b. May lose parts of partially ACKd HINTs
send = file().ack_out().find_filtered(ack_in_,hint,bins::FILLED);
send = send.left_foot(); // single packet
if (send!=bin64_t::NONE)
while (hi<hint_out_.size() && !pos.within(hint_out_[hi].bin))
hi++;
if (hi==hint_out_.size())
- return;
+ return; // something not hinted or hinted in far past
while (hi--) { // removing likely snubbed hints
hint_out_size_ -= hint_out_.front().bin.width();
hint_out_.pop_front();
{
files[fd()] = NULL;
+ for(int i=0; i<Channel::channels.size(); i++)
+ if (Channel::channels[i] && Channel::channels[i]->transfer_==this)
+ delete Channel::channels[i];
}