[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/network/ktorrent/libbtcore
From: Joris Guisson <joris.guisson () gmail ! com>
Date: 2008-07-24 9:47:31
Message-ID: 1216892851.517264.14365.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 837230 by guisson:
Improved networking code, which should lead to more stable download speeds
M +6 -0 mse/streamsocket.cpp
M +3 -0 mse/streamsocket.h
M +2 -0 net/bufferedsocket.cpp
M +43 -51 net/downloadthread.cpp
M +4 -8 net/downloadthread.h
M +2 -3 net/uploadthread.cpp
M +1 -0 peer/peer.cpp
--- trunk/extragear/network/ktorrent/libbtcore/mse/streamsocket.cpp #837229:837230
@@ -34,6 +34,7 @@
#endif
#include <netinet/tcp.h>
#include <net/socketmonitor.h>
+#include <util/functions.h>
#include "rc4encryptor.h"
using namespace bt;
@@ -331,6 +332,11 @@
{
sock->setRemoteAddress(addr);
}
+
+ void StreamSocket::updateSpeeds()
+ {
+ sock->updateSpeeds(bt::GetCurrentTime());
+ }
}
#include "streamsocket.moc"
--- trunk/extragear/network/ktorrent/libbtcore/mse/streamsocket.h #837229:837230
@@ -59,6 +59,9 @@
StreamSocket(int fd,int ip_version);
virtual ~StreamSocket();
+ /// Recalculate upload and download speed
+ void updateSpeeds();
+
/**
* Send a chunk of data. (Does not encrypt the data)
* @param data The data
--- trunk/extragear/network/ktorrent/libbtcore/net/bufferedsocket.cpp #837229:837230
@@ -198,7 +198,9 @@
void BufferedSocket::updateSpeeds(bt::TimeStamp now)
{
+ mutex.lock();
up_speed->update(now);
down_speed->update(now);
+ mutex.unlock();
}
}
--- trunk/extragear/network/ktorrent/libbtcore/net/downloadthread.cpp #837229:837230
@@ -35,7 +35,7 @@
namespace net
{
Uint32 DownloadThread::dcap = 0;
- Uint32 DownloadThread::sleep_time = 3;
+ Uint32 DownloadThread::sleep_time = 50;
DownloadThread::DownloadThread(SocketMonitor* sm) : NetworkThread(sm)
{
@@ -48,53 +48,51 @@
void DownloadThread::update()
{
sm->lock();
- int num = fillPollVector();
- sm->unlock();
-
- int timeout = 10;
-#ifndef Q_WS_WIN
- if (poll(&fd_vec[0],num,timeout) > 0)
-#else
- if (mingw_poll(&fd_vec[0],num,timeout) > 0)
-#endif
+ TimeStamp now = bt::Now();
+ Uint32 num_ready = 0;
+ SocketMonitor::Itr itr = sm->begin();
+ while (itr != sm->end())
{
- sm->lock();
- TimeStamp now = bt::Now();
- Uint32 num_ready = 0;
- SocketMonitor::Itr itr = sm->begin();
- while (itr != sm->end())
+ BufferedSocket* s = *itr;
+ if (s->ok() && s->bytesAvailable() > 0)
{
- BufferedSocket* s = *itr;
- int pi = s->getPollIndex();
- if (pi >= 0 && s->ok() && fd_vec[pi].revents & POLLIN)
- {
- // add to the correct group
- Uint32 gid = s->downloadGroupID();
- SocketGroup* g = groups.find(gid);
- if (!g)
- g = groups.find(0);
+ // add to the correct group
+ Uint32 gid = s->downloadGroupID();
+ SocketGroup* g = groups.find(gid);
+ if (!g)
+ g = groups.find(0);
- g->add(s);
- num_ready++;
- }
- itr++;
+ g->add(s);
+ num_ready++;
}
-
- if (num_ready > 0)
- doGroups(num_ready,now,dcap);
- prev_run_time = now;
- sm->unlock();
+ itr++;
}
- if (dcap > 0 || groups.count() > 0)
+ if (num_ready > 0)
+ doGroups(num_ready,now,dcap);
+ prev_run_time = now;
+ sm->unlock();
+
+ if (num_ready == 0)
+ waitForSocketReady();
+ else
msleep(sleep_time);
}
-
- int DownloadThread::fillPollVector()
+
+ void DownloadThread::setSleepTime(Uint32 stime)
{
- TimeStamp ts = bt::Now();
+ sleep_time = stime;
+ }
+
+ bool DownloadThread::doGroup(SocketGroup* g,Uint32 & allowance,bt::TimeStamp now)
+ {
+ return g->download(allowance,now);
+ }
+
+ void DownloadThread::waitForSocketReady()
+ {
int i = 0;
-
+ sm->lock();
// fill the poll vector with all sockets
SocketMonitor::Itr itr = sm->begin();
while (itr != sm->end())
@@ -121,7 +119,6 @@
}
s->setPollIndex(i);
i++;
- s->updateSpeeds(ts);
}
else
{
@@ -129,18 +126,13 @@
}
itr++;
}
-
- return i;
- }
+ sm->unlock();
- void DownloadThread::setSleepTime(Uint32 stime)
- {
- if (stime >= 1 && stime <= 10)
- sleep_time = stime;
+ int timeout = 1000; // one second for upper limit, so that new sockets do not have to wait for long
+#ifndef Q_WS_WIN
+ poll(&fd_vec[0],i,timeout);
+#else
+ mingw_poll(&fd_vec[0],i,timeout):
+#endif
}
-
- bool DownloadThread::doGroup(SocketGroup* g,Uint32 & allowance,bt::TimeStamp now)
- {
- return g->download(allowance,now);
- }
}
--- trunk/extragear/network/ktorrent/libbtcore/net/downloadthread.h #837229:837230
@@ -37,26 +37,22 @@
{
static bt::Uint32 dcap;
static bt::Uint32 sleep_time;
-
std::vector<struct pollfd> fd_vec;
-
public:
DownloadThread(SocketMonitor* sm);
virtual ~DownloadThread();
-
+
/// Set the download cap
static void setCap(bt::Uint32 cap) {dcap = cap;}
/// Set the sleep time when using download caps
static void setSleepTime(bt::Uint32 stime);
- private:
- int fillPollVector();
-
+ private:
virtual void update();
virtual bool doGroup(SocketGroup* g,Uint32 & allowance,bt::TimeStamp now);
-
-// void processIncomingData(bt::TimeStamp now);
+
+ void waitForSocketReady();
};
}
--- trunk/extragear/network/ktorrent/libbtcore/net/uploadthread.cpp #837229:837230
@@ -29,7 +29,7 @@
namespace net
{
Uint32 UploadThread::ucap = 0;
- Uint32 UploadThread::sleep_time = 3;
+ Uint32 UploadThread::sleep_time = 50;
UploadThread::UploadThread(SocketMonitor* sm) : NetworkThread(sm)
{}
@@ -84,8 +84,7 @@
void UploadThread::setSleepTime(Uint32 stime)
{
- if (stime >= 1 && stime <= 10)
- sleep_time = stime;
+ sleep_time = stime;
}
bool UploadThread::doGroup(SocketGroup* g,Uint32 & allowance,bt::TimeStamp now)
--- trunk/extragear/network/ktorrent/libbtcore/peer/peer.cpp #837229:837230
@@ -464,6 +464,7 @@
return;
}
+ sock->updateSpeeds();
preader->update();
Uint32 data_bytes = pwriter->getUploadedDataBytes();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic