diff --git a/Jamfile b/Jamfile index 951a947d8..d3734f7b0 100755 --- a/Jamfile +++ b/Jamfile @@ -287,6 +287,7 @@ SOURCES = create_torrent disk_buffer_holder entry + error_code file_storage lazy_bdecode escape_string diff --git a/include/Makefile.am b/include/Makefile.am index 67bae4d44..28330963e 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -17,6 +17,7 @@ libtorrent/disk_io_thread.hpp \ libtorrent/entry.hpp \ libtorrent/enum_net.hpp \ libtorrent/escape_string.hpp \ +libtorrent/error_code.hpp \ libtorrent/extensions.hpp \ libtorrent/file.hpp \ libtorrent/file_pool.hpp \ diff --git a/include/libtorrent/error_code.hpp b/include/libtorrent/error_code.hpp index 6b3781fee..7b82a5b9d 100644 --- a/include/libtorrent/error_code.hpp +++ b/include/libtorrent/error_code.hpp @@ -43,10 +43,31 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { + + namespace errors + { + enum error_code_enum + { + no_error = 0, + file_collision + }; + } + #if BOOST_VERSION < 103500 typedef asio::error_code error_code; inline asio::error::error_category get_posix_category() { return asio::error::system_category; } #else + + struct libtorrent_error_category : boost::system::error_category + { + virtual const char* name() const; + virtual std::string message(int ev) const; + virtual boost::system::error_condition default_error_condition(int ev) const + { return boost::system::error_condition(ev, *this); } + }; + + extern libtorrent_error_category libtorrent_category; + using boost::system::error_code; inline boost::system::error_category const& get_posix_category() { return boost::system::get_posix_category(); } diff --git a/src/Makefile.am b/src/Makefile.am index 09253091e..d3358614c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,7 +24,7 @@ logger.cpp file_pool.cpp ut_pex.cpp lsd.cpp upnp.cpp instantiate_connection.cpp socks5_stream.cpp socks4_stream.cpp http_stream.cpp connection_queue.cpp \ disk_io_thread.cpp ut_metadata.cpp magnet_uri.cpp udp_socket.cpp smart_ban.cpp \ http_parser.cpp gzip.cpp disk_buffer_holder.cpp create_torrent.cpp GeoIP.c \ -parse_url.cpp file_storage.cpp $(kademlia_sources) +parse_url.cpp file_storage.cpp error_code.cpp $(kademlia_sources) # mapped_storage.cpp noinst_HEADERS = \ @@ -46,6 +46,7 @@ $(top_srcdir)/include/libtorrent/disk_io_thread.hpp \ $(top_srcdir)/include/libtorrent/entry.hpp \ $(top_srcdir)/include/libtorrent/enum_net.hpp \ $(top_srcdir)/include/libtorrent/escape_string.hpp \ +$(top_srcdir)/include/libtorrent/error_code.hpp \ $(top_srcdir)/include/libtorrent/extensions.hpp \ $(top_srcdir)/include/libtorrent/extensions/metadata_transfer.hpp \ $(top_srcdir)/include/libtorrent/extensions/logger.hpp \ diff --git a/src/file_pool.cpp b/src/file_pool.cpp index de914c70c..2d3ea88cd 100644 --- a/src/file_pool.cpp +++ b/src/file_pool.cpp @@ -42,36 +42,6 @@ namespace libtorrent using boost::multi_index::nth_index; using boost::multi_index::get; -#if BOOST_VERSION >= 103500 - struct file_pool_error_category : boost::system::error_category - { - virtual const char* name() const { return "file pool error"; } - virtual std::string message(int ev) const - { - static char const* msgs[] = - { "no error", "torrent file collides with file from another torrent" }; - if (ev < 0 || ev >= sizeof(msgs)/sizeof(msgs[0])) - return "Unknown error"; - return msgs[ev]; - } - virtual boost::system::error_condition default_error_condition(int ev) const - { - return boost::system::error_condition(ev, *this); - } - virtual bool equivalent(int code, boost::system::error_condition const& condition) const - { - return default_error_condition(code) == condition; - } - virtual bool equivalent(boost::system::error_code const& code, int condition ) const - { - return *this == code.category() && code.value() == condition; - } - }; - - file_pool_error_category file_pool_category; - -#endif - boost::shared_ptr file_pool::open_file(void* st, fs::path const& p , file::open_mode m, error_code& ec) { @@ -92,7 +62,7 @@ namespace libtorrent // this means that another instance of the storage // is using the exact same file. #if BOOST_VERSION >= 103500 - ec = error_code(1, file_pool_category); + ec = error_code(errors::file_collision, libtorrent_category); #endif return boost::shared_ptr(); }