~ubuntu-branches/debian/experimental/libtorrent/experimental

« back to all changes in this revision

Viewing changes to src/protocol/request_list.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Rivas
  • Date: 2007-03-31 10:31:05 UTC
  • mto: (4.1.4 gutsy) (6.2.1 squeeze) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20070331103105-jzpp1rml6ud0ff75
Tags: upstream-0.11.4
ImportĀ upstreamĀ versionĀ 0.11.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
#include "config.h"
38
38
 
 
39
#include <algorithm>
39
40
#include <functional>
40
41
#include <inttypes.h>
41
42
#include <rak/functional.h>
42
43
 
43
 
#include "torrent/block.h"
44
 
#include "torrent/block_list.h"
 
44
#include "torrent/data/block.h"
 
45
#include "torrent/data/block_list.h"
45
46
#include "torrent/exceptions.h"
46
47
#include "download/delegator.h"
47
48
 
140
141
  // the unmodified BlockTransfer.
141
142
  if (piece.length() != m_transfer->piece().length()) {
142
143
    if (piece.length() != 0)
143
 
      throw network_error("Peer sent a piece with wrong, non-zero, length.");
 
144
      throw communication_error("Peer sent a piece with wrong, non-zero, length.");
144
145
 
145
146
    Block::release(m_transfer);
146
147
    goto downloading_error;
158
159
  // Create a dummy BlockTransfer object to hold the piece
159
160
  // information.
160
161
  m_transfer = new BlockTransfer();
161
 
  m_transfer->create_dummy(m_peerChunks->peer_info(), piece);
 
162
  Block::create_dummy(m_transfer, m_peerChunks->peer_info(), piece);
162
163
 
163
164
  return false;
164
165
}
195
196
    throw internal_error("RequestList::transfer_dissimilar() called but no transfer is in progress.");
196
197
 
197
198
  BlockTransfer* dummy = new BlockTransfer();
198
 
  dummy->create_dummy(m_peerChunks->peer_info(), m_transfer->piece());
 
199
  Block::create_dummy(dummy, m_peerChunks->peer_info(), m_transfer->piece());
199
200
  dummy->set_position(m_transfer->position());
200
201
 
201
202
  m_transfer->block()->transfer_dissimilar(m_transfer);
202
203
  m_transfer = dummy;
203
204
}
204
205
 
 
206
// void
 
207
// RequestList::cancel_transfer(BlockTransfer* transfer) {
 
208
// //   ReserveeList itr = std::find_if(m_canceled.begin(), m_canceled.end(), request_list_same_piece(piece));
 
209
 
 
210
// //   ReserveeList itr = std::find_if(m_canceled.begin(), m_canceled.end(), request_list_same_piece(piece));
 
211
// }
 
212
 
205
213
struct equals_reservee : public std::binary_function<BlockTransfer*, uint32_t, bool> {
206
214
  bool operator () (BlockTransfer* r, uint32_t index) const {
207
215
    return r->is_valid() && index == r->index();
251
259
}
252
260
 
253
261
uint32_t
254
 
RequestList::remove_invalid() {
255
 
  uint32_t count = 0;
256
 
  ReserveeList::iterator itr;
257
 
 
258
 
  // Could be more efficient, but rarely do we find any.
259
 
  while ((itr = std::find_if(m_queued.begin(), m_queued.end(),  std::not1(std::mem_fun(&BlockTransfer::is_valid)))) != m_queued.end()) {
260
 
    count++;
261
 
    Block::release(*itr);
262
 
    m_queued.erase(itr);
263
 
  }
264
 
 
265
 
  // Don't count m_canceled that are invalid.
266
 
  while ((itr = std::find_if(m_canceled.begin(), m_canceled.end(), std::not1(std::mem_fun(&BlockTransfer::is_valid)))) != m_canceled.end()) {
267
 
    Block::release(*itr);
268
 
    m_canceled.erase(itr);
269
 
  }
270
 
 
271
 
  return count;
272
 
}
273
 
 
274
 
uint32_t
275
262
RequestList::calculate_pipe_size(uint32_t rate) {
276
263
  // Change into KB.
277
264
  rate /= 1024;