From e750910798bf3eb7d6b6157dfcf55654cc50f113 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 27 Nov 2009 07:08:47 +0000 Subject: [PATCH] fixed windows build --- include/libtorrent/address.hpp | 5 +++++ include/libtorrent/error.hpp | 2 +- include/libtorrent/io_service.hpp | 5 +++++ include/libtorrent/lazy_entry.hpp | 19 +++++++++++-------- include/libtorrent/socket.hpp | 5 +++++ include/libtorrent/thread.hpp | 6 ++++++ src/alert.cpp | 1 + src/broadcast_socket.cpp | 14 +++++++------- src/lazy_bdecode.cpp | 28 ++++++++++++++++++---------- src/natpmp.cpp | 12 ++++++------ 10 files changed, 65 insertions(+), 32 deletions(-) diff --git a/include/libtorrent/address.hpp b/include/libtorrent/address.hpp index eea74d59d..de410eff6 100644 --- a/include/libtorrent/address.hpp +++ b/include/libtorrent/address.hpp @@ -39,6 +39,11 @@ POSSIBILITY OF SUCH DAMAGE. #define Protocol Protocol_ #endif +#if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN +// asio assumes that the windows error codes are defined already +#include +#endif + #if BOOST_VERSION < 103500 #include #else diff --git a/include/libtorrent/error.hpp b/include/libtorrent/error.hpp index 754966be3..1ee4b27fd 100644 --- a/include/libtorrent/error.hpp +++ b/include/libtorrent/error.hpp @@ -53,7 +53,7 @@ namespace libtorrent #if BOOST_VERSION < 103500 namespace error = asio::error; #else - namespace error = boost::asio::error; + namespace error = boost::asio::error; #endif } diff --git a/include/libtorrent/io_service.hpp b/include/libtorrent/io_service.hpp index f9c22a1a9..5867cf54f 100644 --- a/include/libtorrent/io_service.hpp +++ b/include/libtorrent/io_service.hpp @@ -43,6 +43,11 @@ POSSIBILITY OF SUCH DAMAGE. #include +#if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN +// asio assumes that the windows error codes are defined already +#include +#endif + #if BOOST_VERSION < 103500 #include #else diff --git a/include/libtorrent/lazy_entry.hpp b/include/libtorrent/lazy_entry.hpp index 4afc425a0..4569ac62a 100644 --- a/include/libtorrent/lazy_entry.hpp +++ b/include/libtorrent/lazy_entry.hpp @@ -65,6 +65,8 @@ namespace libtorrent } }; + struct lazy_dict_entry; + struct TORRENT_EXPORT lazy_entry { enum entry_type_t @@ -151,13 +153,7 @@ namespace libtorrent lazy_entry const* dict_find_list(char const* name) const; lazy_entry const* dict_find_string(char const* name) const; - std::pair dict_at(int i) const - { - TORRENT_ASSERT(m_type == dict_t); - TORRENT_ASSERT(i < m_size); - std::pair const& e = m_data.dict[i]; - return std::make_pair(std::string(e.first, e.second.m_begin - e.first), &e.second); - } + std::pair dict_at(int i) const; int dict_size() const { @@ -238,10 +234,11 @@ namespace libtorrent entry_type_t m_type; union data_t { - std::pair* dict; + lazy_dict_entry* dict; lazy_entry* list; char const* start; } m_data; + int m_size; // if list or dictionary, the number of items int m_capacity; // if list or dictionary, allocated number of items // used for dictionaries and lists to record the range @@ -254,6 +251,12 @@ namespace libtorrent lazy_entry const& operator=(lazy_entry const&); }; + struct lazy_dict_entry + { + char const* name; + lazy_entry val; + }; + TORRENT_EXPORT std::string print_entry(lazy_entry const& e, bool single_line = false); #if TORRENT_USE_IOSTREAM TORRENT_EXPORT std::ostream& operator<<(std::ostream& os, lazy_entry const& e); diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index b6abf843d..598106af6 100644 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -45,6 +45,11 @@ POSSIBILITY OF SUCH DAMAGE. #define Protocol Protocol_ #endif +#if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN +// asio assumes that the windows error codes are defined already +#include +#endif + #include #if BOOST_VERSION < 103500 diff --git a/include/libtorrent/thread.hpp b/include/libtorrent/thread.hpp index 4a42de5f6..33e349622 100644 --- a/include/libtorrent/thread.hpp +++ b/include/libtorrent/thread.hpp @@ -34,6 +34,12 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_THREAD_HPP_INCLUDED #include "libtorrent/config.hpp" + +#if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN +// asio assumes that the windows error codes are defined already +#include +#endif + #include #include #include diff --git a/src/alert.cpp b/src/alert.cpp index 22c9067c1..d7dad2421 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/io_service.hpp" #include "libtorrent/socket_io.hpp" #include "libtorrent/time.hpp" +#include "libtorrent/error_code.hpp" #include namespace libtorrent { diff --git a/src/broadcast_socket.cpp b/src/broadcast_socket.cpp index 3bce983ef..32d239dca 100644 --- a/src/broadcast_socket.cpp +++ b/src/broadcast_socket.cpp @@ -32,6 +32,13 @@ POSSIBILITY OF SUCH DAMAGE. #include +#include + +#include "libtorrent/socket.hpp" +#include "libtorrent/enum_net.hpp" +#include "libtorrent/broadcast_socket.hpp" +#include "libtorrent/assert.hpp" + #if BOOST_VERSION < 103500 #include #include @@ -40,13 +47,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#include - -#include "libtorrent/socket.hpp" -#include "libtorrent/enum_net.hpp" -#include "libtorrent/broadcast_socket.hpp" -#include "libtorrent/assert.hpp" - namespace libtorrent { bool is_local(address const& a) diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index c8aae871d..c6585ab54 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -191,26 +191,26 @@ namespace libtorrent if (m_capacity == 0) { int capacity = lazy_entry_dict_init; - m_data.dict = new (std::nothrow) std::pair[capacity]; + m_data.dict = new (std::nothrow) lazy_dict_entry[capacity]; if (m_data.dict == 0) return 0; m_capacity = capacity; } else if (m_size == m_capacity) { int capacity = m_capacity * lazy_entry_grow_factor; - std::pair* tmp = new (std::nothrow) std::pair[capacity]; + lazy_dict_entry* tmp = new (std::nothrow) lazy_dict_entry[capacity]; if (tmp == 0) return 0; - std::memcpy(tmp, m_data.dict, sizeof(std::pair) * m_size); - for (int i = 0; i < m_size; ++i) m_data.dict[i].second.release(); + std::memcpy(tmp, m_data.dict, sizeof(lazy_dict_entry) * m_size); + for (int i = 0; i < m_size; ++i) m_data.dict[i].val.release(); delete[] m_data.dict; m_data.dict = tmp; m_capacity = capacity; } TORRENT_ASSERT(m_size < m_capacity); - std::pair& ret = m_data.dict[m_size++]; - ret.first = name; - return &ret.second; + lazy_dict_entry& ret = m_data.dict[m_size++]; + ret.name = name; + return &ret.val; } namespace @@ -257,6 +257,14 @@ namespace libtorrent } } + std::pair lazy_entry::dict_at(int i) const + { + TORRENT_ASSERT(m_type == dict_t); + TORRENT_ASSERT(i < m_size); + lazy_dict_entry const& e = m_data.dict[i]; + return std::make_pair(std::string(e.name, e.val.m_begin - e.name), &e.val); + } + std::string lazy_entry::dict_find_string_value(char const* name) const { lazy_entry const* e = dict_find(name); @@ -304,9 +312,9 @@ namespace libtorrent TORRENT_ASSERT(m_type == dict_t); for (int i = 0; i < m_size; ++i) { - std::pair const& e = m_data.dict[i]; - if (string_equal(name, e.first, e.second.m_begin - e.first)) - return &m_data.dict[i].second; + lazy_dict_entry& e = m_data.dict[i]; + if (string_equal(name, e.name, e.val.m_begin - e.name)) + return &e.val; } return 0; } diff --git a/src/natpmp.cpp b/src/natpmp.cpp index 821ca038f..dad3165e0 100644 --- a/src/natpmp.cpp +++ b/src/natpmp.cpp @@ -35,12 +35,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#if BOOST_VERSION < 103500 -#include -#else -#include -#endif - #include "libtorrent/natpmp.hpp" #include "libtorrent/io.hpp" #include "libtorrent/assert.hpp" @@ -48,6 +42,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket_io.hpp" #include "libtorrent/io_service.hpp" +#if BOOST_VERSION < 103500 +#include +#else +#include +#endif + using boost::bind; using namespace libtorrent;