From 3ff4431a40038ba0f6e129aecdb0133ffecf8fd0 Mon Sep 17 00:00:00 2001 From: Ted Lyngmo Date: Fri, 9 Oct 2020 13:51:40 +0200 Subject: [PATCH] C++11 overhaul - Fixes #7, fixes #9 This is meant as a co-op patch to make the library use and require C++11 or later. This is not a backwards compatible patch since it'll fail to build in C++ versions prior to C++11. * TODO: Figure out how to make boost use std::iterator instead of its own iterator to get rid of the `BOOST_HEADER_DEPRECATED("")` warning Signed-off-by: Ted Lyngmo --- CMakeLists.txt | 4 +++ doc/libiqxmlrpc.doxygen.in | 6 ----- libiqxmlrpc/api_export.h | 4 +-- libiqxmlrpc/client.cc | 12 ++++++--- libiqxmlrpc/client.h | 11 +++++--- libiqxmlrpc/client_conn.cc | 6 +++-- libiqxmlrpc/connector.cc | 2 +- libiqxmlrpc/dispatcher_manager.h | 8 +++--- libiqxmlrpc/executor.cc | 11 ++++---- libiqxmlrpc/executor.h | 15 ++++++----- libiqxmlrpc/http.cc | 4 +-- libiqxmlrpc/http.h | 4 +-- libiqxmlrpc/http_client.h | 4 ++- libiqxmlrpc/https_client.cc | 4 ++- libiqxmlrpc/https_client.h | 8 +++--- libiqxmlrpc/inet_addr.cc | 2 +- libiqxmlrpc/inet_addr.h | 4 +-- libiqxmlrpc/method.h | 12 ++++++--- libiqxmlrpc/net_except.cc | 4 +-- libiqxmlrpc/parser2.h | 4 +-- libiqxmlrpc/reactor_impl.h | 35 +++++++++++++++--------- libiqxmlrpc/reactor_interrupter.cc | 14 ++++++---- libiqxmlrpc/reactor_interrupter.h | 8 +++--- libiqxmlrpc/reactor_poll_impl.h | 8 +++--- libiqxmlrpc/reactor_select_impl.h | 8 +++--- libiqxmlrpc/response.h | 4 +-- libiqxmlrpc/server.cc | 34 +++++++++++------------ libiqxmlrpc/server.h | 7 ++++- libiqxmlrpc/server_conn.cc | 4 ++- libiqxmlrpc/socket.cc | 16 +++++------ libiqxmlrpc/ssl_lib.cc | 19 +++++++------ libiqxmlrpc/ssl_lib.h | 4 +-- libiqxmlrpc/sysinc.h | 4 +-- libiqxmlrpc/util.h | 7 ++++- libiqxmlrpc/value_parser.cc | 6 +++-- libiqxmlrpc/value_parser.h | 4 ++- libiqxmlrpc/xml_builder.h | 10 ++++--- tests/client.cc | 8 +++--- tests/client_stress.cc | 16 ++++++----- tests/parser2.cc | 14 +++++----- tests/test_server.cc | 26 +++++++++++------- tests/test_server_stop.cc | 43 +++++++++++++++++++----------- tests/test_value_usage.cc | 12 +++++---- 43 files changed, 266 insertions(+), 174 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4db19ca8..d856a42f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 2.8) project(Libiqxmlrpc) set(Libiqxmlrpc_VERSION 0.13.6) +set(CMAKE_CXX_STANDARD 11) +set(CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + add_subdirectory(libiqxmlrpc) option(build_tests "Build tests?" OFF) diff --git a/doc/libiqxmlrpc.doxygen.in b/doc/libiqxmlrpc.doxygen.in index 8a389da9..754bba97 100644 --- a/doc/libiqxmlrpc.doxygen.in +++ b/doc/libiqxmlrpc.doxygen.in @@ -472,12 +472,6 @@ HTML_FOOTER = HTML_STYLESHEET = -# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, -# files or namespaces will be aligned in HTML using tables. If set to -# NO a bullet list will be used. - -HTML_ALIGN_MEMBERS = NO - # If the GENERATE_HTMLHELP tag is set to YES, additional index files # will be generated that can be used as input for tools like the # Microsoft HTML help workshop to generate a compressed HTML help file (.chm) diff --git a/libiqxmlrpc/api_export.h b/libiqxmlrpc/api_export.h index e202115e..3d3df648 100644 --- a/libiqxmlrpc/api_export.h +++ b/libiqxmlrpc/api_export.h @@ -6,9 +6,9 @@ #include "sysinc.h" -#if defined(WIN32) || defined(__MINGW32__) +#if defined(_WIN32) || defined(__MINGW32__) #define LIBIQXMLRPC_DLL -#endif // WIN32 || __MINGW32__ +#endif // _WIN32 || __MINGW32__ #ifdef LIBIQXMLRPC_DLL #if defined(LIBIQXMLRPC_COMPILATION) && defined(DLL_EXPORT) diff --git a/libiqxmlrpc/client.cc b/libiqxmlrpc/client.cc index a2ffe2bf..98c9eb59 100644 --- a/libiqxmlrpc/client.cc +++ b/libiqxmlrpc/client.cc @@ -5,6 +5,8 @@ #include "client_conn.h" #include "client_opts.h" +#include + namespace iqxmlrpc { // @@ -21,14 +23,14 @@ class Client_base::Impl { opts(addr, uri, vhost) {} Client_options opts; - boost::scoped_ptr conn_cache; + std::unique_ptr conn_cache; }; // // Auto_conn // -class Auto_conn: boost::noncopyable { +class Auto_conn { public: Auto_conn( Client_base::Impl& client_impl, Client_base& client ): client_impl_(client_impl) @@ -45,6 +47,10 @@ class Auto_conn: boost::noncopyable { conn_ptr_ = tmp_conn_.get(); } } + Auto_conn(const Auto_conn&) = delete; + Auto_conn(Auto_conn&&) = delete; + Auto_conn& operator=(const Auto_conn&) = delete; + Auto_conn& operator=(Auto_conn&&) = delete; ~Auto_conn() { @@ -74,7 +80,7 @@ class Auto_conn: boost::noncopyable { } Client_base::Impl& client_impl_; - boost::scoped_ptr tmp_conn_; + std::unique_ptr tmp_conn_; Client_connection* conn_ptr_; }; diff --git a/libiqxmlrpc/client.h b/libiqxmlrpc/client.h index 104b6c5a..7e110486 100644 --- a/libiqxmlrpc/client.h +++ b/libiqxmlrpc/client.h @@ -9,7 +9,8 @@ #include "response.h" #include -#include + +#include namespace iqxmlrpc { @@ -22,13 +23,17 @@ class Client_connection; //! Client base class. //! It is responsible for performing RPC calls and connection management. -class LIBIQXMLRPC_API Client_base: boost::noncopyable { +class LIBIQXMLRPC_API Client_base { public: Client_base( const iqnet::Inet_addr& addr, const std::string& uri, const std::string& vhost ); + Client_base(const Client_base&) = delete; + Client_base(Client_base&&) = delete; + Client_base& operator=(const Client_base&) = delete; + Client_base& operator=(Client_base&&) = delete; virtual ~Client_base(); @@ -69,7 +74,7 @@ class LIBIQXMLRPC_API Client_base: boost::noncopyable { friend class Auto_conn; class Impl; - boost::scoped_ptr impl_; + std::unique_ptr impl_; }; #ifdef _MSC_VER diff --git a/libiqxmlrpc/client_conn.cc b/libiqxmlrpc/client_conn.cc index e3b93eda..5ff4a9db 100644 --- a/libiqxmlrpc/client_conn.cc +++ b/libiqxmlrpc/client_conn.cc @@ -5,6 +5,8 @@ #include "client_opts.h" #include "http.h" +#include + namespace iqxmlrpc { Client_connection::Client_connection(): @@ -22,7 +24,7 @@ Response Client_connection::process_session( const Request& req, const XHeaders& std::string req_xml_str( dump_request(req) ); - std::auto_ptr req_h( + std::unique_ptr req_h( new Request_header( decorate_uri(), opts().vhost(), @@ -38,7 +40,7 @@ Response Client_connection::process_session( const Request& req, const XHeaders& req_p.set_keep_alive( opts().keep_alive() ); // Received packet - std::auto_ptr res_p( do_process_session(req_p.dump()) ); + std::unique_ptr res_p( do_process_session(req_p.dump()) ); const Response_header* res_h = static_cast(res_p->header()); diff --git a/libiqxmlrpc/connector.cc b/libiqxmlrpc/connector.cc index 83d66268..f1de4138 100644 --- a/libiqxmlrpc/connector.cc +++ b/libiqxmlrpc/connector.cc @@ -6,7 +6,7 @@ namespace iqnet { -#if defined(WIN32) +#if defined(_WIN32) #define IQXMLRPC_INPROGRESS WSAEWOULDBLOCK #else #define IQXMLRPC_INPROGRESS EINPROGRESS diff --git a/libiqxmlrpc/dispatcher_manager.h b/libiqxmlrpc/dispatcher_manager.h index 6d9fb9ad..7e3c59c1 100644 --- a/libiqxmlrpc/dispatcher_manager.h +++ b/libiqxmlrpc/dispatcher_manager.h @@ -6,8 +6,6 @@ #include "method.h" -#include - namespace iqxmlrpc { #ifdef _MSC_VER @@ -20,12 +18,16 @@ namespace iqxmlrpc { * register_method operation and optionally system one, which holds * server's built-in methods */ -class LIBIQXMLRPC_API Method_dispatcher_manager: boost::noncopyable { +class LIBIQXMLRPC_API Method_dispatcher_manager { class Impl; Impl* impl_; public: Method_dispatcher_manager(); + Method_dispatcher_manager(const Method_dispatcher_manager&) = delete; + Method_dispatcher_manager(Method_dispatcher_manager&&) = delete; + Method_dispatcher_manager& operator=(const Method_dispatcher_manager&) = delete; + Method_dispatcher_manager& operator=(Method_dispatcher_manager&&) = delete; ~Method_dispatcher_manager(); //! Registers method factory in default method dispatcher. diff --git a/libiqxmlrpc/executor.cc b/libiqxmlrpc/executor.cc index 8a218b1c..9c43a825 100644 --- a/libiqxmlrpc/executor.cc +++ b/libiqxmlrpc/executor.cc @@ -11,7 +11,8 @@ #include using namespace iqxmlrpc; -typedef boost::mutex::scoped_lock scoped_lock; +typedef std::lock_guard scoped_lock; +typedef std::unique_lock unique_lock; Executor::Executor( Method* m, Server* s, Server_connection* cb ): method(m), @@ -43,7 +44,7 @@ void Executor::interrupt_server() void Serial_executor::execute( const Param_list& params ) { try { - std::auto_ptr result(new Value(0)); + std::unique_ptr result(new Value(0)); method->process_execution( interceptors, params, *result.get() ); schedule_response( Response(result.release()) ); } @@ -95,7 +96,7 @@ void Pool_executor_factory::Pool_thread::operator ()() for(;;) { - scoped_lock lk(pool->req_queue_lock); + unique_lock lk(pool->req_queue_lock); if (pool->req_queue.empty()) { @@ -145,7 +146,7 @@ Executor* Pool_executor_factory::create( iqnet::Reactor_base* Pool_executor_factory::create_reactor() { - return new iqnet::Reactor; + return new iqnet::Reactor; } @@ -211,7 +212,7 @@ void Pool_executor::execute( const Param_list& params_ ) void Pool_executor::process_actual_execution() { try { - std::auto_ptr result(new Value(0)); + std::unique_ptr result(new Value(0)); method->process_execution( interceptors, params, *result.get() ); schedule_response( Response(result.release()) ); } diff --git a/libiqxmlrpc/executor.h b/libiqxmlrpc/executor.h index 2b7a79f0..7f5baa07 100644 --- a/libiqxmlrpc/executor.h +++ b/libiqxmlrpc/executor.h @@ -12,9 +12,10 @@ #pragma warning(disable: 4275) #endif -#include -#include -#include +#include // thread_group +#include +#include +#include #ifdef _MSC_VER #pragma warning(pop) @@ -46,7 +47,7 @@ struct Serial_executor_traits struct Pool_executor_traits { typedef Pool_executor_factory Executor_factory; - typedef boost::mutex Lock; + typedef std::mutex Lock; }; //! Abstract executor class. Defines the policy for method execution. @@ -134,11 +135,11 @@ class LIBIQXMLRPC_API Pool_executor_factory: public Executor_factory_base { // Objects Pool_thread works with std::deque req_queue; - boost::mutex req_queue_lock; - boost::condition req_queue_cond; + std::mutex req_queue_lock; + std::condition_variable req_queue_cond; bool in_destructor; - boost::mutex destructor_lock; + std::mutex destructor_lock; public: Pool_executor_factory(unsigned num_threads); diff --git a/libiqxmlrpc/http.cc b/libiqxmlrpc/http.cc index 88dc6ad5..bc0796ef 100644 --- a/libiqxmlrpc/http.cc +++ b/libiqxmlrpc/http.cc @@ -312,7 +312,7 @@ void Request_header::get_authinfo(std::string& user, std::string& pw) const if (v[0] != "basic") throw Unauthorized(); - boost::scoped_ptr bin_authinfo( Binary_data::from_base64(v[1]) ); + std::unique_ptr bin_authinfo( Binary_data::from_base64(v[1]) ); std::string data = bin_authinfo->get_data(); size_t colon_it = data.find_first_of(":"); @@ -324,7 +324,7 @@ void Request_header::get_authinfo(std::string& user, std::string& pw) const void Request_header::set_authinfo(const std::string& u, const std::string& p) { std::string h = u + ":" + p; - boost::scoped_ptr bin_authinfo( Binary_data::from_data(h) ); + std::unique_ptr bin_authinfo( Binary_data::from_data(h) ); set_option( names::authorization, "Basic " + bin_authinfo->get_base64() ); } diff --git a/libiqxmlrpc/http.h b/libiqxmlrpc/http.h index f3afa669..26437ade 100644 --- a/libiqxmlrpc/http.h +++ b/libiqxmlrpc/http.h @@ -9,9 +9,9 @@ #include "xheaders.h" #include -#include #include +#include #include namespace iqxmlrpc { @@ -149,7 +149,7 @@ class LIBIQXMLRPC_API Response_header: public Header { //! HTTP packet: Header + Content. class LIBIQXMLRPC_API Packet { protected: - boost::shared_ptr header_; + std::shared_ptr header_; std::string content_; public: diff --git a/libiqxmlrpc/http_client.h b/libiqxmlrpc/http_client.h index 215cdd8e..c271c603 100644 --- a/libiqxmlrpc/http_client.h +++ b/libiqxmlrpc/http_client.h @@ -9,6 +9,8 @@ #include "connector.h" #include "reactor.h" +#include + namespace iqxmlrpc { @@ -19,7 +21,7 @@ class LIBIQXMLRPC_API Http_client_connection: public iqxmlrpc::Client_connection, public iqnet::Connection { - std::auto_ptr reactor; + std::unique_ptr reactor; std::string out_str; http::Packet* resp_packet; diff --git a/libiqxmlrpc/https_client.cc b/libiqxmlrpc/https_client.cc index e7e860e6..a0a1e5c5 100644 --- a/libiqxmlrpc/https_client.cc +++ b/libiqxmlrpc/https_client.cc @@ -8,6 +8,8 @@ #include +#include + using namespace iqnet; namespace iqxmlrpc { @@ -45,7 +47,7 @@ Https_proxy_client_connection::Https_proxy_client_connection( Client_connection(), Connection( s ), reactor( new Reactor ), - resp_packet(0), + resp_packet(nullptr), non_blocking(nb) { sock.set_non_blocking( nb ); diff --git a/libiqxmlrpc/https_client.h b/libiqxmlrpc/https_client.h index 2295bf28..a2a12a46 100644 --- a/libiqxmlrpc/https_client.h +++ b/libiqxmlrpc/https_client.h @@ -10,7 +10,7 @@ #include "reactor.h" #include "ssl_connection.h" -#include +#include namespace iqxmlrpc { @@ -32,8 +32,8 @@ class LIBIQXMLRPC_API Https_proxy_client_connection: void setup_tunnel(); - boost::scoped_ptr reactor; - boost::scoped_ptr resp_packet; + std::unique_ptr reactor; + std::unique_ptr resp_packet; bool non_blocking; std::string out_str; }; @@ -43,7 +43,7 @@ class LIBIQXMLRPC_API Https_client_connection: public iqxmlrpc::Client_connection, public iqnet::ssl::Reaction_connection { - std::auto_ptr reactor; + std::unique_ptr reactor; http::Packet* resp_packet; std::string out_str; bool established; diff --git a/libiqxmlrpc/inet_addr.cc b/libiqxmlrpc/inet_addr.cc index 21d52bc2..97f8e11c 100644 --- a/libiqxmlrpc/inet_addr.cc +++ b/libiqxmlrpc/inet_addr.cc @@ -17,7 +17,7 @@ std::string get_host_name() } -#if defined(WIN32) || defined(__APPLE__) +#if defined(_WIN32) || defined(__APPLE__) #define IQXMLRPC_GETHOSTBYNAME(_h) \ hent = ::gethostbyname( _h ); \ if( !hent ) { \ diff --git a/libiqxmlrpc/inet_addr.h b/libiqxmlrpc/inet_addr.h index 45a9c0f5..14ca5521 100644 --- a/libiqxmlrpc/inet_addr.h +++ b/libiqxmlrpc/inet_addr.h @@ -10,8 +10,8 @@ #include "api_export.h" +#include #include -#include //! Object-oriented networking/multithreading infrastructure. namespace iqnet @@ -28,7 +28,7 @@ std::string LIBIQXMLRPC_API get_host_name(); /*! A wrapper for sockaddr_in system structure. */ class LIBIQXMLRPC_API Inet_addr { struct Impl; - boost::shared_ptr impl_; + std::shared_ptr impl_; public: //! Does nothing. diff --git a/libiqxmlrpc/method.h b/libiqxmlrpc/method.h index 3017f37b..5bf8342c 100644 --- a/libiqxmlrpc/method.h +++ b/libiqxmlrpc/method.h @@ -10,9 +10,9 @@ #include "xheaders.h" #include -#include #include +#include #include namespace iqxmlrpc @@ -100,8 +100,14 @@ class LIBIQXMLRPC_API Method { * in the same time. So the synchronization of internal state of * user-defined interceptor is up to it's creator. */ -class LIBIQXMLRPC_API Interceptor: boost::noncopyable { +class LIBIQXMLRPC_API Interceptor { public: + Interceptor() = default; + + Interceptor(const Interceptor&) = delete; + Interceptor(Interceptor&&) = delete; + Interceptor& operator=(const Interceptor&) = delete; + Interceptor& operator=(Interceptor&&) = delete; virtual ~Interceptor() {} void nest(Interceptor* ic) @@ -127,7 +133,7 @@ class LIBIQXMLRPC_API Interceptor: boost::noncopyable { } private: - boost::scoped_ptr nested; + std::unique_ptr nested; }; #ifdef _MSC_VER diff --git a/libiqxmlrpc/net_except.cc b/libiqxmlrpc/net_except.cc index 74a95f43..a97908a4 100644 --- a/libiqxmlrpc/net_except.cc +++ b/libiqxmlrpc/net_except.cc @@ -25,9 +25,9 @@ exception_message(const std::string& prefix, bool use_errno, int myerrno) myerrno = myerrno ? myerrno : errno; -#if !defined WIN32 && defined _GNU_SOURCE +#if !defined _WIN32 && defined _GNU_SOURCE b = strerror_r( myerrno, buf, sizeof(buf) - 1 ); -#elif !defined WIN32 +#elif !defined _WIN32 strerror_r( myerrno, buf, sizeof(buf) - 1 ); #else strerror_s( buf, sizeof(buf) - 1, WSAGetLastError() ); diff --git a/libiqxmlrpc/parser2.h b/libiqxmlrpc/parser2.h index 89742741..029807aa 100644 --- a/libiqxmlrpc/parser2.h +++ b/libiqxmlrpc/parser2.h @@ -5,9 +5,9 @@ #define _iqxmlrpc_parser2_h_ #include +#include #include #include -#include namespace iqxmlrpc { @@ -93,7 +93,7 @@ class Parser { private: class Impl; - boost::shared_ptr impl_; + std::shared_ptr impl_; }; class StateMachine { diff --git a/libiqxmlrpc/reactor_impl.h b/libiqxmlrpc/reactor_impl.h index fd2e4de1..bb80c177 100644 --- a/libiqxmlrpc/reactor_impl.h +++ b/libiqxmlrpc/reactor_impl.h @@ -23,19 +23,25 @@ #include -#include -#include #include +#include +#include +#include +#include namespace iqnet { //! The Reactor template class. -//! Lock param can be either boost::mutex or iqnet::Null_lock. +//! Lock param can be either std::mutex or iqnet::Null_lock. template -class Reactor: public Reactor_base, boost::noncopyable { +class Reactor: public Reactor_base { public: Reactor(); + Reactor(const Reactor&) = delete; + Reactor(Reactor&&) = delete; + Reactor& operator=(const Reactor&) = delete; + Reactor& operator=(Reactor&&) = delete; ~Reactor() {} void register_handler( Event_handler*, Event_mask ); @@ -47,7 +53,12 @@ class Reactor: public Reactor_base, boost::noncopyable { bool handle_events( Timeout ms = -1 ); private: - typedef typename Lock::scoped_lock scoped_lock; + using unique_lock = typename std::conditional< + std::is_same::value, + iqnet::Null_lock::scoped_lock, + std::unique_lock + >::type; + typedef std::map EventHandlersMap; typedef EventHandlersMap::iterator h_iterator; typedef HandlerStateList::const_iterator hs_const_iterator; @@ -98,7 +109,7 @@ Reactor::find_handler_state(Event_handler* eh) template iqnet::Event_handler* Reactor::find_handler(Socket::Handler fd) { - scoped_lock lk(lock); + unique_lock lk(lock); h_iterator i = handlers.find(fd); return i == handlers.end() ? NULL : i->second; } @@ -106,7 +117,7 @@ iqnet::Event_handler* Reactor::find_handler(Socket::Handler fd) template void Reactor::register_handler( Event_handler* eh, Event_mask mask ) { - scoped_lock lk(lock); + unique_lock lk(lock); if (eh->is_stopper()) num_stoppers++; @@ -128,7 +139,7 @@ void Reactor::register_handler( Event_handler* eh, Event_mask mask ) template void Reactor::unregister_handler( Event_handler* eh, Event_mask mask ) { - scoped_lock lk(lock); + unique_lock lk(lock); hs_iterator i = find_handler_state( eh ); if( i != end() ) @@ -149,7 +160,7 @@ void Reactor::unregister_handler( Event_handler* eh, Event_mask mask ) template void Reactor::unregister_handler( Event_handler* eh ) { - scoped_lock lk(lock); + unique_lock lk(lock); h_iterator i = handlers.find(eh->get_handler()); if( i != handlers.end() ) @@ -165,7 +176,7 @@ void Reactor::unregister_handler( Event_handler* eh ) template void Reactor::fake_event( Event_handler* eh, Event_mask mask ) { - scoped_lock lk(lock); + unique_lock lk(lock); hs_iterator i = find_handler_state( eh ); if( i != end() ) @@ -228,7 +239,7 @@ template void Reactor::handle_user_events() { HandlerStateList called_by_user; - scoped_lock lk(lock); + unique_lock lk(lock); for( hs_iterator i = begin(); i != end(); ++i ) { @@ -252,7 +263,7 @@ void Reactor::handle_user_events() template bool Reactor::handle_system_events(Reactor_base::Timeout ms) { - scoped_lock lk(lock); + unique_lock lk(lock); HandlerStateList tmp(handlers_states); lk.unlock(); diff --git a/libiqxmlrpc/reactor_interrupter.cc b/libiqxmlrpc/reactor_interrupter.cc index 7dcaee8a..5cdc10b8 100644 --- a/libiqxmlrpc/reactor_interrupter.cc +++ b/libiqxmlrpc/reactor_interrupter.cc @@ -7,9 +7,9 @@ #include "socket.h" #include -#include #include +#include namespace iqnet { @@ -39,17 +39,21 @@ class Interrupter_connection: public Connection { Reactor_base* reactor_; }; -class Reactor_interrupter::Impl: boost::noncopyable { +class Reactor_interrupter::Impl { public: Impl(Reactor_base* reactor); + Impl(const Impl&) = delete; + Impl(Impl&&) = delete; + Impl& operator=(const Impl&) = delete; + Impl& operator=(Impl&&) = delete; ~Impl() {} void make_interrupt(); private: - std::auto_ptr server_; + std::unique_ptr server_; Socket client_; - boost::mutex lock_; + std::mutex mutex_; }; @@ -68,7 +72,7 @@ Reactor_interrupter::Impl::Impl(Reactor_base* reactor) void Reactor_interrupter::Impl::make_interrupt() { - boost::mutex::scoped_lock lk(lock_); + std::lock_guard lk(mutex_); client_.send("\0", 1); } diff --git a/libiqxmlrpc/reactor_interrupter.h b/libiqxmlrpc/reactor_interrupter.h index ef866d82..4fa3379f 100644 --- a/libiqxmlrpc/reactor_interrupter.h +++ b/libiqxmlrpc/reactor_interrupter.h @@ -6,8 +6,6 @@ #include "reactor.h" -#include - namespace iqnet { #ifdef _MSC_VER @@ -15,9 +13,13 @@ namespace iqnet { #pragma warning(disable: 4275) #endif -class LIBIQXMLRPC_API Reactor_interrupter: boost::noncopyable { +class LIBIQXMLRPC_API Reactor_interrupter { public: Reactor_interrupter(Reactor_base*); + Reactor_interrupter(const Reactor_interrupter&) = delete; + Reactor_interrupter(Reactor_interrupter&&) = delete; + Reactor_interrupter& operator=(const Reactor_interrupter&) = delete; + Reactor_interrupter& operator=(Reactor_interrupter&&) = delete; ~Reactor_interrupter(); void make_interrupt(); diff --git a/libiqxmlrpc/reactor_poll_impl.h b/libiqxmlrpc/reactor_poll_impl.h index d5c3c30d..3fb0f652 100644 --- a/libiqxmlrpc/reactor_poll_impl.h +++ b/libiqxmlrpc/reactor_poll_impl.h @@ -7,18 +7,20 @@ #ifdef HAVE_POLL #include "reactor.h" -#include - namespace iqnet { //! Reactor implementation helper based on poll() system call. -class LIBIQXMLRPC_API Reactor_poll_impl: boost::noncopyable { +class LIBIQXMLRPC_API Reactor_poll_impl { struct Impl; Impl* impl; public: Reactor_poll_impl(); + Reactor_poll_impl(const Reactor_poll_impl&) = delete; + Reactor_poll_impl(Reactor_poll_impl&&) = delete; + Reactor_poll_impl& operator=(const Reactor_poll_impl&) = delete; + Reactor_poll_impl& operator=(Reactor_poll_impl&&) = delete; virtual ~Reactor_poll_impl(); void reset(const Reactor_base::HandlerStateList&); diff --git a/libiqxmlrpc/reactor_select_impl.h b/libiqxmlrpc/reactor_select_impl.h index 105e4098..06be9388 100644 --- a/libiqxmlrpc/reactor_select_impl.h +++ b/libiqxmlrpc/reactor_select_impl.h @@ -7,8 +7,6 @@ #ifndef HAVE_POLL #include "reactor.h" -#include - namespace iqnet { @@ -19,13 +17,17 @@ namespace iqnet #endif //! Reactor implementation helper based on select() system call. -class LIBIQXMLRPC_API Reactor_select_impl: boost::noncopyable { +class LIBIQXMLRPC_API Reactor_select_impl { Socket::Handler max_fd; fd_set read_set, write_set, err_set; Reactor_base::HandlerStateList hs; public: Reactor_select_impl(); + Reactor_select_impl(const Reactor_select_impl&) = delete; + Reactor_select_impl(Reactor_select_impl&&) = delete; + Reactor_select_impl& operator=(const Reactor_select_impl&) = delete; + Reactor_select_impl& operator=(Reactor_select_impl&&) = delete; virtual ~Reactor_select_impl(); void reset(const Reactor_base::HandlerStateList&); diff --git a/libiqxmlrpc/response.h b/libiqxmlrpc/response.h index 01fdce6a..5309cb7a 100644 --- a/libiqxmlrpc/response.h +++ b/libiqxmlrpc/response.h @@ -4,7 +4,7 @@ #ifndef _iqxmlrpc_response_h_ #define _iqxmlrpc_response_h_ -#include +#include #include #include "api_export.h" @@ -41,7 +41,7 @@ class LIBIQXMLRPC_API Response { const std::string& fault_string() const { return fault_string_; } private: - boost::shared_ptr value_; + std::shared_ptr value_; int fault_code_; std::string fault_string_; }; diff --git a/libiqxmlrpc/server.cc b/libiqxmlrpc/server.cc index 180eb550..fd705397 100644 --- a/libiqxmlrpc/server.cc +++ b/libiqxmlrpc/server.cc @@ -2,8 +2,6 @@ // Copyright (C) 2011 Anton Dedov #include -#include -#include #include "server.h" #include "auth_plugin.h" @@ -15,6 +13,8 @@ #include "server_conn.h" #include "xheaders.h" +#include + namespace iqxmlrpc { class Server::Impl { @@ -23,10 +23,10 @@ class Server::Impl { iqnet::Inet_addr bind_addr; - std::auto_ptr reactor; - std::auto_ptr interrupter; - std::auto_ptr conn_factory; - std::auto_ptr acceptor; + std::unique_ptr reactor; + std::unique_ptr interrupter; + std::unique_ptr conn_factory; + std::unique_ptr acceptor; iqnet::Firewall_base* firewall; bool exit_flag; @@ -35,7 +35,7 @@ class Server::Impl { http::Verification_level ver_level; Method_dispatcher_manager disp_manager; - std::auto_ptr interceptors; + std::unique_ptr interceptors; const Auth_Plugin_base* auth_plugin; Impl( @@ -47,14 +47,14 @@ class Server::Impl { reactor(ef->create_reactor()), interrupter(new iqnet::Reactor_interrupter(reactor.get())), conn_factory(cf), - acceptor(0), - firewall(0), + acceptor(nullptr), + firewall(nullptr), exit_flag(false), - log(0), + log(nullptr), max_req_sz(0), ver_level(http::HTTP_CHECK_WEAK), - interceptors(0), - auth_plugin(0) + interceptors(nullptr), + auth_plugin(nullptr) { } }; @@ -180,15 +180,15 @@ authenticate(const http::Packet& pkt, const Auth_Plugin_base* ap) void Server::schedule_execute( http::Packet* pkt, Server_connection* conn ) { - using boost::scoped_ptr; + using std::unique_ptr; using boost::optional; Executor* executor = 0; try { - scoped_ptr packet(pkt); + unique_ptr packet(pkt); optional authname = authenticate(*pkt, impl->auth_plugin); - scoped_ptr req( parse_request(packet->content()) ); + unique_ptr req( parse_request(packet->content()) ); Method::Data mdata = { req->get_name(), @@ -210,7 +210,7 @@ void Server::schedule_execute( http::Packet* pkt, Server_connection* conn ) catch( const iqxmlrpc::http::Error_response& e ) { log_err_msg( e.what() ); - std::auto_ptr executor_to_delete(executor); + std::unique_ptr executor_to_delete(executor); http::Packet *pkt = new http::Packet(e); conn->schedule_response( pkt ); } @@ -237,7 +237,7 @@ void Server::schedule_execute( http::Packet* pkt, Server_connection* conn ) void Server::schedule_response( const Response& resp, Server_connection* conn, Executor* exec ) { - std::auto_ptr executor_to_delete(exec); + std::unique_ptr executor_to_delete(exec); std::string resp_str = dump_response(resp); http::Packet *packet = new http::Packet(new http::Response_header(), resp_str); conn->schedule_response( packet ); diff --git a/libiqxmlrpc/server.h b/libiqxmlrpc/server.h index 059bc50b..89ac1dfa 100644 --- a/libiqxmlrpc/server.h +++ b/libiqxmlrpc/server.h @@ -31,13 +31,18 @@ class Auth_Plugin_base; #endif //! XML-RPC server. -class LIBIQXMLRPC_API Server: boost::noncopyable { +class LIBIQXMLRPC_API Server { public: Server( const iqnet::Inet_addr& addr, iqnet::Accepted_conn_factory* conn_factory, Executor_factory_base* executor_factory ); + Server(const Server&) = delete; + Server(Server&&) = delete; + Server& operator=(const Server&) = delete; + Server& operator=(Server&&) = delete; + virtual ~Server(); //! Register method using abstract factory. diff --git a/libiqxmlrpc/server_conn.cc b/libiqxmlrpc/server_conn.cc index 83dd8ad8..d24c59bd 100644 --- a/libiqxmlrpc/server_conn.cc +++ b/libiqxmlrpc/server_conn.cc @@ -6,6 +6,8 @@ #include "http_errors.h" #include "server.h" +#include + using namespace iqxmlrpc; Server_connection::Server_connection( const iqnet::Inet_addr& a ): @@ -50,7 +52,7 @@ http::Packet* Server_connection::read_request( const std::string& s ) void Server_connection::schedule_response( http::Packet* pkt ) { - std::auto_ptr p(pkt); + std::unique_ptr p(pkt); p->set_keep_alive( keep_alive ); response = p->dump(); do_schedule_response(); diff --git a/libiqxmlrpc/socket.cc b/libiqxmlrpc/socket.cc index ea3463f3..ba0c9ceb 100644 --- a/libiqxmlrpc/socket.cc +++ b/libiqxmlrpc/socket.cc @@ -17,12 +17,12 @@ Socket::Socket() if( (sock = socket( PF_INET, SOCK_STREAM, IPPROTO_TCP )) == -1 ) throw network_error( "Socket::Socket" ); -#ifndef WIN32 +#ifndef _WIN32 { int enable = 1; setsockopt( sock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable) ); } -#endif //WIN32 +#endif //_WIN32 #if defined(__APPLE__) { @@ -45,16 +45,16 @@ void Socket::shutdown() void Socket::close() { -#ifdef WIN32 +#ifdef _WIN32 closesocket(sock); #else ::close( sock ); -#endif //WIN32 +#endif //_WIN32 } void Socket::set_non_blocking( bool flag ) { -#ifdef WIN32 +#ifdef _WIN32 unsigned long f = flag ? 1 : 0; if( ioctlsocket(sock, FIONBIO, &f) != 0 ) throw network_error( "Socket::set_non_blocking"); @@ -64,7 +64,7 @@ void Socket::set_non_blocking( bool flag ) if( fcntl( sock, F_SETFL, O_NDELAY ) == -1 ) throw network_error( "Socket::set_non_blocking" ); -#endif //WIN32 +#endif //_WIN32 } #if defined(MSG_NOSIGNAL) @@ -135,7 +135,7 @@ bool Socket::connect( const iqnet::Inet_addr& peer_addr ) bool wouldblock = false; if( code == -1 ) { -#ifndef WIN32 +#ifndef _WIN32 wouldblock = errno == EINPROGRESS; #else wouldblock = get_last_error() == WSAEWOULDBLOCK; @@ -163,7 +163,7 @@ Inet_addr Socket::get_addr() const int Socket::get_last_error() { int err = 0; -#ifndef WIN32 +#ifndef _WIN32 socklen_t int_sz = sizeof(err); ::getsockopt( sock, SOL_SOCKET, SO_ERROR, &err, &int_sz ); #else diff --git a/libiqxmlrpc/ssl_lib.cc b/libiqxmlrpc/ssl_lib.cc index 2348a38f..18f65be8 100644 --- a/libiqxmlrpc/ssl_lib.cc +++ b/libiqxmlrpc/ssl_lib.cc @@ -1,7 +1,7 @@ // Libiqxmlrpc - an object-oriented XML-RPC solution. // Copyright (C) 2011 Anton Dedov -#ifdef WIN32 +#ifdef _WIN32 #include #endif @@ -12,11 +12,10 @@ #include #include -#include -#include #include +#include -#ifndef WIN32 +#ifndef _WIN32 #include #endif @@ -31,18 +30,22 @@ namespace ssl { // Mutli-threading support stuff // -class LockContainer: boost::noncopyable { +class LockContainer { public: LockContainer(): size(CRYPTO_num_locks()), - locks(new boost::mutex[size]) + locks(new std::mutex[size]) { } + LockContainer(const LockContainer&) = delete; + LockContainer(LockContainer&&) = delete; + LockContainer& operator=(const LockContainer&) = delete; + LockContainer& operator=(LockContainer&&) = delete; ~LockContainer(); size_t size; - boost::mutex* locks; + std::mutex* locks; }; void @@ -51,7 +54,7 @@ openssl_lock_callback(int mode, int n, const char* /*file*/, int /*line*/) static LockContainer lks; // assert n < lks.size - boost::mutex& m = lks.locks[n]; + std::mutex& m = lks.locks[n]; if (mode & CRYPTO_LOCK) { m.lock(); } else { diff --git a/libiqxmlrpc/ssl_lib.h b/libiqxmlrpc/ssl_lib.h index e0ae125f..50426f12 100644 --- a/libiqxmlrpc/ssl_lib.h +++ b/libiqxmlrpc/ssl_lib.h @@ -7,8 +7,8 @@ #include "api_export.h" #include -#include #include +#include namespace iqnet { namespace ssl { @@ -65,7 +65,7 @@ class LIBIQXMLRPC_API Ctx { Ctx(); struct Impl; - boost::shared_ptr impl_; + std::shared_ptr impl_; }; #ifdef _MSC_VER diff --git a/libiqxmlrpc/sysinc.h b/libiqxmlrpc/sysinc.h index c700296a..94683f28 100644 --- a/libiqxmlrpc/sysinc.h +++ b/libiqxmlrpc/sysinc.h @@ -9,7 +9,7 @@ #ifndef _iqxmlrpc_sysinc_h_ #define _iqxmlrpc_sysinc_h_ -#ifdef WIN32 +#ifdef _WIN32 #define BOOST_ALL_NO_LIB #if _MSC_VER < 1700 @@ -28,7 +28,7 @@ #include #include #include -#endif //WIN32 +#endif //_WIN32 #include #include diff --git a/libiqxmlrpc/util.h b/libiqxmlrpc/util.h index 31a7fb6f..edcd1129 100644 --- a/libiqxmlrpc/util.h +++ b/libiqxmlrpc/util.h @@ -66,7 +66,7 @@ class ExplicitPtr { //! Provides serialized access to some bool value template -class LockedBool: boost::noncopyable { +class LockedBool { bool val; Lock lock; @@ -74,6 +74,11 @@ class LockedBool: boost::noncopyable { LockedBool(bool default_): val(default_) {} + LockedBool(const LockedBool&) = delete; + LockedBool(LockedBool&&) = delete; + LockedBool& operator=(const LockedBool&) = delete; + LockedBool& operator=(LockedBool&&) = delete; + ~LockedBool() {} operator bool() diff --git a/libiqxmlrpc/value_parser.cc b/libiqxmlrpc/value_parser.cc index 49159a6f..6c1b7607 100644 --- a/libiqxmlrpc/value_parser.cc +++ b/libiqxmlrpc/value_parser.cc @@ -6,6 +6,8 @@ #include "except.h" #include "value_parser.h" +#include + namespace iqxmlrpc { ValueBuilderBase::ValueBuilderBase(Parser& parser, bool expect_text): @@ -188,8 +190,8 @@ ValueBuilder::do_visit_element_end(const std::string&) if (retval.get()) return; - std::auto_ptr default_int(Value::get_default_int()); - std::auto_ptr default_int64(Value::get_default_int64()); + std::unique_ptr default_int(Value::get_default_int()); + std::unique_ptr default_int64(Value::get_default_int64()); switch (state_.get_state()) { case VALUE: diff --git a/libiqxmlrpc/value_parser.h b/libiqxmlrpc/value_parser.h index 5eee11cf..c326d50f 100644 --- a/libiqxmlrpc/value_parser.h +++ b/libiqxmlrpc/value_parser.h @@ -7,6 +7,8 @@ #include "parser2.h" #include "value.h" +#include + namespace iqxmlrpc { class ValueBuilderBase: public BuilderBase { @@ -20,7 +22,7 @@ class ValueBuilderBase: public BuilderBase { } protected: - std::auto_ptr retval; + std::unique_ptr retval; }; class ValueBuilder: public ValueBuilderBase { diff --git a/libiqxmlrpc/xml_builder.h b/libiqxmlrpc/xml_builder.h index 689c6d28..c44b68cd 100644 --- a/libiqxmlrpc/xml_builder.h +++ b/libiqxmlrpc/xml_builder.h @@ -6,13 +6,12 @@ #include "api_export.h" -#include #include #include namespace iqxmlrpc { -class XmlBuilder: boost::noncopyable { +class XmlBuilder { public: class Node { public: @@ -27,6 +26,10 @@ class XmlBuilder: boost::noncopyable { }; XmlBuilder(); + XmlBuilder(const XmlBuilder&) = delete; + XmlBuilder(XmlBuilder&&) = delete; + XmlBuilder& operator=(const XmlBuilder&) = delete; + XmlBuilder& operator=(XmlBuilder&&) = delete; ~XmlBuilder(); void @@ -35,8 +38,7 @@ class XmlBuilder: boost::noncopyable { void stop(); - std::string - content() const; + std::string content() const; private: xmlBufferPtr buf; diff --git a/tests/client.cc b/tests/client.cc index 25befe67..b172603d 100644 --- a/tests/client.cc +++ b/tests/client.cc @@ -11,10 +11,12 @@ #include "client_common.h" #include "client_opts.h" -#if defined(WIN32) +#if defined(_WIN32) #include #endif +#include + using namespace boost::unit_test; using namespace iqxmlrpc; @@ -26,7 +28,7 @@ class ClientFixture { public: ClientFixture() { -#if defined(WIN32) +#if defined(_WIN32) WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(2, 2); @@ -115,7 +117,7 @@ BOOST_AUTO_TEST_CASE( get_file_test ) MD5(reinterpret_cast(d.get_data().data()), d.get_data().length(), md5); - std::auto_ptr gen_md5( Binary_data::from_data( + std::unique_ptr gen_md5( Binary_data::from_data( reinterpret_cast(md5), sizeof(md5)) ); BOOST_TEST_MESSAGE("Recieved MD5: " + m.get_base64()); diff --git a/tests/client_stress.cc b/tests/client_stress.cc index bf196fd5..c8f1a3d3 100644 --- a/tests/client_stress.cc +++ b/tests/client_stress.cc @@ -1,9 +1,5 @@ #define BOOST_TEST_MODULE test_client_stress -#include #include -#include -#include -#include #include #include #include @@ -11,10 +7,16 @@ #include "client_common.h" #include "client_opts.h" -#if defined(WIN32) +#if defined(_WIN32) #include #endif +#include +#include +#include +#include +#include + using namespace boost::unit_test; using namespace boost::program_options; using namespace iqxmlrpc; @@ -45,7 +47,7 @@ class ClientFixture { public: ClientFixture() { -#if defined(WIN32) +#if defined(_WIN32) WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(2, 2); @@ -84,7 +86,7 @@ void do_call(Client_base* client) void do_test() { try { - std::auto_ptr client(test_config.create_instance()); + std::unique_ptr client(test_config.create_instance()); for (int i = 0; i < test_config.calls_per_thread(); ++i) { do_call(client.get()); } diff --git a/tests/parser2.cc b/tests/parser2.cc index d4ce2af9..dc43558c 100644 --- a/tests/parser2.cc +++ b/tests/parser2.cc @@ -1,7 +1,4 @@ #define BOOST_TEST_MODULE test_parser -#include -#include -#include #include #include #include "libiqxmlrpc/value.h" @@ -9,6 +6,11 @@ #include "libiqxmlrpc/request_parser.h" #include "libiqxmlrpc/response_parser.h" +#include +#include +#include +#include + using namespace boost::unit_test; using namespace iqxmlrpc; @@ -259,7 +261,7 @@ BOOST_AUTO_TEST_CASE(test_parse_request) \ "; - std::auto_ptr req(parse_request(r)); + std::unique_ptr req(parse_request(r)); BOOST_CHECK_EQUAL(req->get_name(), "get_weather"); BOOST_CHECK_EQUAL(req->get_params().size(), 2); BOOST_CHECK_EQUAL(req->get_params().front().get_string(), "Krasnoyarsk"); @@ -278,7 +280,7 @@ BOOST_AUTO_TEST_CASE(test_parse_request_empty_param) \ "; - std::auto_ptr req(parse_request(r)); + std::unique_ptr req(parse_request(r)); BOOST_CHECK_EQUAL(req->get_name(), "do_something"); BOOST_CHECK_EQUAL(req->get_params().size(), 1); BOOST_CHECK_EQUAL(req->get_params().back().get_string(), ""); @@ -287,7 +289,7 @@ BOOST_AUTO_TEST_CASE(test_parse_request_empty_param) BOOST_AUTO_TEST_CASE(test_parse_request_no_params) { std::string r = "do_something"; - std::auto_ptr req(parse_request(r)); + std::unique_ptr req(parse_request(r)); BOOST_CHECK_EQUAL(req->get_name(), "do_something"); BOOST_CHECK_EQUAL(req->get_params().size(), 0); } diff --git a/tests/test_server.cc b/tests/test_server.cc index f8667efd..52d172b8 100644 --- a/tests/test_server.cc +++ b/tests/test_server.cc @@ -1,6 +1,3 @@ -#include -#include -#include #include #include #include @@ -13,10 +10,14 @@ #include "methods.h" #include "libiqxmlrpc/xheaders.h" -#if defined(WIN32) +#if defined(_WIN32) #include #endif +#include +#include +#include + using namespace boost::unit_test; using namespace iqxmlrpc; @@ -83,14 +84,19 @@ class PermissiveAuthPlugin: public iqxmlrpc::Auth_Plugin_base { } }; -class Test_server: boost::noncopyable { - std::auto_ptr ef_; - std::auto_ptr impl_; +class Test_server { + std::unique_ptr ef_; + std::unique_ptr impl_; PermissiveAuthPlugin auth_plugin_; public: Test_server(const Test_server_config&); + Test_server(const Test_server&) = delete; + Test_server(Test_server&&) = delete; + Test_server& operator=(const Test_server&) = delete; + Test_server& operator=(Test_server&&) = delete; + Server& impl() { return *impl_.get(); } void work(); @@ -99,8 +105,8 @@ class Test_server: boost::noncopyable { Test_server* test_server = 0; Test_server::Test_server(const Test_server_config& conf): - ef_(0), - impl_(0) + ef_{nullptr}, + impl_{nullptr} { if (conf.numthreads > 1) { @@ -151,7 +157,7 @@ void test_server_sig_handler(int) int main(int argc, const char** argv) { -#if defined(WIN32) +#if defined(_WIN32) WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(2, 2); diff --git a/tests/test_server_stop.cc b/tests/test_server_stop.cc index 10b88469..2a898510 100644 --- a/tests/test_server_stop.cc +++ b/tests/test_server_stop.cc @@ -1,10 +1,6 @@ #include #include #include -#include -#include -#include -#include #include #include #include @@ -18,19 +14,34 @@ #define MY_BOOST_TIME_UTC boost::TIME_UTC #endif +#include +#include +#include +#include +#include +#include + using namespace boost::unit_test_framework; using namespace iqxmlrpc; -class TestServer: boost::noncopyable { +std::chrono::microseconds from_xtime(const boost::xtime& xt) { + return std::chrono::seconds(xt.sec) + std::chrono::microseconds(xt.usec); +} + +class TestServer { public: TestServer(int port, unsigned threads): exec_factory_(threads > 1 ? static_cast(new Pool_executor_factory(threads)) : static_cast(new Serial_executor_factory)), serv_(new Http_server(port, exec_factory_.get())), - thread_(new boost::thread(boost::bind(&TestServer::run, this))) + thread_(new std::thread(std::bind(&TestServer::run, this))) { } + TestServer(const TestServer&) = delete; + TestServer(TestServer&&) = delete; + TestServer& operator=(const TestServer&) = delete; + TestServer& operator=(TestServer&&) = delete; void stop() { @@ -43,9 +54,9 @@ class TestServer: boost::noncopyable { } private: - boost::scoped_ptr exec_factory_; - boost::scoped_ptr serv_; - boost::scoped_ptr thread_; + std::unique_ptr exec_factory_; + std::unique_ptr serv_; + std::unique_ptr thread_; static void run(TestServer* obj) { @@ -53,7 +64,7 @@ class TestServer: boost::noncopyable { } }; -void stop_and_join(unsigned threads, boost::condition* on_stop) +void stop_and_join(unsigned threads, std::condition_variable* on_stop) { TestServer s(3344, threads); @@ -61,7 +72,7 @@ void stop_and_join(unsigned threads, boost::condition* on_stop) boost::xtime_get(&time_wait, MY_BOOST_TIME_UTC); time_wait.sec += 1; - boost::thread::sleep(time_wait); + std::this_thread::sleep_for(from_xtime(time_wait)); s.stop(); s.join(); @@ -70,23 +81,23 @@ void stop_and_join(unsigned threads, boost::condition* on_stop) void stop_test_server(unsigned server_threads) { - boost::condition stopped; - boost::mutex c_mutex; + std::condition_variable stopped; + std::mutex c_mutex; - boost::thread thr(boost::bind(stop_and_join, server_threads, &stopped)); + std::thread thr(std::bind(stop_and_join, server_threads, &stopped)); { boost::xtime time_wait; boost::xtime_get(&time_wait, MY_BOOST_TIME_UTC); time_wait.sec += 1; - boost::thread::sleep(time_wait); + std::this_thread::sleep_for(from_xtime(time_wait)); } boost::xtime time_wait; boost::xtime_get(&time_wait, MY_BOOST_TIME_UTC); time_wait.sec += 3; - boost::mutex::scoped_lock lck(c_mutex); + std::lock_guard lck(c_mutex); BOOST_CHECK( stopped.timed_wait(lck, time_wait) ); } diff --git a/tests/test_value_usage.cc b/tests/test_value_usage.cc index b199e3dc..7419882f 100644 --- a/tests/test_value_usage.cc +++ b/tests/test_value_usage.cc @@ -1,11 +1,13 @@ #define BOOST_TEST_MODULE value_test -#include -#include -#include #include #include #include "libiqxmlrpc/value.h" +#include +#include +#include +#include + using namespace boost::unit_test; using namespace iqxmlrpc; @@ -79,7 +81,7 @@ BOOST_AUTO_TEST_CASE( array_test ) Array a; a.push_back(0); BOOST_TEST_CHECKPOINT("Suspicious Array cloning"); - std::auto_ptr a1(a.clone()); + std::unique_ptr a1(a.clone()); BOOST_CHECK_EQUAL((*a1.get())[0].get_int(), 0); } @@ -161,7 +163,7 @@ BOOST_AUTO_TEST_CASE( struct_test ) BOOST_CHECK(s["pages"].is_int()); BOOST_TEST_CHECKPOINT("Suspicious Struct cloning"); - std::auto_ptr s1(s.clone()); + std::unique_ptr s1(s.clone()); BOOST_CHECK(s1->has_field("pages")); }