~ubuntu-branches/ubuntu/oneiric/libtorrent/oneiric

« back to all changes in this revision

Viewing changes to src/net/throttle_list.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Rivas
  • Date: 2007-09-11 15:12:31 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070911151231-brompt7pecvfbaau
Tags: 0.11.8-1
* New upstream version
* debian/patches/update-changelog.patch:
 + Updated with the new changelog.
* debian/control:
 + Added the Homepage field, deleted Homepages from the descriptions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// libTorrent - BitTorrent library
2
 
// Copyright (C) 2005-2006, Jari Sundell
 
2
// Copyright (C) 2005-2007, Jari Sundell
3
3
//
4
4
// This program is free software; you can redistribute it and/or modify
5
5
// it under the terms of the GNU General Public License as published by
50
50
  m_size(0),
51
51
  m_outstandingQuota(0),
52
52
  m_unallocatedQuota(0),
 
53
  m_unusedUnthrottledQuota(0),
53
54
 
54
55
  m_minChunkSize(2 << 10),
55
56
  m_maxChunkSize(16 << 10),
108
109
 
109
110
  m_outstandingQuota = 0;
110
111
  m_unallocatedQuota = 0;
 
112
  m_unusedUnthrottledQuota = 0;
111
113
 
112
114
  std::for_each(begin(), end(), std::mem_fun(&ThrottleNode::clear_quota));
113
115
  std::for_each(m_splitActive, end(), std::mem_fun(&ThrottleNode::activate));
120
122
  if (!m_enabled)
121
123
    throw internal_error("ThrottleList::update_quota(...) called but the object is not enabled.");
122
124
 
 
125
  // Distribute new quota to unthrottled quota first, and use
 
126
  // left-over unthrottled quota from last turn to be allocated
 
127
  // to throttled nodes this turn.
123
128
  // When distributing, we include the unallocated quota from the
124
129
  // previous turn. This will ensure that quota that was reclaimed
125
130
  // will have a chance of being used, even by those nodes that were
126
131
  // deactivated.
127
 
  m_unallocatedQuota += quota;
 
132
  m_unallocatedQuota += m_unusedUnthrottledQuota;
 
133
  m_unusedUnthrottledQuota = quota;
128
134
 
129
135
  // Add remaining to the next, even when less than activate border.
130
136
  while (m_splitActive != end()) {
163
169
  }
164
170
}
165
171
 
166
 
void
 
172
uint32_t
167
173
ThrottleList::node_used(ThrottleNode* node, uint32_t used) {
168
174
  m_rateSlow.insert(used);
169
175
  node->rate()->insert(used);
170
176
 
171
177
  if (used == 0 || !m_enabled || node->list_iterator() == end())
172
 
    return;
 
178
    return used;
173
179
 
174
180
  uint32_t quota = std::min(used, node->quota());
175
181
 
179
185
  node->set_quota(node->quota() - quota);
180
186
  m_outstandingQuota -= quota;
181
187
  m_unallocatedQuota -= std::min(used - quota, m_unallocatedQuota);
 
188
 
 
189
  return used;
 
190
}
 
191
 
 
192
uint32_t
 
193
ThrottleList::node_used_unthrottled(uint32_t used) {
 
194
  m_rateSlow.insert(used);
 
195
 
 
196
  // Use what we can from the unthrottled quota,
 
197
  // if node used too much borrow from throttled quota.
 
198
  uint32_t avail = std::min(used, m_unusedUnthrottledQuota);
 
199
  m_unusedUnthrottledQuota -= avail;
 
200
  m_unallocatedQuota -= std::min(used - avail, m_unallocatedQuota);
 
201
 
 
202
  return used;
182
203
}
183
204
 
184
205
void