diff --git a/include/libtorrent/error_code.hpp b/include/libtorrent/error_code.hpp index 25ecb681a..3d35f3fc0 100644 --- a/include/libtorrent/error_code.hpp +++ b/include/libtorrent/error_code.hpp @@ -468,24 +468,11 @@ namespace libtorrent bad_gateway = 502, service_unavailable = 503 }; - } -} -#if BOOST_VERSION >= 103500 + // hidden + TORRENT_EXPORT boost::system::error_code make_error_code(error_code_enum e); -namespace boost { namespace system { - - template<> struct is_error_code_enum - { static const bool value = true; }; - - template<> struct is_error_condition_enum - { static const bool value = true; }; -} } - -#endif - -namespace libtorrent -{ + } // namespace errors #if BOOST_VERSION < 103500 typedef asio::error_code error_code; @@ -519,15 +506,6 @@ namespace libtorrent // returns the error_category for HTTP errors TORRENT_EXPORT boost::system::error_category& get_http_category(); - namespace errors - { - // hidden - inline boost::system::error_code make_error_code(error_code_enum e) - { - return boost::system::error_code(e, get_libtorrent_category()); - } - } - using boost::system::error_code; // hidden @@ -619,5 +597,25 @@ namespace libtorrent } +#if BOOST_VERSION >= 103500 + +namespace boost { namespace system { + + template<> struct is_error_code_enum + { static const bool value = true; }; + + template<> struct is_error_condition_enum + { static const bool value = true; }; + + template<> struct is_error_code_enum + { static const bool value = true; }; + + template<> struct is_error_condition_enum + { static const bool value = true; }; +} } + +#endif // BOOST_VERSION + + #endif diff --git a/include/libtorrent/gzip.hpp b/include/libtorrent/gzip.hpp index 047018e38..75678f0cf 100644 --- a/include/libtorrent/gzip.hpp +++ b/include/libtorrent/gzip.hpp @@ -120,9 +120,11 @@ namespace boost { namespace system { template<> struct is_error_code_enum -{ - static const bool value = true; -}; +{ static const bool value = true; }; + +template<> +struct is_error_condition_enum +{ static const bool value = true; }; } } #endif // BOOST_VERSION diff --git a/include/libtorrent/i2p_stream.hpp b/include/libtorrent/i2p_stream.hpp index d554162cf..7b7a5b56c 100644 --- a/include/libtorrent/i2p_stream.hpp +++ b/include/libtorrent/i2p_stream.hpp @@ -220,9 +220,11 @@ namespace boost { namespace system { template<> struct is_error_code_enum -{ - static const bool value = true; -}; +{ static const bool value = true; }; + +template<> +struct is_error_condition_enum +{ static const bool value = true; }; } } #endif // BOOST_VERSION diff --git a/include/libtorrent/lazy_entry.hpp b/include/libtorrent/lazy_entry.hpp index 9818e6cd3..012fd55e8 100644 --- a/include/libtorrent/lazy_entry.hpp +++ b/include/libtorrent/lazy_entry.hpp @@ -438,6 +438,8 @@ namespace boost { namespace system { template<> struct is_error_code_enum { static const bool value = true; }; + template<> struct is_error_condition_enum + { static const bool value = true; }; } } #endif diff --git a/include/libtorrent/socks5_stream.hpp b/include/libtorrent/socks5_stream.hpp index 846c14f5d..2099f77eb 100644 --- a/include/libtorrent/socks5_stream.hpp +++ b/include/libtorrent/socks5_stream.hpp @@ -42,31 +42,32 @@ POSSIBILITY OF SUCH DAMAGE. #endif namespace libtorrent { +namespace socks_error { - namespace socks_error { + // SOCKS5 error values. If an error_code has the + // socks error category (get_socks_category()), these + // are the error values. + enum socks_error_code + { + no_error = 0, + unsupported_version, + unsupported_authentication_method, + unsupported_authentication_version, + authentication_error, + username_required, + general_failure, + command_not_supported, + no_identd, + identd_error, - // SOCKS5 error values. If an error_code has the - // socks error category (get_socks_category()), these - // are the error values. - enum socks_error_code - { - no_error = 0, - unsupported_version, - unsupported_authentication_method, - unsupported_authentication_version, - authentication_error, - username_required, - general_failure, - command_not_supported, - no_identd, - identd_error, + num_errors + }; - num_errors - }; - } + TORRENT_EXPORT boost::system::error_code make_error_code(socks_error_code e); +} // namespace socks_error - // returns the error_category for SOCKS5 errors - TORRENT_EXPORT boost::system::error_category& get_socks_category(); +// returns the error_category for SOCKS5 errors +TORRENT_EXPORT boost::system::error_category& get_socks_category(); class socks5_stream : public proxy_base { @@ -170,5 +171,18 @@ private: } +#if BOOST_VERSION >= 103500 + +namespace boost { namespace system { + + template<> struct is_error_code_enum + { static const bool value = true; }; + + template<> struct is_error_condition_enum + { static const bool value = true; }; +} } + +#endif // BOOST_VERSION + #endif diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index 9c48b0c1e..e1fcdcec5 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -93,6 +93,9 @@ namespace libtorrent // specific port external_port_must_be_wildcard = 727 }; + + // hidden + TORRENT_EXPORT boost::system::error_code make_error_code(error_code_enum e); } TORRENT_EXPORT boost::system::error_category& get_upnp_category(); @@ -380,6 +383,18 @@ private: } +#if BOOST_VERSION >= 103500 + +namespace boost { namespace system { + + template<> struct is_error_code_enum + { static const bool value = true; }; + + template<> struct is_error_condition_enum + { static const bool value = true; }; +} } + +#endif // BOOST_VERSION #endif diff --git a/src/error_code.cpp b/src/error_code.cpp index 6db477745..97f2f6fb3 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -342,5 +342,14 @@ namespace libtorrent } #endif + namespace errors + { + // hidden + boost::system::error_code make_error_code(error_code_enum e) + { + return boost::system::error_code(e, get_libtorrent_category()); + } + } + } diff --git a/src/socks5_stream.cpp b/src/socks5_stream.cpp index 3826ef0e6..230d33e5c 100644 --- a/src/socks5_stream.cpp +++ b/src/socks5_stream.cpp @@ -37,6 +37,14 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { + namespace socks_error + { + boost::system::error_code make_error_code(socks_error_code e) + { + return error_code(e, get_socks_category()); + } + } + struct socks_error_category : boost::system::error_category { virtual const char* name() const BOOST_SYSTEM_NOEXCEPT @@ -132,7 +140,7 @@ namespace libtorrent } else { - (*h)(error_code(socks_error::unsupported_version, get_socks_category())); + (*h)(socks_error::unsupported_version); error_code ec; close(ec); } @@ -168,7 +176,7 @@ namespace libtorrent if (version < m_version) { - (*h)(error_code(socks_error::unsupported_version, get_socks_category())); + (*h)(socks_error::unsupported_version); error_code ec; close(ec); return; @@ -182,7 +190,7 @@ namespace libtorrent { if (m_user.empty()) { - (*h)(error_code(socks_error::username_required, get_socks_category())); + (*h)(socks_error::username_required); error_code ec; close(ec); return; @@ -205,7 +213,7 @@ namespace libtorrent } else { - (*h)(error_code(socks_error::unsupported_authentication_method, get_socks_category())); + (*h)(socks_error::unsupported_authentication_method); error_code ec; close(ec); return; @@ -244,7 +252,7 @@ namespace libtorrent if (version != 1) { - (*h)(error_code(socks_error::unsupported_authentication_version, get_socks_category())); + (*h)(socks_error::unsupported_authentication_version); error_code ec; close(ec); return; @@ -252,7 +260,7 @@ namespace libtorrent if (status != 0) { - (*h)(error_code(socks_error::authentication_error, get_socks_category())); + (*h)(socks_error::authentication_error); error_code ec; close(ec); return; @@ -296,7 +304,7 @@ namespace libtorrent // SOCKS4 only supports IPv4 if (!m_remote_endpoint.address().is_v4()) { - (*h)(error_code(boost::asio::error::address_family_not_supported)); + (*h)(boost::asio::error::address_family_not_supported); error_code ec; close(ec); return; @@ -313,7 +321,7 @@ namespace libtorrent } else { - (*h)(error_code(socks_error::unsupported_version, get_socks_category())); + (*h)(socks_error::unsupported_version); error_code ec; close(ec); return; @@ -363,7 +371,7 @@ namespace libtorrent { if (version < m_version) { - (*h)(error_code(socks_error::unsupported_version, get_socks_category())); + (*h)(socks_error::unsupported_version); error_code ec; close(ec); return; @@ -378,7 +386,7 @@ namespace libtorrent case 4: ec = asio::error::host_unreachable; break; case 5: ec = asio::error::connection_refused; break; case 6: ec = asio::error::timed_out; break; - case 7: ec = error_code(socks_error::command_not_supported, get_socks_category()); break; + case 7: ec = socks_error::command_not_supported; break; case 8: ec = asio::error::address_family_not_supported; break; } (*h)(ec); @@ -442,7 +450,7 @@ namespace libtorrent { if (version != 0) { - (*h)(error_code(socks_error::general_failure, get_socks_category())); + (*h)(socks_error::general_failure); error_code ec; close(ec); return; diff --git a/src/upnp.cpp b/src/upnp.cpp index 30f8842c2..aca062fd2 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -58,6 +58,15 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { +namespace upnp_errors +{ + boost::system::error_code make_error_code(error_code_enum e) + { + return error_code(e, get_upnp_category()); + } + +} // upnp_errors namespace + static error_code ec; // TODO: listen_interface is not used. It's meant to bind the broadcast socket