mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-08 07:09:21 +00:00
Moved polling code to libtorrent.
This commit is contained in:
@@ -63,36 +63,12 @@ PollManagerEPoll::~PollManagerEPoll() {
|
|||||||
|
|
||||||
void
|
void
|
||||||
PollManagerEPoll::poll(rak::timer timeout) {
|
PollManagerEPoll::poll(rak::timer timeout) {
|
||||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
static_cast<torrent::PollEPoll*>(m_poll)->do_poll();
|
||||||
// resolution.
|
|
||||||
torrent::perform();
|
|
||||||
timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
|
||||||
|
|
||||||
ThreadBase::release_global_lock();
|
|
||||||
ThreadBase::entering_main_polling();
|
|
||||||
|
|
||||||
int status = static_cast<torrent::PollEPoll*>(m_poll)->poll((timeout.usec() + 999) / 1000);
|
|
||||||
|
|
||||||
ThreadBase::leaving_main_polling();
|
|
||||||
ThreadBase::acquire_global_lock();
|
|
||||||
|
|
||||||
if (status == -1)
|
|
||||||
return check_error();
|
|
||||||
|
|
||||||
torrent::perform();
|
|
||||||
static_cast<torrent::PollEPoll*>(m_poll)->perform();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PollManagerEPoll::poll_simple(rak::timer timeout) {
|
PollManagerEPoll::poll_simple(rak::timer timeout) {
|
||||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
static_cast<torrent::PollEPoll*>(m_poll)->do_poll(torrent::Poll::poll_worker_thread);
|
||||||
// resolution.
|
|
||||||
timeout = timeout + 1000;
|
|
||||||
|
|
||||||
if (static_cast<torrent::PollEPoll*>(m_poll)->poll((timeout.usec() + 999) / 1000) == -1)
|
|
||||||
return check_error();
|
|
||||||
|
|
||||||
static_cast<torrent::PollEPoll*>(m_poll)->perform();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,36 +64,12 @@ PollManagerKQueue::~PollManagerKQueue() {
|
|||||||
|
|
||||||
void
|
void
|
||||||
PollManagerKQueue::poll(rak::timer timeout) {
|
PollManagerKQueue::poll(rak::timer timeout) {
|
||||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
static_cast<torrent::PollKQueue*>(m_poll)->do_poll();
|
||||||
// resolution.
|
|
||||||
torrent::perform();
|
|
||||||
timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
|
||||||
|
|
||||||
ThreadBase::release_global_lock();
|
|
||||||
ThreadBase::entering_main_polling();
|
|
||||||
|
|
||||||
int status = static_cast<torrent::PollKQueue*>(m_poll)->poll((timeout.usec() + 999) / 1000);
|
|
||||||
|
|
||||||
ThreadBase::leaving_main_polling();
|
|
||||||
ThreadBase::acquire_global_lock();
|
|
||||||
|
|
||||||
if (status == -1)
|
|
||||||
return check_error();
|
|
||||||
|
|
||||||
torrent::perform();
|
|
||||||
static_cast<torrent::PollKQueue*>(m_poll)->perform();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PollManagerKQueue::poll_simple(rak::timer timeout) {
|
PollManagerKQueue::poll_simple(rak::timer timeout) {
|
||||||
// Add 1ms to ensure we don't idle loop due to the lack of
|
static_cast<torrent::PollKQueue*>(m_poll)->do_poll(torrent::Poll::poll_worker_thread);
|
||||||
// resolution.
|
|
||||||
timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
|
||||||
|
|
||||||
if (static_cast<torrent::PollKQueue*>(m_poll)->poll((timeout.usec() + 999) / 1000) == -1)
|
|
||||||
return check_error();
|
|
||||||
|
|
||||||
static_cast<torrent::PollKQueue*>(m_poll)->perform();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,13 +53,6 @@ namespace core {
|
|||||||
PollManagerSelect::PollManagerSelect(torrent::Poll* p) : PollManager(p) {
|
PollManagerSelect::PollManagerSelect(torrent::Poll* p) : PollManager(p) {
|
||||||
#if defined USE_VARIABLE_FDSET
|
#if defined USE_VARIABLE_FDSET
|
||||||
m_setSize = (m_poll->open_max() + 7) / 8;
|
m_setSize = (m_poll->open_max() + 7) / 8;
|
||||||
|
|
||||||
char* buffer = rak::cacheline_allocator<char>::alloc_size(3 * m_setSize);
|
|
||||||
std::memset(buffer, 0, 3 * m_setSize);
|
|
||||||
|
|
||||||
m_readSet = (fd_set*)buffer;
|
|
||||||
m_writeSet = (fd_set*)(buffer += m_setSize);
|
|
||||||
m_errorSet = (fd_set*)(buffer += m_setSize);
|
|
||||||
#else
|
#else
|
||||||
#error Only variable fdset supported atm.
|
#error Only variable fdset supported atm.
|
||||||
#endif
|
#endif
|
||||||
@@ -76,52 +69,16 @@ PollManagerSelect::create(int maxOpenSockets) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PollManagerSelect::~PollManagerSelect() {
|
PollManagerSelect::~PollManagerSelect() {
|
||||||
free(m_readSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PollManagerSelect::poll(rak::timer timeout) {
|
PollManagerSelect::poll(rak::timer timeout) {
|
||||||
torrent::perform();
|
static_cast<torrent::PollSelect*>(m_poll)->do_poll();
|
||||||
timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000;
|
|
||||||
|
|
||||||
std::memset(m_readSet, 0, m_setSize);
|
|
||||||
std::memset(m_writeSet, 0, m_setSize);
|
|
||||||
std::memset(m_errorSet, 0, m_setSize);
|
|
||||||
|
|
||||||
unsigned int maxFd = static_cast<torrent::PollSelect*>(m_poll)->fdset(m_readSet, m_writeSet, m_errorSet);
|
|
||||||
|
|
||||||
timeval t = timeout.tval();
|
|
||||||
|
|
||||||
ThreadBase::entering_main_polling();
|
|
||||||
ThreadBase::release_global_lock();
|
|
||||||
|
|
||||||
int status = select(maxFd + 1, m_readSet, m_writeSet, m_errorSet, &t);
|
|
||||||
|
|
||||||
ThreadBase::leaving_main_polling();
|
|
||||||
ThreadBase::acquire_global_lock();
|
|
||||||
|
|
||||||
if (status == -1)
|
|
||||||
return check_error();
|
|
||||||
|
|
||||||
torrent::perform();
|
|
||||||
static_cast<torrent::PollSelect*>(m_poll)->perform(m_readSet, m_writeSet, m_errorSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PollManagerSelect::poll_simple(rak::timer timeout) {
|
PollManagerSelect::poll_simple(rak::timer timeout) {
|
||||||
torrent::PollSelect* currentPoll = static_cast<torrent::PollSelect*>(m_poll);
|
static_cast<torrent::PollSelect*>(m_poll)->do_poll(torrent::PollSelect::poll_worker_thread);
|
||||||
|
|
||||||
timeout = timeout + 1000;
|
|
||||||
std::memset(m_readSet, 0, 3 * m_setSize);
|
|
||||||
|
|
||||||
unsigned int maxFd = currentPoll->fdset(m_readSet, m_writeSet, m_errorSet);
|
|
||||||
|
|
||||||
timeval t = timeout.tval();
|
|
||||||
|
|
||||||
if (select(maxFd + 1, m_readSet, m_writeSet, m_errorSet, &t) == -1)
|
|
||||||
return check_error();
|
|
||||||
|
|
||||||
currentPoll->perform(m_readSet, m_writeSet, m_errorSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,9 +57,6 @@ private:
|
|||||||
PollManagerSelect(torrent::Poll* p);
|
PollManagerSelect(torrent::Poll* p);
|
||||||
|
|
||||||
unsigned int m_setSize;
|
unsigned int m_setSize;
|
||||||
fd_set* m_readSet;
|
|
||||||
fd_set* m_writeSet;
|
|
||||||
fd_set* m_errorSet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user