Skip to content

Commit

Permalink
Cleaned up the signal API.
Browse files Browse the repository at this point in the history
Removed caughtExceptions, replaced with the
Download::signal_network_log(...).


git-svn-id: svn://rakshasa.no/libtorrent/trunk/libtorrent@342 e378c898-3ddf-0310-93e7-cc216c733640
  • Loading branch information
rakshasa committed Mar 12, 2005
1 parent 6aefafc commit 6d28d96
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 118 deletions.
47 changes: 7 additions & 40 deletions BUGS
Original file line number Diff line number Diff line change
@@ -1,45 +1,12 @@
test.cc caught "Connection write fd(18) state(10) "Throttle::spendt(...) error, used to many bytes""
*** glibc detected *** double free or corruption: 0x0805ec90 ***
Aborted
FIXME SOON:

Somehow every peer is marked interested, check if this is a real problem.
Caught exception: "System call msync failed in FileChunk"

test.cc caught "Connection read fd(67) state(1) "Empty HashQueue is still in service""
Removed the underlying file while it was open, then closed the torrent.

Writing "Refrain Blue OVA - 01.avi": Success
Writing "battlestar.galactica.s01e02.proper.pdtv-sfm.avi": Success
Exited
Signal SIGSEGV recived, dumping stack:
0 rtorrent [0x806f345]
1 /lib/tls/libc.so.6 [0x20bec8]
2 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2(_ZN7torrent7Service14remove_serviceEv+0xd8) [0x8e4988]
3 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2(_ZN7torrent7ServiceD2Ev+0x2a) [0x8e45ba]
4 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2 [0x8ed251]
5 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2 [0x8ef7fa]
6 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2 [0x8d52fb]
7 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2 [0x9262f6]
8 /lib/ld-linux.so.2 [0x621edd]
9 /lib/tls/libc.so.6(exit+0x63) [0x20e6d3]
10 /lib/tls/libc.so.6 [0x1f97ff]
11 rtorrent(dlopen+0x41) [0x8065f61]

FIXME LATER:

Signal SIGBUS recived, dumping stack:
0 rtorrent [0x80685f3]
1 rtorrent [0x80692c2]
2 rtorrent [0x806c62a]
3 /lib/tls/libc.so.6 [0x37aec8]
4 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2(_ZN4sigc8internal10slot_call2INS_12bind_functorILin1ENS_16pointer_functor4IiRKN7torrent8PeerInfoEPNS4_13DownloadStateEPNS4_11DownloadNetEPNS4_14PeerConnectionEEES9_SB_NS_3nilESF_SF_SF_SF_EESD_iS7_E7call_itEPNS0_8slot_repERKiS7_+0x29) [0x2ca8d9]
5 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2(_ZN7torrent11DownloadNet14add_connectionEiRKNS_8PeerInfoE+0x4d4) [0x2c5a14]
6 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2(_ZN7torrent18receive_connectionEiRKSsRKNS_8PeerInfoE+0x76) [0x2aaa56]
7 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2(_ZN4sigc8internal10slot_call3INS_16pointer_functor3IiRKSsRKN7torrent8PeerInfoEvEEviS4_S8_E7call_itEPNS0_8slot_repERKiS4_S8_+0x22) [0x2ad1f2]
8 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2(_ZN7torrent16HandshakeManager17receive_connectedEPNS_9HandshakeE+0x98) [0x2d2268]
9 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2(_ZN7torrent17HandshakeOutgoing4readEv+0xf1) [0x2d2e81]
10 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2(_ZN4algo8for_eachILb1ESt14_List_iteratorIPN7torrent10SocketBaseERS4_PS4_ENS_4IfOnINS2_18check_socket_issetENS_10CallMemberIS3_vNS_11back_as_refEEENS_5emptyEEEEEvT0_SF_T1_+0x67) [0x2ace17]
11 /uio/platon/mn-l2/jaris/local/lib/libtorrent.so.2(_ZN7torrent4workEP6fd_setS1_S1_i+0x186) [0x2abab6]
12 rtorrent [0x8077be5]
13 rtorrent [0x8077a8b]
14 rtorrent [0x8067b7a]
15 /lib/tls/libc.so.6(__libc_start_main+0xed) [0x36879d]
16 rtorrent(_ZNSt13runtime_errorC1ERKSs+0x3d) [0x8066751]
A bus error might mean you ran out of diskspace.
Caught exception: "DownloadWrapper::resume_save() called with wrong state"

