From a3241998e1e300e87e7c57d92c2478f67ec91db6 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Fri, 19 Dec 2014 15:21:29 -0500 Subject: [PATCH] namespace: remove boost namespace pollution --- src/bitcoin-cli.cpp | 14 +++++------ src/core_read.cpp | 1 - src/db.cpp | 5 ++-- src/init.cpp | 25 +++++++++--------- src/main.cpp | 3 +-- src/net.cpp | 1 - src/qt/paymentserver.cpp | 1 - src/rpcmisc.cpp | 1 - src/rpcprotocol.cpp | 1 - src/rpcrawtransaction.cpp | 1 - src/rpcserver.cpp | 53 +++++++++++++++++++-------------------- src/rpcwallet.cpp | 1 - src/walletdb.cpp | 13 +++++----- 13 files changed, 53 insertions(+), 67 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 668d492d6bc..f273a15713f 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -15,8 +15,6 @@ #define _(x) std::string(x) /* Keep the _() around in case gettext or such will be used later to translate non-UI */ using namespace std; -using namespace boost; -using namespace boost::asio; using namespace json_spirit; std::string HelpMessageCli() @@ -108,12 +106,12 @@ Object CallRPC(const string& strMethod, const Array& params) // Connect to localhost bool fUseSSL = GetBoolArg("-rpcssl", false); - asio::io_service io_service; - ssl::context context(io_service, ssl::context::sslv23); - context.set_options(ssl::context::no_sslv2 | ssl::context::no_sslv3); - asio::ssl::stream sslStream(io_service, context); - SSLIOStreamDevice d(sslStream, fUseSSL); - iostreams::stream< SSLIOStreamDevice > stream(d); + boost::asio::io_service io_service; + boost::asio::ssl::context context(io_service, boost::asio::ssl::context::sslv23); + context.set_options(boost::asio::ssl::context::no_sslv2 | boost::asio::ssl::context::no_sslv3); + boost::asio::ssl::stream sslStream(io_service, context); + SSLIOStreamDevice d(sslStream, fUseSSL); + boost::iostreams::stream< SSLIOStreamDevice > stream(d); const bool fConnected = d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(BaseParams().RPCPort()))); if (!fConnected) diff --git a/src/core_read.cpp b/src/core_read.cpp index 7999030662d..85b60e9adba 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -20,7 +20,6 @@ #include #include -using namespace boost; using namespace boost::algorithm; using namespace std; diff --git a/src/db.cpp b/src/db.cpp index 94629968d5c..fcc177f1ccd 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -24,7 +24,6 @@ #include using namespace std; -using namespace boost; unsigned int nWalletDBUpdated; @@ -73,9 +72,9 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn) boost::this_thread::interruption_point(); path = pathIn; - filesystem::path pathLogDir = path / "database"; + boost::filesystem::path pathLogDir = path / "database"; TryCreateDirectory(pathLogDir); - filesystem::path pathErrorFile = path / "db.log"; + boost::filesystem::path pathErrorFile = path / "db.log"; LogPrintf("CDBEnv::Open : LogDir=%s ErrorFile=%s\n", pathLogDir.string(), pathErrorFile.string()); unsigned int nEnvFlags = 0; diff --git a/src/init.cpp b/src/init.cpp index a09caeea401..1b0c909b962 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -43,7 +43,6 @@ #include #include -using namespace boost; using namespace std; #ifdef ENABLE_WALLET @@ -427,12 +426,12 @@ void ThreadImport(std::vector vImportFiles) } // hardcoded $DATADIR/bootstrap.dat - filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat"; - if (filesystem::exists(pathBootstrap)) { + boost::filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat"; + if (boost::filesystem::exists(pathBootstrap)) { FILE *file = fopen(pathBootstrap.string().c_str(), "rb"); if (file) { CImportingNow imp; - filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old"; + boost::filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old"; LogPrintf("Importing bootstrap.dat...\n"); LoadExternalBlockFile(file); RenameOver(pathBootstrap, pathBootstrapOld); @@ -816,7 +815,7 @@ bool AppInit2(boost::thread_group& threadGroup) return false; } - if (filesystem::exists(GetDataDir() / strWalletFile)) + if (boost::filesystem::exists(GetDataDir() / strWalletFile)) { CDBEnv::VerifyResult r = bitdb.Verify(strWalletFile, CWalletDB::Recover); if (r == CDBEnv::RECOVER_OK) @@ -937,20 +936,20 @@ bool AppInit2(boost::thread_group& threadGroup) fReindex = GetBoolArg("-reindex", false); // Upgrading to 0.8; hard-link the old blknnnn.dat files into /blocks/ - filesystem::path blocksDir = GetDataDir() / "blocks"; - if (!filesystem::exists(blocksDir)) + boost::filesystem::path blocksDir = GetDataDir() / "blocks"; + if (!boost::filesystem::exists(blocksDir)) { - filesystem::create_directories(blocksDir); + boost::filesystem::create_directories(blocksDir); bool linked = false; for (unsigned int i = 1; i < 10000; i++) { - filesystem::path source = GetDataDir() / strprintf("blk%04u.dat", i); - if (!filesystem::exists(source)) break; - filesystem::path dest = blocksDir / strprintf("blk%05u.dat", i-1); + boost::filesystem::path source = GetDataDir() / strprintf("blk%04u.dat", i); + if (!boost::filesystem::exists(source)) break; + boost::filesystem::path dest = blocksDir / strprintf("blk%05u.dat", i-1); try { - filesystem::create_hard_link(source, dest); + boost::filesystem::create_hard_link(source, dest); LogPrintf("Hardlinked %s -> %s\n", source.string(), dest.string()); linked = true; - } catch (const filesystem::filesystem_error& e) { + } catch (const boost::filesystem::filesystem_error& e) { // Note: hardlink creation failing is not a disaster, it just means // blocks will get re-downloaded from peers. LogPrintf("Error hardlinking blk%04u.dat : %s\n", i, e.what()); diff --git a/src/main.cpp b/src/main.cpp index f02a6a12efe..f768f1e29fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,7 +28,6 @@ #include #include -using namespace boost; using namespace std; #if defined(NDEBUG) @@ -2788,7 +2787,7 @@ bool AbortNode(const std::string &strMessage, const std::string &userMessage) { bool CheckDiskSpace(uint64_t nAdditionalBytes) { - uint64_t nFreeBytesAvailable = filesystem::space(GetDataDir()).available; + uint64_t nFreeBytesAvailable = boost::filesystem::space(GetDataDir()).available; // Check for nMinDiskSpace bytes (currently 50MB) if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes) diff --git a/src/net.cpp b/src/net.cpp index 6401ecbf83e..d07882c7f4c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -49,7 +49,6 @@ #endif #endif -using namespace boost; using namespace std; namespace { diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index b3dbb693d73..66331ee4b4c 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -46,7 +46,6 @@ #include #endif -using namespace boost; using namespace std; const int BITCOIN_IPC_CONNECT_TIMEOUT = 1000; // milliseconds diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 7c08a5c2469..1013418184c 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -23,7 +23,6 @@ #include "json/json_spirit_utils.h" #include "json/json_spirit_value.h" -using namespace boost; using namespace boost::assign; using namespace json_spirit; using namespace std; diff --git a/src/rpcprotocol.cpp b/src/rpcprotocol.cpp index c4d6f06b12c..b08598d0bf9 100644 --- a/src/rpcprotocol.cpp +++ b/src/rpcprotocol.cpp @@ -26,7 +26,6 @@ #include "json/json_spirit_writer_template.h" using namespace std; -using namespace boost; using namespace boost::asio; using namespace json_spirit; diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index b87a8baac3c..35319e4803a 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -25,7 +25,6 @@ #include "json/json_spirit_utils.h" #include "json/json_spirit_value.h" -using namespace boost; using namespace boost::assign; using namespace json_spirit; using namespace std; diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 210c7fe9733..a070ab5bbe7 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -26,7 +26,6 @@ #include #include "json/json_spirit_writer_template.h" -using namespace boost; using namespace boost::asio; using namespace json_spirit; using namespace std; @@ -39,7 +38,7 @@ static std::string rpcWarmupStatus("RPC server started"); static CCriticalSection cs_rpcWarmup; //! These are created by StartRPCThreads, destroyed in StopRPCThreads -static asio::io_service* rpc_io_service = NULL; +static boost::asio::io_service* rpc_io_service = NULL; static map > deadlineTimers; static ssl::context* rpc_ssl_context = NULL; static boost::thread_group* rpc_worker_group = NULL; @@ -428,7 +427,7 @@ class AcceptedConnectionImpl : public AcceptedConnection { public: AcceptedConnectionImpl( - asio::io_service& io_service, + boost::asio::io_service& io_service, ssl::context &context, bool fUseSSL) : sslStream(io_service, context), @@ -453,11 +452,11 @@ public: } typename Protocol::endpoint peer; - asio::ssl::stream sslStream; + boost::asio::ssl::stream sslStream; private: SSLIOStreamDevice _d; - iostreams::stream< SSLIOStreamDevice > _stream; + boost::iostreams::stream< SSLIOStreamDevice > _stream; }; void ServiceConnection(AcceptedConnection *conn); @@ -504,7 +503,7 @@ static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptoris_open()) + if (error != boost::asio::error::operation_aborted && acceptor->is_open()) RPCListen(acceptor, context, fUseSSL); AcceptedConnectionImpl* tcp_conn = dynamic_cast< AcceptedConnectionImpl* >(conn.get()); @@ -535,7 +534,7 @@ static ip::tcp::endpoint ParseEndpoint(const std::string &strEndpoint, int defau std::string addr; int port = defaultPort; SplitHostPort(strEndpoint, port, addr); - return ip::tcp::endpoint(asio::ip::address::from_string(addr), port); + return ip::tcp::endpoint(boost::asio::ip::address::from_string(addr), port); } void StartRPCThreads() @@ -590,7 +589,7 @@ void StartRPCThreads() } assert(rpc_io_service == NULL); - rpc_io_service = new asio::io_service(); + rpc_io_service = new boost::asio::io_service(); rpc_ssl_context = new ssl::context(*rpc_io_service, ssl::context::sslv23); const bool fUseSSL = GetBoolArg("-rpcssl", false); @@ -599,14 +598,14 @@ void StartRPCThreads() { rpc_ssl_context->set_options(ssl::context::no_sslv2 | ssl::context::no_sslv3); - filesystem::path pathCertFile(GetArg("-rpcsslcertificatechainfile", "server.cert")); - if (!pathCertFile.is_complete()) pathCertFile = filesystem::path(GetDataDir()) / pathCertFile; - if (filesystem::exists(pathCertFile)) rpc_ssl_context->use_certificate_chain_file(pathCertFile.string()); + boost::filesystem::path pathCertFile(GetArg("-rpcsslcertificatechainfile", "server.cert")); + if (!pathCertFile.is_complete()) pathCertFile = boost::filesystem::path(GetDataDir()) / pathCertFile; + if (boost::filesystem::exists(pathCertFile)) rpc_ssl_context->use_certificate_chain_file(pathCertFile.string()); else LogPrintf("ThreadRPCServer ERROR: missing server certificate file %s\n", pathCertFile.string()); - filesystem::path pathPKFile(GetArg("-rpcsslprivatekeyfile", "server.pem")); - if (!pathPKFile.is_complete()) pathPKFile = filesystem::path(GetDataDir()) / pathPKFile; - if (filesystem::exists(pathPKFile)) rpc_ssl_context->use_private_key_file(pathPKFile.string(), ssl::context::pem); + boost::filesystem::path pathPKFile(GetArg("-rpcsslprivatekeyfile", "server.pem")); + if (!pathPKFile.is_complete()) pathPKFile = boost::filesystem::path(GetDataDir()) / pathPKFile; + if (boost::filesystem::exists(pathPKFile)) rpc_ssl_context->use_private_key_file(pathPKFile.string(), ssl::context::pem); else LogPrintf("ThreadRPCServer ERROR: missing server private key file %s\n", pathPKFile.string()); string strCiphers = GetArg("-rpcsslciphers", "TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH"); @@ -618,8 +617,8 @@ void StartRPCThreads() int defaultPort = GetArg("-rpcport", BaseParams().RPCPort()); if (!mapArgs.count("-rpcallowip")) // Default to loopback if not allowing external IPs { - vEndpoints.push_back(ip::tcp::endpoint(asio::ip::address_v6::loopback(), defaultPort)); - vEndpoints.push_back(ip::tcp::endpoint(asio::ip::address_v4::loopback(), defaultPort)); + vEndpoints.push_back(ip::tcp::endpoint(boost::asio::ip::address_v6::loopback(), defaultPort)); + vEndpoints.push_back(ip::tcp::endpoint(boost::asio::ip::address_v4::loopback(), defaultPort)); if (mapArgs.count("-rpcbind")) { LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n"); @@ -641,8 +640,8 @@ void StartRPCThreads() } } } else { // No specific bind address specified, bind to any - vEndpoints.push_back(ip::tcp::endpoint(asio::ip::address_v6::any(), defaultPort)); - vEndpoints.push_back(ip::tcp::endpoint(asio::ip::address_v4::any(), defaultPort)); + vEndpoints.push_back(ip::tcp::endpoint(boost::asio::ip::address_v6::any(), defaultPort)); + vEndpoints.push_back(ip::tcp::endpoint(boost::asio::ip::address_v4::any(), defaultPort)); // Prefer making the socket dual IPv6/IPv4 instead of binding // to both addresses seperately. bBindAny = true; @@ -654,7 +653,7 @@ void StartRPCThreads() BOOST_FOREACH(const ip::tcp::endpoint &endpoint, vEndpoints) { try { - asio::ip::address bindAddress = endpoint.address(); + boost::asio::ip::address bindAddress = endpoint.address(); straddress = bindAddress.to_string(); LogPrintf("Binding RPC on address %s port %i (IPv4+IPv6 bind any: %i)\n", straddress, endpoint.port(), bBindAny); boost::system::error_code v6_only_error; @@ -665,7 +664,7 @@ void StartRPCThreads() // Try making the socket dual IPv6/IPv4 when listening on the IPv6 "any" address acceptor->set_option(boost::asio::ip::v6_only( - !bBindAny || bindAddress != asio::ip::address_v6::any()), v6_only_error); + !bBindAny || bindAddress != boost::asio::ip::address_v6::any()), v6_only_error); acceptor->bind(endpoint); acceptor->listen(socket_base::max_connections); @@ -675,7 +674,7 @@ void StartRPCThreads() fListening = true; rpc_acceptors.push_back(acceptor); // If dual IPv6/IPv4 bind successful, skip binding to IPv4 separately - if(bBindAny && bindAddress == asio::ip::address_v6::any() && !v6_only_error) + if(bBindAny && bindAddress == boost::asio::ip::address_v6::any() && !v6_only_error) break; } catch (const boost::system::system_error& e) @@ -693,7 +692,7 @@ void StartRPCThreads() rpc_worker_group = new boost::thread_group(); for (int i = 0; i < GetArg("-rpcthreads", 4); i++) - rpc_worker_group->create_thread(boost::bind(&asio::io_service::run, rpc_io_service)); + rpc_worker_group->create_thread(boost::bind(&boost::asio::io_service::run, rpc_io_service)); fRPCRunning = true; } @@ -701,12 +700,12 @@ void StartDummyRPCThread() { if(rpc_io_service == NULL) { - rpc_io_service = new asio::io_service(); + rpc_io_service = new boost::asio::io_service(); /* Create dummy "work" to keep the thread from exiting when no timeouts active, * see http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/reference/io_service.html#boost_asio.reference.io_service.stopping_the_io_service_from_running_out_of_work */ - rpc_dummy_work = new asio::io_service::work(*rpc_io_service); + rpc_dummy_work = new boost::asio::io_service::work(*rpc_io_service); rpc_worker_group = new boost::thread_group(); - rpc_worker_group->create_thread(boost::bind(&asio::io_service::run, rpc_io_service)); + rpc_worker_group->create_thread(boost::bind(&boost::asio::io_service::run, rpc_io_service)); fRPCRunning = true; } } @@ -719,7 +718,7 @@ void StopRPCThreads() // First, cancel all timers and acceptors // This is not done automatically by ->stop(), and in some cases the destructor of - // asio::io_service can hang if this is skipped. + // boost::asio::io_service can hang if this is skipped. boost::system::error_code ec; BOOST_FOREACH(const boost::shared_ptr &acceptor, rpc_acceptors) { @@ -787,7 +786,7 @@ void RPCRunLater(const std::string& name, boost::function func, int6 deadlineTimers.insert(make_pair(name, boost::shared_ptr(new deadline_timer(*rpc_io_service)))); } - deadlineTimers[name]->expires_from_now(posix_time::seconds(nSeconds)); + deadlineTimers[name]->expires_from_now(boost::posix_time::seconds(nSeconds)); deadlineTimers[name]->async_wait(boost::bind(RPCRunHandler, _1, func)); } diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 56be6dba135..a6b38ead624 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -23,7 +23,6 @@ #include "json/json_spirit_value.h" using namespace std; -using namespace boost; using namespace boost::assign; using namespace json_spirit; diff --git a/src/walletdb.cpp b/src/walletdb.cpp index 4fd7eb512b9..668130ed695 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -18,7 +18,6 @@ #include #include -using namespace boost; using namespace std; static uint64_t nAccountingEntryNumber = 0; @@ -865,20 +864,20 @@ bool BackupWallet(const CWallet& wallet, const string& strDest) bitdb.mapFileUseCount.erase(wallet.strWalletFile); // Copy wallet.dat - filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile; - filesystem::path pathDest(strDest); - if (filesystem::is_directory(pathDest)) + boost::filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile; + boost::filesystem::path pathDest(strDest); + if (boost::filesystem::is_directory(pathDest)) pathDest /= wallet.strWalletFile; try { #if BOOST_VERSION >= 104000 - filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists); + boost::filesystem::copy_file(pathSrc, pathDest, boost::filesystem::copy_option::overwrite_if_exists); #else - filesystem::copy_file(pathSrc, pathDest); + boost::filesystem::copy_file(pathSrc, pathDest); #endif LogPrintf("copied wallet.dat to %s\n", pathDest.string()); return true; - } catch (const filesystem::filesystem_error& e) { + } catch (const boost::filesystem::filesystem_error& e) { LogPrintf("error copying wallet.dat to %s - %s\n", pathDest.string(), e.what()); return false; }