From 6c67da08d6cdd2b4f48844e5715482d7d338b442 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 16 Sep 2009 03:46:36 +0000 Subject: [PATCH] split socket.hpp up in multiple headers to lower build time somewhat --- CMakeLists.txt | 1 + Jamfile | 1 + include/libtorrent/Makefile.am | 2 + include/libtorrent/alert_types.hpp | 1 + include/libtorrent/aux_/session_impl.hpp | 1 + include/libtorrent/bandwidth_manager.hpp | 2 + include/libtorrent/broadcast_socket.hpp | 1 + include/libtorrent/connection_queue.hpp | 3 +- include/libtorrent/deadline_timer.hpp | 93 +++++++++++++++ include/libtorrent/enum_net.hpp | 1 + include/libtorrent/http_connection.hpp | 3 +- include/libtorrent/i2p_stream.hpp | 2 +- include/libtorrent/kademlia/dht_tracker.hpp | 1 + include/libtorrent/lsd.hpp | 1 + include/libtorrent/natpmp.hpp | 2 + include/libtorrent/peer_info.hpp | 1 + include/libtorrent/proxy_base.hpp | 2 + include/libtorrent/socket.hpp | 115 ------------------- include/libtorrent/socket_io.hpp | 118 ++++++++++++++++++++ include/libtorrent/storage.hpp | 1 - include/libtorrent/time.hpp | 33 ------ include/libtorrent/torrent.hpp | 1 + include/libtorrent/tracker_manager.hpp | 2 +- include/libtorrent/udp_socket.hpp | 2 + include/libtorrent/upnp.hpp | 2 + include/libtorrent/variant_stream.hpp | 4 + src/Makefile.am | 3 +- src/connection_queue.cpp | 1 + src/enum_net.cpp | 1 + src/http_stream.cpp | 1 + src/http_tracker_connection.cpp | 1 + src/i2p_stream.cpp | 5 +- src/kademlia/dht_tracker.cpp | 1 + src/natpmp.cpp | 1 + src/session_impl.cpp | 4 +- src/socket_io.cpp | 78 +++++++++++++ src/socks5_stream.cpp | 1 + src/udp_socket.cpp | 3 + src/upnp.cpp | 1 + src/ut_pex.cpp | 1 + test/test_ip_filter.cpp | 1 + 41 files changed, 341 insertions(+), 158 deletions(-) create mode 100644 include/libtorrent/deadline_timer.hpp create mode 100644 include/libtorrent/socket_io.hpp create mode 100644 src/socket_io.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f5b86ab5..ed64c411f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ set(sources policy session session_impl + socket_io socks5_stream stat storage diff --git a/Jamfile b/Jamfile index e02f221ad..c1370349c 100755 --- a/Jamfile +++ b/Jamfile @@ -368,6 +368,7 @@ SOURCES = policy session session_impl + socket_io socks5_stream stat storage diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index d85cf7b25..c3698f3fb 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -18,6 +18,7 @@ nobase_include_HEADERS = \ ConvertUTF.h \ create_torrent.hpp \ debug.hpp \ + deadline_timer.hpp \ disk_buffer_holder.hpp \ disk_io_thread.hpp \ entry.hpp \ @@ -67,6 +68,7 @@ nobase_include_HEADERS = \ size_type.hpp \ socket.hpp \ socket_type.hpp \ + socket_io.hpp \ socks5_stream.hpp \ ssl_stream.hpp \ stat.hpp \ diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index a51b38d9c..598e52fd4 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/identify_client.hpp" +#include "libtorrent/socket_io.hpp" namespace libtorrent { diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 4ab8afd90..0b425a52c 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -77,6 +77,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/policy.hpp" // for policy::peer #include "libtorrent/alert.hpp" // for alert_manager +#include "libtorrent/deadline_timer.hpp" namespace libtorrent { diff --git a/include/libtorrent/bandwidth_manager.hpp b/include/libtorrent/bandwidth_manager.hpp index 7bb501bfc..344669de5 100644 --- a/include/libtorrent/bandwidth_manager.hpp +++ b/include/libtorrent/bandwidth_manager.hpp @@ -40,10 +40,12 @@ POSSIBILITY OF SUCH DAMAGE. #endif #include "libtorrent/socket.hpp" +#include "libtorrent/error_code.hpp" #include "libtorrent/invariant_check.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/bandwidth_limit.hpp" #include "libtorrent/bandwidth_queue_entry.hpp" +#include "libtorrent/time.hpp" using boost::intrusive_ptr; diff --git a/include/libtorrent/broadcast_socket.hpp b/include/libtorrent/broadcast_socket.hpp index 00b246fdc..edf97832d 100644 --- a/include/libtorrent/broadcast_socket.hpp +++ b/include/libtorrent/broadcast_socket.hpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/error_code.hpp" #include #include #include diff --git a/include/libtorrent/connection_queue.hpp b/include/libtorrent/connection_queue.hpp index c5b8c8939..a353afcbf 100644 --- a/include/libtorrent/connection_queue.hpp +++ b/include/libtorrent/connection_queue.hpp @@ -38,7 +38,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include "libtorrent/socket.hpp" -#include "libtorrent/time.hpp" +#include "libtorrent/error_code.hpp" +#include "libtorrent/deadline_timer.hpp" #ifdef TORRENT_CONNECTION_LOGGING #include diff --git a/include/libtorrent/deadline_timer.hpp b/include/libtorrent/deadline_timer.hpp new file mode 100644 index 000000000..a57597eef --- /dev/null +++ b/include/libtorrent/deadline_timer.hpp @@ -0,0 +1,93 @@ +/* + +Copyright (c) 2009, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TORRENT_DEADLINE_TIMER_HPP_INCLUDED +#define TORRENT_DEADLINE_TIMER_HPP_INCLUDED + +#ifdef __OBJC__ +#define Protocol Protocol_ +#endif + +#if BOOST_VERSION < 103500 +#include +#include +#else +#include +#include +#endif + +#ifdef __OBJC__ +#undef Protocol +#endif + +#include "libtorrent/time.hpp" + +// asio time_traits +#if BOOST_VERSION >= 103500 +namespace boost { +#endif +namespace asio +{ + template<> + struct time_traits + { + typedef libtorrent::ptime time_type; + typedef libtorrent::time_duration duration_type; + static time_type now() + { return time_type(libtorrent::time_now_hires()); } + static time_type add(time_type t, duration_type d) + { return time_type(t.time + d.diff);} + static duration_type subtract(time_type t1, time_type t2) + { return duration_type(t1 - t2); } + static bool less_than(time_type t1, time_type t2) + { return t1 < t2; } + static boost::posix_time::time_duration to_posix_duration( + duration_type d) + { return boost::posix_time::microseconds(libtorrent::total_microseconds(d)); } + }; +} +#if BOOST_VERSION >= 103500 +} +#endif + +namespace libtorrent +{ + +#if BOOST_VERSION < 103500 + typedef ::asio::basic_deadline_timer deadline_timer; +#else + typedef boost::asio::basic_deadline_timer deadline_timer; +#endif +} + +#endif // TORRENT_DEADLINE_TIMER_HPP_INCLUDED + diff --git a/include/libtorrent/enum_net.hpp b/include/libtorrent/enum_net.hpp index 643c4c0c0..da3e9c319 100644 --- a/include/libtorrent/enum_net.hpp +++ b/include/libtorrent/enum_net.hpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/error_code.hpp" namespace libtorrent { diff --git a/include/libtorrent/http_connection.hpp b/include/libtorrent/http_connection.hpp index eba930a5f..601257c9c 100644 --- a/include/libtorrent/http_connection.hpp +++ b/include/libtorrent/http_connection.hpp @@ -43,8 +43,9 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "libtorrent/socket.hpp" +#include "libtorrent/error_code.hpp" #include "libtorrent/http_parser.hpp" -#include "libtorrent/time.hpp" +#include "libtorrent/deadline_timer.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/socket_type.hpp" #include "libtorrent/session_settings.hpp" diff --git a/include/libtorrent/i2p_stream.hpp b/include/libtorrent/i2p_stream.hpp index 094b28c43..19c8d6e31 100644 --- a/include/libtorrent/i2p_stream.hpp +++ b/include/libtorrent/i2p_stream.hpp @@ -169,7 +169,7 @@ public: && m_state != sam_connecting; } void open(proxy_settings const& s, i2p_stream::handler_type const& h); - void close(); + void close(error_code&); char const* session_id() const { return m_session_id.c_str(); } std::string const& local_endpoint() const { return m_i2p_local_endpoint; } diff --git a/include/libtorrent/kademlia/dht_tracker.hpp b/include/libtorrent/kademlia/dht_tracker.hpp index 55105b310..7be5cbb56 100644 --- a/include/libtorrent/kademlia/dht_tracker.hpp +++ b/include/libtorrent/kademlia/dht_tracker.hpp @@ -53,6 +53,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/session_status.hpp" #include "libtorrent/udp_socket.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/deadline_timer.hpp" namespace libtorrent { diff --git a/include/libtorrent/lsd.hpp b/include/libtorrent/lsd.hpp index 6e3ddea7d..61c8fe3cc 100644 --- a/include/libtorrent/lsd.hpp +++ b/include/libtorrent/lsd.hpp @@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer_id.hpp" #include "libtorrent/broadcast_socket.hpp" #include "libtorrent/intrusive_ptr_base.hpp" +#include "libtorrent/deadline_timer.hpp" #include #include diff --git a/include/libtorrent/natpmp.hpp b/include/libtorrent/natpmp.hpp index 698a67467..c568ae552 100644 --- a/include/libtorrent/natpmp.hpp +++ b/include/libtorrent/natpmp.hpp @@ -34,7 +34,9 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_NATPMP_HPP #include "libtorrent/socket.hpp" +#include "libtorrent/error_code.hpp" #include "libtorrent/intrusive_ptr_base.hpp" +#include "libtorrent/deadline_timer.hpp" #include #include diff --git a/include/libtorrent/peer_info.hpp b/include/libtorrent/peer_info.hpp index e2b99dc55..40fd77ccc 100644 --- a/include/libtorrent/peer_info.hpp +++ b/include/libtorrent/peer_info.hpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_PEER_INFO_HPP_INCLUDED #include "libtorrent/socket.hpp" +#include "libtorrent/deadline_timer.hpp" #include "libtorrent/peer_id.hpp" #include "libtorrent/size_type.hpp" #include "libtorrent/config.hpp" diff --git a/include/libtorrent/proxy_base.hpp b/include/libtorrent/proxy_base.hpp index 3b3b3020c..40795db48 100644 --- a/include/libtorrent/proxy_base.hpp +++ b/include/libtorrent/proxy_base.hpp @@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/io.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/escape_string.hpp" +#include "libtorrent/error_code.hpp" #include #include #if BOOST_VERSION < 103500 diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index d490582eb..e77d6e096 100644 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -51,31 +51,20 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #include #include -#include -#include #else #include #include #include -#include #include #include -#include -#include #endif #ifdef __OBJC__ #undef Protocol #endif -#include "libtorrent/io.hpp" -#include "libtorrent/time.hpp" -#include "libtorrent/error_code.hpp" -#include "libtorrent/escape_string.hpp" // for to_string - #ifdef _MSC_VER #pragma warning(pop) #endif @@ -96,7 +85,6 @@ namespace libtorrent typedef ::asio::ip::udp::socket datagram_socket; typedef ::asio::ip::tcp::acceptor socket_acceptor; typedef ::asio::io_service io_service; - typedef ::asio::basic_deadline_timer deadline_timer; #else using boost::asio::ip::tcp; using boost::asio::ip::udp; @@ -112,111 +100,8 @@ namespace libtorrent typedef boost::asio::io_service io_service; namespace asio = boost::asio; - typedef boost::asio::basic_deadline_timer deadline_timer; #endif - inline std::string print_address(address const& addr) - { - error_code ec; - return addr.to_string(ec); - } - - inline std::string print_endpoint(tcp::endpoint const& ep) - { - error_code ec; - std::string ret; - address const& addr = ep.address(); -#if TORRENT_USE_IPV6 - if (addr.is_v6()) - { - ret += '['; - ret += addr.to_string(ec); - ret += ']'; - ret += ':'; - ret += to_string(ep.port()).elems; - } - else -#endif - { - ret += addr.to_string(ec); - ret += ':'; - ret += to_string(ep.port()).elems; - } - return ret; - } - - inline std::string print_endpoint(udp::endpoint const& ep) - { - return print_endpoint(tcp::endpoint(ep.address(), ep.port())); - } - - namespace detail - { - template - void write_address(address const& a, OutIt& out) - { -#if TORRENT_USE_IPV6 - if (a.is_v4()) - { -#endif - write_uint32(a.to_v4().to_ulong(), out); -#if TORRENT_USE_IPV6 - } - else if (a.is_v6()) - { - address_v6::bytes_type bytes - = a.to_v6().to_bytes(); - std::copy(bytes.begin(), bytes.end(), out); - } -#endif - } - - template - address read_v4_address(InIt& in) - { - unsigned long ip = read_uint32(in); - return address_v4(ip); - } - -#if TORRENT_USE_IPV6 - template - address read_v6_address(InIt& in) - { - typedef address_v6::bytes_type bytes_t; - bytes_t bytes; - for (bytes_t::iterator i = bytes.begin() - , end(bytes.end()); i != end; ++i) - *i = read_uint8(in); - return address_v6(bytes); - } -#endif - - template - void write_endpoint(Endpoint const& e, OutIt& out) - { - write_address(e.address(), out); - write_uint16(e.port(), out); - } - - template - Endpoint read_v4_endpoint(InIt& in) - { - address addr = read_v4_address(in); - int port = read_uint16(in); - return Endpoint(addr, port); - } - -#if TORRENT_USE_IPV6 - template - Endpoint read_v6_endpoint(InIt& in) - { - address addr = read_v6_address(in); - int port = read_uint16(in); - return Endpoint(addr, port); - } -#endif - } - #if TORRENT_USE_IPV6 struct v6only { diff --git a/include/libtorrent/socket_io.hpp b/include/libtorrent/socket_io.hpp new file mode 100644 index 000000000..e21afa12b --- /dev/null +++ b/include/libtorrent/socket_io.hpp @@ -0,0 +1,118 @@ +/* + +Copyright (c) 2009, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TORRENT_SOCKET_IO_HPP_INCLUDED +#define TORRENT_SOCKET_IO_HPP_INCLUDED + +#include "libtorrent/socket.hpp" +#include "libtorrent/io.hpp" +#include "libtorrent/error_code.hpp" +#include + +namespace libtorrent +{ + std::string print_address(address const& addr); + std::string print_endpoint(tcp::endpoint const& ep); + std::string print_endpoint(udp::endpoint const& ep); + + namespace detail + { + template + void write_address(address const& a, OutIt& out) + { +#if TORRENT_USE_IPV6 + if (a.is_v4()) + { +#endif + write_uint32(a.to_v4().to_ulong(), out); +#if TORRENT_USE_IPV6 + } + else if (a.is_v6()) + { + address_v6::bytes_type bytes + = a.to_v6().to_bytes(); + std::copy(bytes.begin(), bytes.end(), out); + } +#endif + } + + template + address read_v4_address(InIt& in) + { + unsigned long ip = read_uint32(in); + return address_v4(ip); + } + +#if TORRENT_USE_IPV6 + template + address read_v6_address(InIt& in) + { + typedef address_v6::bytes_type bytes_t; + bytes_t bytes; + for (bytes_t::iterator i = bytes.begin() + , end(bytes.end()); i != end; ++i) + *i = read_uint8(in); + return address_v6(bytes); + } +#endif + + template + void write_endpoint(Endpoint const& e, OutIt& out) + { + write_address(e.address(), out); + write_uint16(e.port(), out); + } + + template + Endpoint read_v4_endpoint(InIt& in) + { + address addr = read_v4_address(in); + int port = read_uint16(in); + return Endpoint(addr, port); + } + +#if TORRENT_USE_IPV6 + template + Endpoint read_v6_endpoint(InIt& in) + { + address addr = read_v6_address(in); + int port = read_uint16(in); + return Endpoint(addr, port); + } +#endif + } + + +} + +#endif + diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index c291763a4..6d7aeaed6 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -34,7 +34,6 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_STORAGE_HPP_INCLUDE #include -#include #ifdef _MSC_VER #pragma warning(push, 1) diff --git a/include/libtorrent/time.hpp b/include/libtorrent/time.hpp index d0502cb55..75bdaaf3c 100644 --- a/include/libtorrent/time.hpp +++ b/include/libtorrent/time.hpp @@ -87,11 +87,6 @@ namespace libtorrent #else // TORRENT_USE_BOOST_DATE_TIME -#if BOOST_VERSION < 103500 -#include -#else -#include -#endif #include #include "libtorrent/assert.hpp" @@ -166,34 +161,6 @@ namespace libtorrent boost::int64_t total_microseconds(time_duration td); } -// asio time_traits -#if BOOST_VERSION >= 103500 -namespace boost { -#endif -namespace asio -{ - template<> - struct time_traits - { - typedef libtorrent::ptime time_type; - typedef libtorrent::time_duration duration_type; - static time_type now() - { return time_type(libtorrent::time_now_hires()); } - static time_type add(time_type t, duration_type d) - { return time_type(t.time + d.diff);} - static duration_type subtract(time_type t1, time_type t2) - { return duration_type(t1 - t2); } - static bool less_than(time_type t1, time_type t2) - { return t1 < t2; } - static boost::posix_time::time_duration to_posix_duration( - duration_type d) - { return boost::posix_time::microseconds(libtorrent::total_microseconds(d)); } - }; -} -#if BOOST_VERSION >= 103500 -} -#endif - #if defined TORRENT_USE_ABSOLUTE_TIME #include diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index e56adcbad..c919b9930 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -71,6 +71,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/bitfield.hpp" #include "libtorrent/aux_/session_impl.hpp" +#include "libtorrent/deadline_timer.hpp" namespace libtorrent { diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 36fd52b98..586d3989f 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -60,7 +60,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer_id.hpp" #include "libtorrent/peer.hpp" #include "libtorrent/config.hpp" -#include "libtorrent/time.hpp" +#include "libtorrent/deadline_timer.hpp" #include "libtorrent/connection_queue.hpp" #include "libtorrent/intrusive_ptr_base.hpp" diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index bc9f5cb2c..af2a68f02 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -34,8 +34,10 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_UDP_SOCKET_HPP_INCLUDED #include "libtorrent/socket.hpp" +#include "libtorrent/error_code.hpp" #include "libtorrent/session_settings.hpp" #include "libtorrent/buffer.hpp" +#include "libtorrent/deadline_timer.hpp" #include #include diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index cc55fafc5..37792fba1 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -34,10 +34,12 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_UPNP_HPP #include "libtorrent/socket.hpp" +#include "libtorrent/error_code.hpp" #include "libtorrent/broadcast_socket.hpp" #include "libtorrent/http_connection.hpp" #include "libtorrent/connection_queue.hpp" #include "libtorrent/intrusive_ptr_base.hpp" +#include "libtorrent/deadline_timer.hpp" #include #include diff --git a/include/libtorrent/variant_stream.hpp b/include/libtorrent/variant_stream.hpp index e596350ba..2001c8e12 100644 --- a/include/libtorrent/variant_stream.hpp +++ b/include/libtorrent/variant_stream.hpp @@ -27,6 +27,10 @@ #include #endif +#include "libtorrent/config.hpp" +#include "libtorrent/error_code.hpp" +#include "libtorrent/assert.hpp" + # define NETWORK_VARIANT_STREAM_LIMIT 5 namespace libtorrent { diff --git a/src/Makefile.am b/src/Makefile.am index 836dbdf03..a6db32383 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -62,6 +62,7 @@ libtorrent_rasterbar_la_SOURCES = \ sha1.cpp \ smart_ban.cpp \ socks5_stream.cpp \ + socket_io.cpp \ stat.cpp \ storage.cpp \ torrent.cpp \ @@ -78,7 +79,6 @@ libtorrent_rasterbar_la_SOURCES = \ $(KADEMLIA_SOURCES) \ $(GEOIP_SOURCES) - #libtorrent_rasterbar_la_LDFLAGS = $(LDFLAGS) -version-info $(INTERFACE_VERSION_INFO) libtorrent_rasterbar_la_LDFLAGS = -version-info $(INTERFACE_VERSION_INFO) @@ -99,3 +99,4 @@ if WITH_SHIPPED_ZLIB libtorrent_rasterbar_la_LIBADD += $(top_builddir)/zlib/libzlib.la AM_CPPFLAGS += -I$(top_srcdir)/zlib endif + diff --git a/src/connection_queue.cpp b/src/connection_queue.cpp index 87a781b3f..bc5313d2c 100644 --- a/src/connection_queue.cpp +++ b/src/connection_queue.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/invariant_check.hpp" #include "libtorrent/connection_queue.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/error_code.hpp" namespace libtorrent { diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 7d618d2c2..90fb0312e 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "libtorrent/enum_net.hpp" #include "libtorrent/broadcast_socket.hpp" +#include "libtorrent/error_code.hpp" #if BOOST_VERSION < 103500 #include #else diff --git a/src/http_stream.cpp b/src/http_stream.cpp index a72637e82..c482f13e7 100644 --- a/src/http_stream.cpp +++ b/src/http_stream.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/http_stream.hpp" #include "libtorrent/escape_string.hpp" // for base64encode +#include "libtorrent/socket_io.hpp" namespace libtorrent { diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index aff077fe6..4abde6434 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/gzip.hpp" +#include "libtorrent/socket_io.hpp" #ifdef _MSC_VER #pragma warning(push, 1) diff --git a/src/i2p_stream.cpp b/src/i2p_stream.cpp index 3329630f8..7013355f4 100644 --- a/src/i2p_stream.cpp +++ b/src/i2p_stream.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/i2p_stream.hpp" #include "libtorrent/assert.hpp" +#include "libtorrent/error_code.hpp" #include @@ -74,9 +75,9 @@ namespace libtorrent i2p_connection::~i2p_connection() {} - void i2p_connection::close() + void i2p_connection::close(error_code& e) { - if (m_sam_socket) m_sam_socket->close(); + if (m_sam_socket) m_sam_socket->close(e); } void i2p_connection::open(proxy_settings const& s, i2p_stream::handler_type const& handler) diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index 65c1d536b..37d7ff63d 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -50,6 +50,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/socket_io.hpp" #include "libtorrent/bencode.hpp" #include "libtorrent/io.hpp" #include "libtorrent/version.hpp" diff --git a/src/natpmp.cpp b/src/natpmp.cpp index 2a99377a4..d5f79d229 100644 --- a/src/natpmp.cpp +++ b/src/natpmp.cpp @@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/io.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/enum_net.hpp" +#include "libtorrent/socket_io.hpp" using boost::bind; using namespace libtorrent; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index e65b4bde2..ecc2492ec 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -526,8 +526,9 @@ namespace aux { #endif // abort the main thread m_abort = true; + error_code ec; #if TORRENT_USE_I2P - m_i2p_conn.close(); + m_i2p_conn.close(ec); #endif m_queued_for_checking.clear(); if (m_lsd) m_lsd->close(); @@ -537,7 +538,6 @@ namespace aux { if (m_dht) m_dht->stop(); m_dht_socket.close(); #endif - error_code ec; m_timer.cancel(ec); // close the listen sockets diff --git a/src/socket_io.cpp b/src/socket_io.cpp new file mode 100644 index 000000000..8643d5a1b --- /dev/null +++ b/src/socket_io.cpp @@ -0,0 +1,78 @@ +/* + +Copyright (c) 2009, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include + +#include "libtorrent/escape_string.hpp" +#include "libtorrent/error_code.hpp" +#include "libtorrent/socket.hpp" + +namespace libtorrent +{ + + std::string print_address(address const& addr) + { + error_code ec; + return addr.to_string(ec); + } + + std::string print_endpoint(tcp::endpoint const& ep) + { + error_code ec; + std::string ret; + address const& addr = ep.address(); +#if TORRENT_USE_IPV6 + if (addr.is_v6()) + { + ret += '['; + ret += addr.to_string(ec); + ret += ']'; + ret += ':'; + ret += to_string(ep.port()).elems; + } + else +#endif + { + ret += addr.to_string(ec); + ret += ':'; + ret += to_string(ep.port()).elems; + } + return ret; + } + + std::string print_endpoint(udp::endpoint const& ep) + { + return print_endpoint(tcp::endpoint(ep.address(), ep.port())); + } + +} + diff --git a/src/socks5_stream.cpp b/src/socks5_stream.cpp index b66b9c637..829301276 100644 --- a/src/socks5_stream.cpp +++ b/src/socks5_stream.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socks5_stream.hpp" #include "libtorrent/assert.hpp" +#include "libtorrent/socket_io.hpp" namespace libtorrent { diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index a61caf884..51d07d0ff 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -30,9 +30,12 @@ POSSIBILITY OF SUCH DAMAGE. */ +#include "libtorrent/config.hpp" +#include "libtorrent/socket.hpp" #include "libtorrent/udp_socket.hpp" #include "libtorrent/connection_queue.hpp" #include "libtorrent/escape_string.hpp" +#include "libtorrent/socket_io.hpp" #include #include #include diff --git a/src/upnp.cpp b/src/upnp.cpp index c7531a501..23aa2678e 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/pch.hpp" #include "libtorrent/socket.hpp" +#include "libtorrent/socket_io.hpp" #include "libtorrent/upnp.hpp" #include "libtorrent/io.hpp" #include "libtorrent/parse_url.hpp" diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 04414e8f5..3c0755741 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -48,6 +48,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/torrent.hpp" #include "libtorrent/extensions.hpp" #include "libtorrent/broadcast_socket.hpp" +#include "libtorrent/socket_io.hpp" #include "libtorrent/extensions/ut_pex.hpp" diff --git a/test/test_ip_filter.cpp b/test/test_ip_filter.cpp index bde665f3c..ce2792f24 100644 --- a/test/test_ip_filter.cpp +++ b/test/test_ip_filter.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "test.hpp" +#include "libtorrent/socket_io.hpp" /*