Pressed ^D during hash check/resume check.
32 changes: 18 additions & 14 deletions src/download/download_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class PeerConnection;

class DownloadNet {
public:
typedef std::deque<PeerInfo> PeerContainer;
typedef std::list<PeerInfo> PeerList;
typedef std::list<PeerConnection*> ConnectionList;
typedef std::deque<PeerInfo> PeerContainer;
typedef std::list<PeerInfo> PeerList;
typedef std::list<PeerConnection*> ConnectionList;

DownloadNet() : m_settings(NULL), m_endgame(false) {}
~DownloadNet();
Expand Down Expand Up @@ -58,20 +58,23 @@ class DownloadNet {

// Signals and slots.

typedef sigc::signal1<void, Peer> SignalPeer;
typedef sigc::signal1<void, Peer> SignalPeer;
typedef sigc::signal1<void, const std::string&> SignalString;

typedef sigc::slot2<PeerConnection*, int, const PeerInfo&> SlotCreateConnection;
typedef sigc::slot1<void, const PeerInfo&> SlotStartHandshake;
typedef sigc::slot1<bool, const PeerInfo&> SlotHasHandshake;
typedef sigc::slot0<uint32_t> SlotCountHandshakes;
typedef sigc::slot2<PeerConnection*, int, const PeerInfo&> SlotCreateConnection;
typedef sigc::slot1<void, const PeerInfo&> SlotStartHandshake;
typedef sigc::slot1<bool, const PeerInfo&> SlotHasHandshake;
typedef sigc::slot0<uint32_t> SlotCountHandshakes;

SignalPeer& signal_peer_connected() { return m_signalPeerConnected; }
SignalPeer& signal_peer_disconnected() { return m_signalPeerDisconnected; }
SignalPeer& signal_peer_connected() { return m_signalPeerConnected; }
SignalPeer& signal_peer_disconnected() { return m_signalPeerDisconnected; }

void slot_create_connection(SlotCreateConnection s) { m_slotCreateConnection = s; }
void slot_start_handshake(SlotStartHandshake s) { m_slotStartHandshake = s; }
void slot_has_handshake(SlotHasHandshake s) { m_slotHasHandshake = s; }
void slot_count_handshakes(SlotCountHandshakes s) { m_slotCountHandshakes = s; }
SignalString& signal_network_log() { return m_signalNetworkLog; }

void slot_create_connection(SlotCreateConnection s) { m_slotCreateConnection = s; }
void slot_start_handshake(SlotStartHandshake s) { m_slotStartHandshake = s; }
void slot_has_handshake(SlotHasHandshake s) { m_slotHasHandshake = s; }
void slot_count_handshakes(SlotCountHandshakes s) { m_slotCountHandshakes = s; }

private:
DownloadNet(const DownloadNet&);
Expand All @@ -89,6 +92,7 @@ class DownloadNet {

SignalPeer m_signalPeerConnected;
SignalPeer m_signalPeerDisconnected;
SignalString m_signalNetworkLog;

SlotCreateConnection m_slotCreateConnection;
SlotStartHandshake m_slotStartHandshake;
Expand Down
2 changes: 0 additions & 2 deletions src/download/download_setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace torrent {

extern std::list<std::string> caughtExceptions;

void
DownloadMain::setup_delegator() {
m_net.get_delegator().get_select().set_bitfield(&m_state.get_content().get_bitfield());
Expand Down
15 changes: 6 additions & 9 deletions src/peer_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ using namespace algo;

namespace torrent {

// Find a better way to do this?
extern std::list<std::string> caughtExceptions;

PeerConnection*
PeerConnection::create(int fd, const PeerInfo& p, DownloadState* d, DownloadNet* net) {
PeerConnection* pc = new PeerConnection;
Expand Down Expand Up @@ -181,7 +178,7 @@ void PeerConnection::read() {
if (m_down.lengthOrig == 9) {
// Some clients send zero length messages when we request pieces
// they don't have.
caughtExceptions.push_front("Received piece with length zero");
m_net->signal_network_log().emit("Received piece with length zero");

m_down.state = IDLE;
goto evil_goto_read;
Expand All @@ -203,7 +200,7 @@ void PeerConnection::read() {
m_down.length = piece.get_length();
m_down.state = READ_SKIP_PIECE;

caughtExceptions.push_back("Receiving piece we don't want from " + m_peer.get_dns());
m_net->signal_network_log().emit("Receiving piece we don't want from " + m_peer.get_dns());
}

goto evil_goto_read;
Expand Down Expand Up @@ -313,7 +310,7 @@ void PeerConnection::read() {
m_net->remove_connection(this);

} catch (network_error& e) {
caughtExceptions.push_front(e.what());
m_net->signal_network_log().emit(e.what());

m_net->remove_connection(this);

Expand Down Expand Up @@ -436,7 +433,7 @@ void PeerConnection::write() {
m_net->remove_connection(this);

} catch (network_error& e) {
caughtExceptions.push_front(e.what());
m_net->signal_network_log().emit(e.what());

m_net->remove_connection(this);

Expand All @@ -451,7 +448,7 @@ void PeerConnection::write() {
}

void PeerConnection::except() {
caughtExceptions.push_front("Connection exception: " + std::string(strerror(errno)));
m_net->signal_network_log().emit("Connection exception: " + std::string(strerror(errno)));

m_net->remove_connection(this);
}
Expand Down Expand Up @@ -727,7 +724,7 @@ PeerConnection::task_stall() {
// entries get those new ones stalled if needed.
m_taskStall.insert(Timer::cache() + m_download->get_settings().stallTimeout);

caughtExceptions.push_back("Peer stalled " + m_peer.get_dns());
m_net->signal_network_log().emit("Peer stalled " + m_peer.get_dns());
}

}
Expand Down
2 changes: 0 additions & 2 deletions src/peer_connection_extra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ using namespace algo;

namespace torrent {

extern std::list<std::string> caughtExceptions;

PeerConnection::PeerConnection() :
m_shutdown(false),
m_stallCount(0),
Expand Down
34 changes: 34 additions & 0 deletions src/rate.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,40 @@ class Rate {
mutable std::deque<std::pair<Timer, int> > m_entries;
};

/* New rate class draft
class Rate : private std::deque<std::pair<Timer, uint32_t> > {
public:
typedef std::deque<std::pair<Timer, uint32_t> > Base;
using Base::value_type;
Rate() : m_current(0), m_total(0) {}
uint32_t rate() const;
uint64_t total() const { return m_total; }
void insert(uint32_t bytes) {
bool operator < (Rate& r) {
return rate() < r.rate();
}
bool operator > (Rate& r) {
return rate() > r.rate();
}
// TODO: Make this less accurate?
bool operator == (Rate& r) {
return rate() == r.rate();
}
private:
mutable uint32_t m_current;
uint64_t m_total;
}
*/

}

#endif // LIBTORRENT_RATE_H
15 changes: 10 additions & 5 deletions src/torrent/download.cc
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,12 @@ Download::peer_find(const std::string& id) {
}

sigc::connection
Download::signal_download_done(Download::Slot s) {
Download::signal_download_done(Download::SlotVoid s) {
return m_ptr->get_main().get_state().get_content().signal_download_done().connect(s);
}

sigc::connection
Download::signal_hash_done(Download::Slot s) {
Download::signal_hash_done(Download::SlotVoid s) {
return m_ptr->get_hash_checker().signal_torrent().connect(s);
}

Expand All @@ -346,17 +346,17 @@ Download::signal_peer_disconnected(Download::SlotPeer s) {
}

sigc::connection
Download::signal_tracker_succeded(Download::Slot s) {
Download::signal_tracker_succeded(Download::SlotVoid s) {
return m_ptr->get_main().get_tracker().signal_peers().connect(sigc::hide(s));
}

sigc::connection
Download::signal_tracker_failed(Download::SlotTrackerFailed s) {
Download::signal_tracker_failed(Download::SlotString s) {
return m_ptr->get_main().get_tracker().signal_failed().connect(s);
}

sigc::connection
Download::signal_tracker_dump(Download::SlotTrackerDump s) {
Download::signal_tracker_dump(Download::SlotBencode s) {
return m_ptr->get_main().get_tracker().signal_bencode().connect(s);
}

Expand All @@ -370,4 +370,9 @@ Download::signal_chunk_failed(Download::SlotChunk s) {
return m_ptr->get_main().get_state().signal_chunk_failed().connect(s);
}

sigc::connection
Download::signal_network_log(SlotString s) {
return m_ptr->get_main().get_net().signal_network_log().connect(s);
}

}
23 changes: 13 additions & 10 deletions src/torrent/download.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,29 @@ class Download {
// class does not get copied as the binding only points to the original
// memory location.

typedef sigc::slot0<void> Slot;
typedef sigc::slot0<void> SlotVoid;
typedef sigc::slot1<void, const std::string&> SlotString;

typedef sigc::slot1<void, Peer> SlotPeer;
typedef sigc::slot1<void, Bencode&> SlotTrackerDump;
typedef sigc::slot1<void, std::string> SlotTrackerFailed;
typedef sigc::slot1<void, uint32_t> SlotChunk;
typedef sigc::slot1<void, Peer> SlotPeer;
typedef sigc::slot1<void, Bencode&> SlotBencode;
typedef sigc::slot1<void, uint32_t> SlotChunk;

sigc::connection signal_download_done(Slot s);
sigc::connection signal_hash_done(Slot s);
sigc::connection signal_download_done(SlotVoid s);
sigc::connection signal_hash_done(SlotVoid s);

sigc::connection signal_peer_connected(SlotPeer s);
sigc::connection signal_peer_disconnected(SlotPeer s);

sigc::connection signal_tracker_succeded(Slot s);
sigc::connection signal_tracker_failed(SlotTrackerFailed s);
sigc::connection signal_tracker_dump(SlotTrackerDump s);
sigc::connection signal_tracker_succeded(SlotVoid s);
sigc::connection signal_tracker_failed(SlotString s);
sigc::connection signal_tracker_dump(SlotBencode s);

sigc::connection signal_chunk_passed(SlotChunk s);
sigc::connection signal_chunk_failed(SlotChunk s);

// Various log message signals.
sigc::connection signal_network_log(SlotString s);

private:
DownloadWrapper* m_ptr;
};
Expand Down
14 changes: 7 additions & 7 deletions src/torrent/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace torrent {
// Keep in mind that these objects get reused.
class Http {
public:
typedef sigc::signal0<void> SignalDone;
typedef sigc::signal1<void, std::string> SignalFailed;
typedef sigc::slot0<Http*> SlotFactory;
typedef sigc::signal0<void> Signal;
typedef sigc::signal1<void, const std::string&> SignalString;
typedef sigc::slot0<Http*> SlotFactory;

Http() : m_userAgent("not_set"), m_stream(NULL) {}
virtual ~Http();
Expand All @@ -32,8 +32,8 @@ class Http {
void set_user_agent(const std::string& s) { m_userAgent = s; }
const std::string& get_user_agent() { return m_userAgent; }

SignalDone& signal_done() { return m_signalDone; }
SignalFailed& signal_failed() { return m_signalFailed; }
Signal& signal_done() { return m_signalDone; }
SignalString& signal_failed() { return m_signalFailed; }

// Set the factory function that constructs and returns a valid Http* object.
static void set_factory(const SlotFactory& f);
Expand All @@ -46,8 +46,8 @@ class Http {
std::string m_userAgent;
std::iostream* m_stream;

SignalDone m_signalDone;
SignalFailed m_signalFailed;
Signal m_signalDone;
SignalString m_signalFailed;

private:
// Disabled ctor. Do we want ref counting instead?
Expand Down
15 changes: 0 additions & 15 deletions src/torrent/torrent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ using namespace algo;
namespace torrent {

int64_t Timer::m_cache;
std::list<std::string> caughtExceptions;

Listen* listen = NULL;
HashQueue* hashQueue = NULL;
Expand Down Expand Up @@ -180,8 +179,6 @@ work(fd_set* readSet, fd_set* writeSet, fd_set* exceptSet, int maxFd) {
// Make sure we don't do read/write on fd's that are in except. This should
// not be a problem as any except call should remove it from the m_*Set's.

caughtExceptions.clear();

// If except is called, make sure you correctly remove us from the poll.
for_each<true>(SocketBase::except_sockets().begin(), SocketBase::except_sockets().end(),
if_on(check_socket_isset(exceptSet),
Expand Down Expand Up @@ -293,9 +290,6 @@ get(GValue t) {
case DEFAULT_CHOKE_CYCLE:
return DownloadSettings::global().chokeCycle;

case HAS_EXCEPTION:
return !caughtExceptions.empty();

case TIME_CURRENT:
return Timer::current().usec();

Expand All @@ -318,15 +312,6 @@ get(GString t) {
case LIBRARY_NAME:
return std::string("libtorrent") + " " VERSION;

case POP_EXCEPTION:
if (caughtExceptions.empty())
throw internal_error("get(GString) tried to pop an exception from an empty list");

s = caughtExceptions.front();
caughtExceptions.pop_front();

return s;

default:
throw internal_error("get(GString) received invalid type");
}
Expand Down
Loading

0 comments on commit 6d28d96

Please sign in to comment.