Permalink
Browse files

Merge branch 'cleanup'

Conflicts:
	src/protocol/handshake_manager.cc
	src/torrent/connection_manager.h
  • Loading branch information...
2 parents ac869ae + 1957566 commit 4ae336efce807fc2add944daa6280e05e0dd5bbd @rakshasa committed May 3, 2012
View
5 README
@@ -20,8 +20,7 @@ to the mailinglist.
LIBRARY DEPENDENCIES
- libsigc++ 2.0 (deb: libsigc++-2.0-dev)
- g++ >= 3.3
+ g++ >= 4.2.1
SIGC++
@@ -34,4 +33,4 @@ POLLING
"libtorrent/src/torrent/poll.h" provides an abstract class for
implementing any kind of polling the client wishes to use. Currently
-epoll and select based polling is included.
+epoll and select based polling is included.
View
4 configure.ac
@@ -95,10 +95,6 @@ AC_ARG_ENABLE(cyrus-rc4,
]
)
-PKG_CHECK_MODULES(STUFF, sigc++-2.0,
- CXXFLAGS="$CXXFLAGS $STUFF_CFLAGS";
- LIBS="$LIBS $STUFF_LIBS")
-
AC_CHECK_FUNCS(posix_memalign)
TORRENT_CHECK_MADVISE()
View
17 rak/functional.h
@@ -661,6 +661,23 @@ slot_list_call(const Container& slot_list, Arg1 arg1) {
(*first)(arg1);
}
+template <typename Container, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
+inline void
+slot_list_call(const Container& slot_list, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) {
+ if (slot_list.empty())
+ return;
+
+ typename Container::const_iterator first = slot_list.begin();
+ typename Container::const_iterator next = slot_list.begin();
+
+ while (++next != slot_list.end()) {
+ (*first)(arg1, arg2, arg3, arg4);
+ first = next;
+ }
+
+ (*first)(arg1, arg2, arg3, arg4);
+}
+
}
#endif
View
2 src/download/download_main.cc
@@ -155,7 +155,7 @@ std::pair<ThrottleList*, ThrottleList*>
DownloadMain::throttles(const sockaddr* sa) {
ThrottlePair pair = ThrottlePair(NULL, NULL);
- if (!manager->connection_manager()->address_throttle().empty())
+ if (manager->connection_manager()->address_throttle())
pair = manager->connection_manager()->address_throttle()(sa);
return std::make_pair(pair.first == NULL ? upload_throttle() : pair.first->throttle_list(),
View
1 src/download/download_main.h
@@ -39,7 +39,6 @@
#include <deque>
#include <rak/functional.h>
-#include <sigc++/signal.h>
#include "globals.h"
View
5 src/download/download_wrapper.cc
@@ -39,7 +39,6 @@
#include <iterator>
#include <stdlib.h>
#include <rak/file_stat.h>
-#include <sigc++/adaptors/bind.h>
#include "data/chunk_list.h"
#include "data/hash_queue.h"
@@ -108,8 +107,8 @@ DownloadWrapper::initialize(const std::string& hash, const std::string& id) {
info()->mutable_local_id().assign(id.c_str());
- info()->slot_left() = sigc::mem_fun(m_main->file_list(), &FileList::left_bytes);
- info()->slot_completed() = sigc::mem_fun(m_main->file_list(), &FileList::completed_bytes);
+ info()->slot_left() = tr1::bind(&FileList::left_bytes, m_main->file_list());
+ info()->slot_completed() = tr1::bind(&FileList::completed_bytes, m_main->file_list());
file_list()->mutable_data()->mutable_hash().assign(hash.c_str());
View
11 src/download/download_wrapper.h
@@ -37,11 +37,7 @@
#ifndef LIBTORRENT_DOWNLOAD_WRAPPER_H
#define LIBTORRENT_DOWNLOAD_WRAPPER_H
-#include <sigc++/connection.h>
-#include <sigc++/signal.h>
-
#include "data/chunk_handle.h"
-
#include "download_main.h"
namespace torrent {
@@ -59,10 +55,6 @@ class Peer;
class DownloadWrapper {
public:
- typedef sigc::signal0<void> Signal;
- typedef sigc::signal1<void, uint32_t> SignalChunk;
- typedef sigc::signal1<void, const std::string&> SignalString;
-
DownloadWrapper();
~DownloadWrapper();
@@ -126,9 +118,6 @@ class DownloadWrapper {
std::string m_hash;
int m_connectionType;
-
- sigc::connection m_connectionChunkPassed;
- sigc::connection m_connectionChunkFailed;
};
}
View
16 src/torrent/connection_manager.cc
@@ -47,8 +47,11 @@
#include "error.h"
#include "exceptions.h"
+namespace tr1 { using namespace std::tr1; }
+
namespace torrent {
+// Fix TrackerUdp, etc, if this is made async.
static ConnectionManager::slot_resolver_result_type*
resolve_host(const char* host, int family, int socktype, ConnectionManager::slot_resolver_result_type slot) {
rak::address_info* ai;
@@ -76,8 +79,7 @@ ConnectionManager::ConnectionManager() :
m_encryptionOptions(encryption_none),
m_listen(new Listen),
- m_listenPort(0),
- m_slotResolver(&resolve_host) {
+ m_listenPort(0) {
m_bindAddress = (new rak::socket_address())->c_sockaddr();
rak::socket_address::cast_from(m_bindAddress)->sa_inet()->clear();
@@ -87,6 +89,12 @@ ConnectionManager::ConnectionManager() :
m_proxyAddress = (new rak::socket_address())->c_sockaddr();
rak::socket_address::cast_from(m_proxyAddress)->sa_inet()->clear();
+
+ m_slot_resolver = tr1::bind(&resolve_host,
+ tr1::placeholders::_1,
+ tr1::placeholders::_2,
+ tr1::placeholders::_3,
+ tr1::placeholders::_4);
}
ConnectionManager::~ConnectionManager() {
@@ -153,10 +161,10 @@ ConnectionManager::set_proxy_address(const sockaddr* sa) {
uint32_t
ConnectionManager::filter(const sockaddr* sa) {
- if (m_slotFilter.empty())
+ if (!m_slot_filter)
return 1;
else
- return m_slotFilter(sa);
+ return m_slot_filter(sa);
}
bool
View
59 src/torrent/connection_manager.h
@@ -34,20 +34,19 @@
// Skomakerveien 33
// 3185 Skoppum, NORWAY
-// Add some helpfull words here.
+// Add some helpfull words here. (These are some words, hope they are
+// helpful)
#ifndef LIBTORRENT_CONNECTION_MANAGER_H
#define LIBTORRENT_CONNECTION_MANAGER_H
-#include <sys/socket.h>
+#include <list>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
-#include <sigc++/connection.h>
-#include <sigc++/signal.h>
-#include <sigc++/functors/slot.h>
-
+#include <sys/socket.h>
+#include <tr1/functional>
#include <torrent/common.h>
namespace torrent {
@@ -58,10 +57,9 @@ typedef std::pair<Throttle*, Throttle*> ThrottlePair;
class LIBTORRENT_EXPORT ConnectionManager {
public:
- typedef uint32_t size_type;
- typedef uint16_t port_type;
- typedef uint8_t priority_type;
- typedef sigc::slot<uint32_t, const sockaddr*> slot_filter_type;
+ typedef uint32_t size_type;
+ typedef uint16_t port_type;
+ typedef uint8_t priority_type;
static const priority_type iptos_default = 0;
static const priority_type iptos_lowdelay = IPTOS_LOWDELAY;
@@ -100,11 +98,12 @@ class LIBTORRENT_EXPORT ConnectionManager {
handshake_retry_encrypted = 9
};
- // The sockaddr argument in the result slot call is NULL if the resolve failed, and the int holds the errno.
- typedef sigc::slot2<void, const sockaddr*, int> slot_resolver_result_type;
- typedef sigc::slot4<slot_resolver_result_type*, const char*, int, int, slot_resolver_result_type> slot_resolver_type;
+ typedef std::tr1::function<uint32_t (const sockaddr*)> slot_filter_type;
+ typedef std::tr1::function<ThrottlePair (const sockaddr*)> slot_throttle_type;
- typedef sigc::slot1<ThrottlePair, const sockaddr*> slot_address_throttle_type;
+ // The sockaddr argument in the result slot call is NULL if the resolve failed, and the int holds the errno.
+ typedef std::tr1::function<void (const sockaddr*, int)> slot_resolver_result_type;
+ typedef std::tr1::function<slot_resolver_result_type* (const char*, int, int, slot_resolver_result_type)> slot_resolver_type;
ConnectionManager();
~ConnectionManager();
@@ -143,32 +142,30 @@ class LIBTORRENT_EXPORT ConnectionManager {
void set_proxy_address(const sockaddr* sa);
uint32_t filter(const sockaddr* sa);
- void set_filter(const slot_filter_type& s) { m_slotFilter = s; }
+ void set_filter(const slot_filter_type& s) { m_slot_filter = s; }
bool listen_open(port_type begin, port_type end);
void listen_close();
- // The resolver returns a pointer to its copy of the result slot
- // which the caller may set blocked to prevent the slot from being
- // called. The pointer must be NULL if the result slot was already
- // called because the resolve was synchronous.
- const slot_resolver_type& resolver() const { return m_slotResolver; }
- void set_resolver(const slot_resolver_type& s) { m_slotResolver = s; }
-
// Since trackers need our port number, it doesn't get cleared after
// 'listen_close()'. The client may change the reported port number,
// but do note that it gets overwritten after 'listen_open(...)'.
port_type listen_port() const { return m_listenPort; }
void set_listen_port(port_type p) { m_listenPort = p; }
- // The slot returns a ThrottlePair to use for the given address, or NULLs to use the default throttle.
- const slot_address_throttle_type&
- address_throttle() const { return m_slotAddressThrottle; }
- void set_address_throttle(const slot_address_throttle_type& s)
- { m_slotAddressThrottle = s; }
+
+ // The resolver returns a pointer to its copy of the result slot
+ // which the caller may set blocked to prevent the slot from being
+ // called. The pointer must be NULL if the result slot was already
+ // called because the resolve was synchronous.
+ slot_resolver_type& resolver() { return m_slot_resolver; }
+
+ // The slot returns a ThrottlePair to use for the given address, or
+ // NULLs to use the default throttle.
+ slot_throttle_type& address_throttle() { return m_slot_address_throttle; }
// For internal usage.
- Listen* listen() { return m_listen; }
+ Listen* listen() { return m_listen; }
private:
ConnectionManager(const ConnectionManager&);
@@ -189,9 +186,9 @@ class LIBTORRENT_EXPORT ConnectionManager {
Listen* m_listen;
port_type m_listenPort;
- slot_filter_type m_slotFilter;
- slot_resolver_type m_slotResolver;
- slot_address_throttle_type m_slotAddressThrottle;
+ slot_filter_type m_slot_filter;
+ slot_resolver_type m_slot_resolver;
+ slot_throttle_type m_slot_address_throttle;
};
}
View
2 src/torrent/download.cc
@@ -39,8 +39,6 @@
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
-#include <sigc++/adaptors/bind.h>
-#include <sigc++/adaptors/hide.h>
#include "data/block.h"
#include "data/block_list.h"
View
2 src/torrent/download.h
@@ -40,8 +40,6 @@
#include <list>
#include <vector>
#include <string>
-#include <sigc++/connection.h>
-#include <sigc++/functors/slot.h>
#include <torrent/common.h>
#include <torrent/peer/peer.h>
View
29 src/tracker/tracker_udp.cc
@@ -40,7 +40,6 @@
#include <sys/types.h>
-#include <sigc++/adaptors/bind.h>
#include <torrent/connection_manager.h>
#include <cstdio>
@@ -56,6 +55,8 @@
#include "tracker_udp.h"
#include "manager.h"
+namespace tr1 { using namespace std::tr1; }
+
#define LT_LOG_TRACKER(log_level, log_fmt, ...) \
lt_log_print_info(LOG_TRACKER_##log_level, m_parent->info(), "tracker", "[%u] " log_fmt, group(), __VA_ARGS__);
@@ -67,16 +68,18 @@ namespace torrent {
TrackerUdp::TrackerUdp(TrackerList* parent, const std::string& url, int flags) :
Tracker(parent, url, flags),
- m_slotResolver(NULL),
+ m_slot_resolver(NULL),
m_readBuffer(NULL),
m_writeBuffer(NULL) {
m_taskTimeout.slot() = std::tr1::bind(&TrackerUdp::receive_timeout, this);
}
TrackerUdp::~TrackerUdp() {
- if (m_slotResolver != NULL)
- static_cast<ConnectionManager::slot_resolver_result_type*>(m_slotResolver)->blocked();
+ if (m_slot_resolver != NULL) {
+ *m_slot_resolver = resolver_type();
+ m_slot_resolver = NULL;
+ }
close_directly();
}
@@ -100,17 +103,25 @@ TrackerUdp::send_state(int state) {
// Because we can only remember one slot, set any pending resolves blocked
// so that if this tracker is deleted, the member function won't be called.
- if (m_slotResolver != NULL)
- static_cast<ConnectionManager::slot_resolver_result_type*>(m_slotResolver)->blocked();
+ if (m_slot_resolver != NULL) {
+ *m_slot_resolver = resolver_type();
+ m_slot_resolver = NULL;
+ }
m_sendState = state;
- m_slotResolver = manager->connection_manager()->resolver()(hostname, PF_INET, SOCK_DGRAM,
- sigc::mem_fun(this, &TrackerUdp::start_announce));
+ m_slot_resolver = manager->connection_manager()->resolver()(hostname, PF_INET, SOCK_DGRAM,
+ tr1::bind(&TrackerUdp::start_announce,
+ this,
+ tr1::placeholders::_1,
+ tr1::placeholders::_2));
}
void
TrackerUdp::start_announce(const sockaddr* sa, int err) {
- m_slotResolver = NULL;
+ if (m_slot_resolver != NULL) {
+ *m_slot_resolver = resolver_type();
+ m_slot_resolver = NULL;
+ }
if (sa == NULL)
return receive_failed("Could not resolve hostname.");
View
5 src/tracker/tracker_udp.h
@@ -41,6 +41,7 @@
#include "net/protocol_buffer.h"
#include "net/socket_datagram.h"
+#include "torrent/connection_manager.h"
#include "torrent/tracker.h"
#include "globals.h"
@@ -52,6 +53,8 @@ class TrackerUdp : public SocketDatagram, public Tracker {
typedef ProtocolBuffer<512> ReadBuffer;
typedef ProtocolBuffer<512> WriteBuffer;
+ typedef ConnectionManager::slot_resolver_result_type resolver_type;
+
static const uint64_t magic_connection_id = 0x0000041727101980ll;
TrackerUdp(TrackerList* parent, const std::string& url, int flags);
@@ -92,7 +95,7 @@ class TrackerUdp : public SocketDatagram, public Tracker {
int m_sendState;
- void* m_slotResolver;
+ resolver_type* m_slot_resolver;
uint32_t m_action;
uint64_t m_connectionId;

0 comments on commit 4ae336e

Please sign in to comment.