diff --git a/ACore/src/Log.hpp b/ACore/src/Log.hpp index 92fcc5eb5..6ad7a917f 100644 --- a/ACore/src/Log.hpp +++ b/ACore/src/Log.hpp @@ -35,8 +35,6 @@ #include #include -#include - #include "DurationTimer.hpp" namespace ecf { @@ -217,7 +215,7 @@ std::string stringize_f(Functor const& f) { f(out); return out.str(); } -#define STRINGIZE(EXPRESSION) (ecf::stringize_f(boost::lambda::_1 << EXPRESSION)) +#define STRINGIZE(EXPRESSION) (ecf::stringize_f([&](std::ostringstream& os) { os << EXPRESSION; })) #define LOG(level, EXPRESSION) ecf::log(level, STRINGIZE(EXPRESSION)) #define LOG_ASSERT(expr, EXPRESSION) \ ((expr) ? (static_cast(0)) : ecf::log_assert(#expr, __FILE__, __LINE__, STRINGIZE(EXPRESSION))) diff --git a/ANode/src/ExprParser.cpp b/ANode/src/ExprParser.cpp index d5c6b568e..7a12a651b 100644 --- a/ANode/src/ExprParser.cpp +++ b/ANode/src/ExprParser.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -49,9 +50,6 @@ #include "Log.hpp" #include "NodeAttr.hpp" #include "Str.hpp" -#include "boost/cast.hpp" -#include "boost/lambda/bind.hpp" -#include "boost/lambda/lambda.hpp" // Reference // ‘*’ Zero or more diff --git a/Base/src/Client.cpp b/Base/src/Client.cpp index f22f02c2c..b21523ab9 100644 --- a/Base/src/Client.cpp +++ b/Base/src/Client.cpp @@ -18,8 +18,6 @@ #include #include -#include - #include "StcCmd.hpp" #ifdef DEBUG_PERF @@ -111,8 +109,10 @@ bool Client::start_connect(boost::asio::ip::tcp::resolver::iterator endpoint_ite deadline_.expires_from_now(boost::posix_time::seconds(timeout_)); boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator; - connection_.socket_ll().async_connect( - endpoint, boost::bind(&Client::handle_connect, this, boost::asio::placeholders::error, endpoint_iterator)); + connection_.socket_ll().async_connect(endpoint, + [this, endpoint_iterator](const boost::system::error_code& error) { + this->handle_connect(error, endpoint_iterator); + }); } else { // ran out of end points @@ -194,7 +194,7 @@ void Client::start_write() { deadline_.expires_from_now(boost::posix_time::seconds(timeout_)); connection_.async_write(outbound_request_, - boost::bind(&Client::handle_write, this, boost::asio::placeholders::error)); + [this](const boost::system::error_code& error) { this->handle_write(error); }); } void Client::handle_write(const boost::system::error_code& e) { @@ -238,7 +238,7 @@ void Client::start_read() { deadline_.expires_from_now(boost::posix_time::seconds(timeout_)); connection_.async_read(inbound_response_, - boost::bind(&Client::handle_read, this, boost::asio::placeholders::error)); + [this](const boost::system::error_code& error) { this->handle_read(error); }); } void Client::handle_read(const boost::system::error_code& e) { diff --git a/Base/src/Connection.hpp b/Base/src/Connection.hpp index 8c1b1d672..3dd73b488 100644 --- a/Base/src/Connection.hpp +++ b/Base/src/Connection.hpp @@ -25,8 +25,6 @@ #include #include -#include -#include #include "Serialization.hpp" @@ -68,8 +66,7 @@ class connection { catch (const std::exception& ae) { // Unable to decode data. Something went wrong, inform the caller. log_archive_error("Connection::async_write, exception ", ae, outbound_data_); - boost::system::error_code error(boost::asio::error::invalid_argument); - boost::asio::post(socket_.get_executor(), boost::bind(handler, error)); + boost::asio::post(socket_.get_executor(), [handler]() { handler(boost::asio::error::invalid_argument); }); return; } @@ -82,8 +79,7 @@ class connection { if (!header_stream || header_stream.str().size() != header_length) { // Something went wrong, inform the caller. log_error("Connection::async_write, could not format header"); - boost::system::error_code error(boost::asio::error::invalid_argument); - boost::asio::post(socket_.get_executor(), boost::bind(handler, error)); + boost::asio::post(socket_.get_executor(), [handler]() { handler(boost::asio::error::invalid_argument); }); return; } outbound_header_ = header_stream.str(); @@ -101,7 +97,10 @@ class connection { buffers.reserve(2); buffers.emplace_back(boost::asio::buffer(outbound_header_)); buffers.emplace_back(boost::asio::buffer(outbound_data_)); - boost::asio::async_write(socket_, buffers, handler); + boost::asio::async_write( + socket_, buffers, [handler](const boost::system::error_code& error, std::size_t bytes_transferred) { + handler(error); + }); #ifdef DEBUG_CONNECTION std::cout << " END\n"; @@ -119,22 +118,19 @@ class connection { std::cout << "CLIENT: Connection::async_read\n"; #endif - // Issue a read operation to read exactly the number of bytes in a header. - void (connection::*f)(const boost::system::error_code&, T&, boost::tuple) = - &connection::handle_read_header; - + // Issue a read operation to read exactly the number of bytes in a header boost::asio::async_read( socket_, boost::asio::buffer(inbound_header_), - boost::bind(f, this, boost::asio::placeholders::error, boost::ref(t), boost::make_tuple(handler))); + [this, &t, handler](const boost::system::error_code& error, std::size_t bytes_transferred) { + this->handle_read_header(error, t, handler); + }); } private: - /// Handle a completed read of a message header. The handler is passed using - /// a tuple since boost::bind seems to have trouble binding a function object - /// created using boost::bind as a parameter. + /// Handle a completed read of a message header. template - void handle_read_header(const boost::system::error_code& e, T& t, boost::tuple handler) { + void handle_read_header(const boost::system::error_code& e, T& t, Handler handler) { #ifdef DEBUG_CONNECTION if (Ecf::server()) std::cout << "SERVER: Connection::handle_read_header\n"; @@ -144,7 +140,7 @@ class connection { << "' # this size of payload in hex\n"; #endif if (e) { - boost::get<0>(handler)(e); + handler(e); } else { // Determine the length of the serialized data. @@ -156,25 +152,24 @@ class connection { std::string err = "Connection::handle_read_header: invalid header : " + std::string(inbound_header_, header_length); log_error(err.c_str()); - boost::system::error_code error(boost::asio::error::invalid_argument); - boost::get<0>(handler)(error); + handler(boost::asio::error::invalid_argument); return; } // Start an asynchronous call to receive the data. inbound_data_.resize(inbound_data_size); - void (connection::*f)(const boost::system::error_code&, T&, boost::tuple) = - &connection::handle_read_data; - - boost::asio::async_read(socket_, - boost::asio::buffer(inbound_data_), - boost::bind(f, this, boost::asio::placeholders::error, boost::ref(t), handler)); + boost::asio::async_read( + socket_, + boost::asio::buffer(inbound_data_), + [this, &t, handler](const boost::system::error_code& error, std::size_t bytes_transferred) { + this->handle_read_data(error, t, handler); + }); } } /// Handle a completed read of message data. template - void handle_read_data(const boost::system::error_code& e, T& t, boost::tuple handler) { + void handle_read_data(const boost::system::error_code& e, T& t, Handler handler) { #ifdef DEBUG_CONNECTION if (Ecf::server()) std::cout << "SERVER: Connection::handle_read_data\n"; @@ -183,7 +178,7 @@ class connection { #endif if (e) { - boost::get<0>(handler)(e); + handler(e); } else { // Extract the data structure from the data just received. @@ -198,13 +193,12 @@ class connection { } catch (std::exception& e) { log_archive_error("Connection::handle_read_data, Unable to decode data :", e, archive_data); - boost::system::error_code error(boost::asio::error::invalid_argument); - boost::get<0>(handler)(error); + handler(boost::asio::error::invalid_argument); return; } // Inform caller that data has been received ok. - boost::get<0>(handler)(e); + handler(e); } } diff --git a/Base/src/Openssl.cpp b/Base/src/Openssl.cpp index 59efbc0c7..9c338523c 100644 --- a/Base/src/Openssl.cpp +++ b/Base/src/Openssl.cpp @@ -12,19 +12,17 @@ // // Description : /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +#include "Openssl.hpp" + #include #include // getenv #include -// #include - -#include +#include #include "File.hpp" #include "Host.hpp" -#include "Openssl.hpp" #include "Str.hpp" -#include "boost/filesystem/operations.hpp" using namespace std; namespace fs = boost::filesystem; @@ -126,7 +124,10 @@ void Openssl::init_for_server() { ssl_context_->set_options(boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 | boost::asio::ssl::context::single_dh_use); // this must be done before loading any keys. as below - ssl_context_->set_password_callback(boost::bind(&Openssl::get_password, this)); + ssl_context_->set_password_callback( + [this](std::size_t size, boost::asio::ssl::context_base::password_purpose purpose) { + return this->get_password(); + }); ssl_context_->use_certificate_chain_file(crt()); ssl_context_->use_private_key_file(key(), boost::asio::ssl::context::pem); ssl_context_->use_tmp_dh_file(pem()); diff --git a/Base/src/SslClient.cpp b/Base/src/SslClient.cpp index 3190dd316..893ae4104 100644 --- a/Base/src/SslClient.cpp +++ b/Base/src/SslClient.cpp @@ -16,8 +16,6 @@ #include -#include - #include "ErrorCmd.hpp" #include "StcCmd.hpp" @@ -111,9 +109,10 @@ bool SslClient::start_connect(boost::asio::ip::tcp::resolver::iterator endpoint_ deadline_.expires_from_now(boost::posix_time::seconds(timeout_)); boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator; - connection_.socket_ll().async_connect( - endpoint, - boost::bind(&SslClient::handle_connect, this, boost::asio::placeholders::error, endpoint_iterator)); + connection_.socket_ll().async_connect(endpoint, + [this, endpoint_iterator](const boost::system::error_code& error) { + this->handle_connect(error, endpoint_iterator); + }); } else { // ran out of end points @@ -226,7 +225,7 @@ void SslClient::start_write() { deadline_.expires_from_now(boost::posix_time::seconds(timeout_)); connection_.async_write(outbound_request_, - boost::bind(&SslClient::handle_write, this, boost::asio::placeholders::error)); + [this](const boost::system::error_code& error) { this->handle_write(error); }); } void SslClient::handle_write(const boost::system::error_code& e) { @@ -270,7 +269,7 @@ void SslClient::start_read() { deadline_.expires_from_now(boost::posix_time::seconds(timeout_)); connection_.async_read(inbound_response_, - boost::bind(&SslClient::handle_read, this, boost::asio::placeholders::error)); + [this](const boost::system::error_code& error) { this->handle_write(error); }); } void SslClient::handle_read(const boost::system::error_code& e) { diff --git a/Base/src/ssl_connection.cpp b/Base/src/ssl_connection.cpp index 1be281d40..f62f640f9 100644 --- a/Base/src/ssl_connection.cpp +++ b/Base/src/ssl_connection.cpp @@ -42,7 +42,9 @@ ssl_connection::ssl_connection(boost::asio::io_service& io_service, boost::asio: // if (Ecf::server()) // socket_.set_verify_mode(boost::asio::ssl::verify_peer|boost::asio::ssl::verify_fail_if_no_peer_cert); else // socket_.set_verify_mode(boost::asio::ssl::verify_peer); - socket_.set_verify_callback(boost::bind(&ssl_connection::verify_certificate, this, _1, _2)); + socket_.set_verify_callback([this](bool preverified, boost::asio::ssl::verify_context& ctx) { + return this->verify_certificate(preverified, ctx); + }); } bool ssl_connection::verify_certificate(bool preverified, boost::asio::ssl::verify_context& ctx) { diff --git a/Base/src/ssl_connection.hpp b/Base/src/ssl_connection.hpp index 8b67efb37..315cb093d 100644 --- a/Base/src/ssl_connection.hpp +++ b/Base/src/ssl_connection.hpp @@ -26,8 +26,6 @@ #include #include -#include -#include #include "Serialization.hpp" @@ -77,7 +75,7 @@ class ssl_connection { // Unable to decode data. Something went wrong, inform the caller. log_archive_error("ssl_connection::async_write, exception ", ae, outbound_data_); boost::system::error_code error(boost::asio::error::invalid_argument); - boost::asio::post(socket_.get_executor(), boost::bind(handler, error)); + boost::asio::post(socket_.get_executor(), [handler, error]() { handler(error); }); return; } @@ -91,7 +89,7 @@ class ssl_connection { // Something went wrong, inform the caller. log_error("ssl_connection::async_write, could not format header"); boost::system::error_code error(boost::asio::error::invalid_argument); - boost::asio::post(socket_.get_executor(), boost::bind(handler, error)); + boost::asio::post(socket_.get_executor(), [handler, error]() { handler(error); }); return; } outbound_header_ = header_stream.str(); @@ -110,7 +108,10 @@ class ssl_connection { buffers.reserve(2); buffers.emplace_back(boost::asio::buffer(outbound_header_)); buffers.emplace_back(boost::asio::buffer(outbound_data_)); - boost::asio::async_write(socket_, buffers, handler); + boost::asio::async_write( + socket_, buffers, [handler](const boost::system::error_code& error, std::size_t bytes_transferred) { + handler(error); + }); #ifdef DEBUG_CONNECTION std::cout << " END\n"; @@ -129,21 +130,18 @@ class ssl_connection { #endif // Issue a read operation to read exactly the number of bytes in a header. - void (ssl_connection::*f)(const boost::system::error_code&, T&, boost::tuple) = - &ssl_connection::handle_read_header; - boost::asio::async_read( socket_, boost::asio::buffer(inbound_header_), - boost::bind(f, this, boost::asio::placeholders::error, boost::ref(t), boost::make_tuple(handler))); + [this, &t, handler](const boost::system::error_code& error, std::size_t bytes_transferred) { + this->handle_read_header(error, t, handler); + }); } private: - /// Handle a completed read of a message header. The handler is passed using - /// a tuple since boost::bind seems to have trouble binding a function object - /// created using boost::bind as a parameter. + /// Handle a completed read of a message header. template - void handle_read_header(const boost::system::error_code& e, T& t, boost::tuple handler) { + void handle_read_header(const boost::system::error_code& e, T& t, Handler handler) { #ifdef DEBUG_CONNECTION if (Ecf::server()) std::cout << "SERVER: ssl_onnection::handle_read_header\n"; @@ -153,7 +151,7 @@ class ssl_connection { << "' # this size of payload in hex\n"; #endif if (e) { - boost::get<0>(handler)(e); + handler(e); } else { // Determine the length of the serialized data. @@ -165,25 +163,24 @@ class ssl_connection { std::string err = "ssl_connection::handle_read_header: invalid header : " + std::string(inbound_header_, header_length); log_error(err.c_str()); - boost::system::error_code error(boost::asio::error::invalid_argument); - boost::get<0>(handler)(error); + handler(boost::asio::error::invalid_argument); return; } // Start an asynchronous call to receive the data. inbound_data_.resize(inbound_data_size); - void (ssl_connection::*f)(const boost::system::error_code&, T&, boost::tuple) = - &ssl_connection::handle_read_data; - - boost::asio::async_read(socket_, - boost::asio::buffer(inbound_data_), - boost::bind(f, this, boost::asio::placeholders::error, boost::ref(t), handler)); + boost::asio::async_read( + socket_, + boost::asio::buffer(inbound_data_), + [this, &t, handler](const boost::system::error_code& error, std::size_t bytes_transferred) { + this->handle_read_data(error, t, handler); + }); } } /// Handle a completed read of message data. template - void handle_read_data(const boost::system::error_code& e, T& t, boost::tuple handler) { + void handle_read_data(const boost::system::error_code& e, T& t, Handler handler) { #ifdef DEBUG_CONNECTION if (Ecf::server()) std::cout << "SERVER: ssl_connection::handle_read_data\n"; @@ -192,7 +189,7 @@ class ssl_connection { #endif if (e) { - boost::get<0>(handler)(e); + handler(e); } else { // Extract the data structure from the data just received. @@ -207,13 +204,12 @@ class ssl_connection { } catch (std::exception& e) { log_archive_error("ssl_connection::handle_read_data, Unable to decode data :", e, archive_data); - boost::system::error_code error(boost::asio::error::invalid_argument); - boost::get<0>(handler)(error); + handler(boost::asio::error::invalid_argument); return; } // Inform caller that data has been received ok. - boost::get<0>(handler)(e); + handler(e); } } diff --git a/Client/src/Rtt.hpp b/Client/src/Rtt.hpp index e23b4b1a0..5862fe4d4 100644 --- a/Client/src/Rtt.hpp +++ b/Client/src/Rtt.hpp @@ -16,10 +16,9 @@ // of all client based command /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 #include +#include #include -#include - namespace ecf { class Rtt { @@ -58,7 +57,7 @@ std::string stringize_rtt(Functor const& f) { f(out); return out.str(); } -#define STRINGIZE_RTT(EXPRESSION) (ecf::stringize_rtt(boost::lambda::_1 << EXPRESSION)) +#define STRINGIZE_RTT(EXPRESSION) (ecf::stringize_rtt([](std::ostringstream& os) { os << EXPRESSION };)) #define RTT(EXPRESSION) ecf::rtt(STRINGIZE_RTT(EXPRESSION)) } // namespace ecf #endif diff --git a/Server/src/ServerEnvironment.cpp b/Server/src/ServerEnvironment.cpp index d15785fb9..fb96d8dbe 100644 --- a/Server/src/ServerEnvironment.cpp +++ b/Server/src/ServerEnvironment.cpp @@ -19,7 +19,6 @@ #include // for getenv() #include -#include #include #include diff --git a/Server/src/SslTcpServer.cpp b/Server/src/SslTcpServer.cpp index 6064c2ea1..b44aaba16 100644 --- a/Server/src/SslTcpServer.cpp +++ b/Server/src/SslTcpServer.cpp @@ -15,8 +15,6 @@ #include -#include - #include "Log.hpp" #include "ServerEnvironment.hpp" #include "SslServer.hpp" @@ -61,7 +59,7 @@ void SslTcpServer::handle_accept(const boost::system::error_code& e, ssl_connect // Read and interpret message from the client conn->socket().async_handshake( boost::asio::ssl::stream_base::server, - boost::bind(&SslTcpServer::handle_handshake, this, boost::asio::placeholders::error, conn)); + [this, conn](const boost::system::error_code& error) { this->handle_handshake(error, conn); }); } else { if (serverEnv_.debug()) @@ -91,8 +89,9 @@ void SslTcpServer::handle_handshake(const boost::system::error_code& e, ssl_conn // Successfully accepted a new connection. Determine what the // client sent to us. The connection::async_read() function will // automatically. serialise the inbound_request_ data structure for us. - new_conn->async_read(inbound_request_, - boost::bind(&SslTcpServer::handle_read, this, boost::asio::placeholders::error, new_conn)); + new_conn->async_read(inbound_request_, [this, new_conn](const boost::system::error_code& error) { + this->handle_read(error, new_conn); + }); } else { // An error occurred. @@ -112,12 +111,12 @@ void SslTcpServer::handle_read(const boost::system::error_code& e, ssl_connectio // Always *Reply* back to the client, Otherwise client will get EOF conn->async_write(outbound_response_, - boost::bind(&SslTcpServer::handle_write, this, boost::asio::placeholders::error, conn)); + [this, conn](const boost::system::error_code& error) { this->handle_write(error, conn); }); } else { handle_read_error(e); // populates outbound_response_ conn->async_write(outbound_response_, - boost::bind(&SslTcpServer::handle_write, this, boost::asio::placeholders::error, conn)); + [this, conn](const boost::system::error_code& error) { this->handle_write(error, conn); }); } } diff --git a/Server/src/TcpServer.cpp b/Server/src/TcpServer.cpp index a0702e762..e0ea36816 100644 --- a/Server/src/TcpServer.cpp +++ b/Server/src/TcpServer.cpp @@ -15,8 +15,6 @@ #include -#include - #include "Log.hpp" #include "Server.hpp" #include "ServerEnvironment.hpp" @@ -59,7 +57,7 @@ void TcpServer::handle_accept(const boost::system::error_code& e, connection_ptr // client sent to us. The connection::async_read() function will // automatically. serialise the inbound_request_ data structure for us. conn->async_read(inbound_request_, - boost::bind(&TcpServer::handle_read, this, boost::asio::placeholders::error, conn)); + [this, conn](const boost::system::error_code& error) { this->handle_read(error, conn); }); } else { if (serverEnv_.debug()) @@ -99,12 +97,12 @@ void TcpServer::handle_read(const boost::system::error_code& e, connection_ptr c // Always *Reply* back to the client, Otherwise client will get EOF conn->async_write(outbound_response_, - boost::bind(&TcpServer::handle_write, this, boost::asio::placeholders::error, conn)); + [this, conn](const boost::system::error_code& error) { this->handle_write(error, conn); }); } else { handle_read_error(e); // populates outbound_response_ conn->async_write(outbound_response_, - boost::bind(&TcpServer::handle_write, this, boost::asio::placeholders::error, conn)); + [this, conn](const boost::system::error_code& error) { this->handle_write(error, conn); }); } }