fixed up link test to make sure library and client are using the same configuration, also factored out common code from session constructor
This commit is contained in:
parent
9a461c5e46
commit
84d81d3a82
|
@ -21,6 +21,7 @@ nobase_include_HEADERS = \
|
|||
broadcast_socket.hpp \
|
||||
bt_peer_connection.hpp \
|
||||
buffer.hpp \
|
||||
build_config.hpp \
|
||||
chained_buffer.hpp \
|
||||
config.hpp \
|
||||
connection_queue.hpp \
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
|
||||
Copyright (c) 2010, 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_BUILD_CONFIG_HPP_INCLUDED
|
||||
#define TORRENT_BUILD_CONFIG_HPP_INCLUDED
|
||||
|
||||
#include "libtorrent/config.hpp"
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
|
||||
#ifdef TORRENT_DEBUG
|
||||
#define TORRENT_CFG_DEBUG dbg-
|
||||
#else
|
||||
#define TORRENT_CFG_DEBUG
|
||||
#endif
|
||||
|
||||
#if TORRENT_USE_BOOST_DATE_TIME
|
||||
#define TORRENT_CFG_TIME boosttime-
|
||||
#elif TORRENT_USE_ABSOLUTE_TIME
|
||||
#define TORRENT_CFG_TIME absolutetime-
|
||||
#elif TORRENT_USE_PERFORMANCE_TIMER
|
||||
#define TORRENT_CFG_TIME performancetimer-
|
||||
#elif TORRENT_USE_CLOCK_GETTIME
|
||||
#define TORRENT_CFG_TIME clocktime-
|
||||
#elif TORRENT_USE_SYSTEM_TIME
|
||||
#define TORRENT_CFG_TIME systime-
|
||||
#else
|
||||
#error what timer is used?
|
||||
#endif
|
||||
|
||||
#if TORRENT_USE_IPV6
|
||||
#define TORRENT_CFG_IPV6 ipv6-
|
||||
#else
|
||||
#define TORRENT_CFG_IPV6 noipv6-
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_DISABLE_DHT
|
||||
#define TORRENT_CFG_DHT nodht-
|
||||
#else
|
||||
#define TORRENT_CFG_DHT dht-
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_DISABLE_POOL_ALLOCATORS
|
||||
#define TORRENT_CFG_POOL nopools-
|
||||
#else
|
||||
#define TORRENT_CFG_POOL pools-
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
#define TORRENT_CFG_LOG verboselog-
|
||||
#elif defined TORRENT_LOGGING
|
||||
#define TORRENT_CFG_LOG log-
|
||||
#else
|
||||
#define TORRENT_CFG_LOG nolog-
|
||||
#endif
|
||||
|
||||
#ifdef _UNICODE
|
||||
#define TORRENT_CFG_UNICODE unicode-
|
||||
#else
|
||||
#define TORRENT_CFG_UNICODE ansi-
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_DISABLE_RESOLVE_COUNTRIES
|
||||
#define TORRENT_CFG_RESOLVE noresolvecountries-
|
||||
#else
|
||||
#define TORRENT_CFG_RESOLVE resolvecountries-
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_NO_DEPRECATE
|
||||
#define TORRENT_CFG_DEPR nodeprecate-
|
||||
#else
|
||||
#define TORRENT_CFG_DEPR deprecated-
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_DISABLE_FULL_STATS
|
||||
#define TORRENT_CFG_STATS partialstats-
|
||||
#else
|
||||
#define TORRENT_CFG_STATS fullstats-
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_DISABLE_EXTENSIONS
|
||||
#define TORRENT_CFG_EXT noext-
|
||||
#else
|
||||
#define TORRENT_CFG_EXT ext-
|
||||
#endif
|
||||
|
||||
#define TORRENT_CFG_STRING \
|
||||
#TORRENT_CFG_DEBUG \
|
||||
#TORRENT_CFG_TIME \
|
||||
#TORRENT_CFG_POOL \
|
||||
#TORRENT_CFG_LOG \
|
||||
#TORRENT_CFG_RESOLVE \
|
||||
#TORRENT_CFG_DEPR \
|
||||
#TORRENT_CFG_DHT \
|
||||
#TORRENT_CFG_EXT
|
||||
|
||||
#define TORRENT_CFG \
|
||||
BOOST_PP_CAT(TORRENT_CFG_DEBUG, \
|
||||
BOOST_PP_CAT(TORRENT_CFG_TIME, \
|
||||
BOOST_PP_CAT(TORRENT_CFG_POOL, \
|
||||
BOOST_PP_CAT(TORRENT_CFG_LOG, \
|
||||
BOOST_PP_CAT(TORRENT_CFG_RESOLVE, \
|
||||
BOOST_PP_CAT(TORRENT_CFG_DEPR, \
|
||||
BOOST_PP_CAT(TORRENT_CFG_DHT, \
|
||||
TORRENT_CFG_EXT)))))))
|
||||
|
||||
#endif
|
||||
|
|
@ -58,8 +58,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/add_torrent_params.hpp"
|
||||
|
||||
#include "libtorrent/storage.hpp"
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include <eh.h>
|
||||
|
@ -76,48 +74,11 @@ namespace libtorrent
|
|||
class upnp;
|
||||
class alert;
|
||||
|
||||
// this is used to create linker errors when trying to link to
|
||||
// a library with a conflicting build configuration than the application
|
||||
#ifdef TORRENT_DEBUG
|
||||
#define G _release
|
||||
#else
|
||||
#define G _debug
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_USE_OPENSSL
|
||||
#define S _ssl
|
||||
#else
|
||||
#define S _nossl
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_DISABLE_DHT
|
||||
#define D _nodht
|
||||
#else
|
||||
#define D _dht
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
#define P _nopoolalloc
|
||||
#else
|
||||
#define P _poolalloc
|
||||
#endif
|
||||
|
||||
#define TORRENT_LINK_TEST_PREFIX libtorrent_build_config
|
||||
#define TORRENT_LINK_TEST_NAME BOOST_PP_CAT(TORRENT_LINK_TEST_PREFIX, BOOST_PP_CAT(P, BOOST_PP_CAT(D, BOOST_PP_CAT(S, G))))
|
||||
#undef P
|
||||
#undef D
|
||||
#undef S
|
||||
#undef G
|
||||
|
||||
inline void test_link()
|
||||
{
|
||||
extern void TORRENT_LINK_TEST_NAME();
|
||||
TORRENT_LINK_TEST_NAME();
|
||||
}
|
||||
|
||||
session_settings min_memory_usage();
|
||||
session_settings high_performance_seed();
|
||||
|
||||
void TORRENT_EXPORT TORRENT_CFG();
|
||||
|
||||
namespace aux
|
||||
{
|
||||
// workaround for microsofts
|
||||
|
@ -151,6 +112,16 @@ namespace libtorrent
|
|||
boost::shared_ptr<aux::session_impl> m_impl;
|
||||
};
|
||||
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
#define TORRENT_LOGPATH_ARG_DEFAULT , std::string logpath = "."
|
||||
#define TORRENT_LOGPATH_ARG , std::string logpath
|
||||
#define TORRENT_LOGPATH , logpath
|
||||
#else
|
||||
#define TORRENT_LOGPATH_ARG_DEFAULT
|
||||
#define TORRENT_LOGPATH_ARG
|
||||
#define TORRENT_LOGPATH
|
||||
#endif
|
||||
|
||||
class TORRENT_EXPORT session: public boost::noncopyable, aux::eh_initializer
|
||||
{
|
||||
public:
|
||||
|
@ -159,20 +130,25 @@ namespace libtorrent
|
|||
, LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0)
|
||||
, int flags = start_default_features | add_default_plugins
|
||||
, int alert_mask = alert::error_notification
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
, std::string logpath = "."
|
||||
#endif
|
||||
);
|
||||
TORRENT_LOGPATH_ARG_DEFAULT)
|
||||
{
|
||||
TORRENT_CFG();
|
||||
init(std::make_pair(0, 0), "0.0.0.0", print, flags, alert_mask TORRENT_LOGPATH);
|
||||
}
|
||||
|
||||
session(
|
||||
fingerprint const& print
|
||||
, std::pair<int, int> listen_port_range
|
||||
, char const* listen_interface = "0.0.0.0"
|
||||
, int flags = start_default_features | add_default_plugins
|
||||
, int alert_mask = alert::error_notification
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
, std::string logpath = "."
|
||||
#endif
|
||||
);
|
||||
TORRENT_LOGPATH_ARG_DEFAULT)
|
||||
{
|
||||
TORRENT_CFG();
|
||||
TORRENT_ASSERT(listen_port_range.first > 0);
|
||||
TORRENT_ASSERT(listen_port_range.first < listen_port_range.second);
|
||||
init(listen_port_range, listen_interface, print, flags, alert_mask TORRENT_LOGPATH);
|
||||
}
|
||||
|
||||
~session();
|
||||
|
||||
|
@ -451,6 +427,9 @@ namespace libtorrent
|
|||
|
||||
private:
|
||||
|
||||
void init(std::pair<int, int> listen_range, char const* listen_interface
|
||||
, fingerprint const& id, int flags, int alert_mask TORRENT_LOGPATH_ARG);
|
||||
|
||||
// data shared between the main thread
|
||||
// and the working thread
|
||||
boost::shared_ptr<aux::session_impl> m_impl;
|
||||
|
|
|
@ -303,61 +303,17 @@ namespace libtorrent
|
|||
m_impl->m_io_service.post(boost::bind(&fun_ret<type>, &r, &done, &m_impl->cond, &m_impl->mut, boost::function<type(void)>(boost::bind(&session_impl:: x, m_impl.get(), a1, a2, a3)))); \
|
||||
do { m_impl->cond.wait(l); } while(!done)
|
||||
|
||||
session::session(
|
||||
fingerprint const& id
|
||||
, std::pair<int, int> listen_port_range
|
||||
, char const* listen_interface
|
||||
, int flags
|
||||
, int alert_mask
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
, std::string logpath
|
||||
#endif
|
||||
)
|
||||
: m_impl(new session_impl(listen_port_range, id, listen_interface
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
, logpath
|
||||
#endif
|
||||
))
|
||||
{
|
||||
#ifdef TORRENT_MEMDEBUG
|
||||
start_malloc_debug();
|
||||
#endif
|
||||
TORRENT_ASSERT(listen_port_range.first > 0);
|
||||
TORRENT_ASSERT(listen_port_range.first < listen_port_range.second);
|
||||
set_alert_mask(alert_mask);
|
||||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||
if (flags & add_default_plugins)
|
||||
{
|
||||
add_extension(create_ut_pex_plugin);
|
||||
add_extension(create_ut_metadata_plugin);
|
||||
add_extension(create_lt_trackers_plugin);
|
||||
add_extension(create_smart_ban_plugin);
|
||||
}
|
||||
#endif
|
||||
if (flags & start_default_features)
|
||||
{
|
||||
start_upnp();
|
||||
start_natpmp();
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
start_dht();
|
||||
#endif
|
||||
start_lsd();
|
||||
}
|
||||
}
|
||||
// this is a dummy function that's exported and named based
|
||||
// on the configuration. The session.hpp file will reference
|
||||
// it and if the library and the client are built with different
|
||||
// configurations this will give a link error
|
||||
void TORRENT_EXPORT TORRENT_CFG() {}
|
||||
|
||||
session::session(fingerprint const& id
|
||||
, int flags
|
||||
, int alert_mask
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
, std::string logpath
|
||||
#endif
|
||||
)
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
: m_impl(new session_impl(std::make_pair(0, 0), id, "0.0.0.0", logpath))
|
||||
#else
|
||||
: m_impl(new session_impl(std::make_pair(0, 0), id, "0.0.0.0"))
|
||||
#endif
|
||||
void session::init(std::pair<int, int> listen_range, char const* listen_interface
|
||||
, fingerprint const& id, int flags, int alert_mask TORRENT_LOGPATH_ARG)
|
||||
{
|
||||
m_impl.reset(new session_impl(listen_range, id, listen_interface) TORRENT_LOGPATH);
|
||||
|
||||
#ifdef TORRENT_MEMDEBUG
|
||||
start_malloc_debug();
|
||||
#endif
|
||||
|
|
|
@ -76,6 +76,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/instantiate_connection.hpp"
|
||||
#include "libtorrent/peer_info.hpp"
|
||||
#include "libtorrent/settings.hpp"
|
||||
#include "libtorrent/build_config.hpp"
|
||||
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
#endif
|
||||
|
@ -593,6 +594,12 @@ namespace aux {
|
|||
#endif
|
||||
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
|
||||
(*m_logger) << "libtorrent configuration: " << TORRENT_CFG_STRING << "\n"
|
||||
<< "libtorrent version: " << LIBTORRENT_VERSION << "\n"
|
||||
<< "libtorrent revision: " << LIBTORRENT_REVISION << "\n\n";
|
||||
|
||||
|
||||
#define PRINT_SIZEOF(x) (*m_logger) << "sizeof(" #x "): " << sizeof(x) << "\n";
|
||||
#define PRINT_OFFSETOF(x, y) (*m_logger) << " offsetof(" #x "," #y "): " << offsetof(x, y) << "\n";
|
||||
|
||||
|
|
Loading…
Reference in New Issue