replace boost.asio with standalone asio.

This commit is contained in:
Chunting Gu
2020-02-20 10:43:46 +08:00
parent b72db3a048
commit 718392fa9e
490 changed files with 110256 additions and 144 deletions
+24 -24
View File
@@ -12,9 +12,9 @@
#endif // defined(_WIN32) || defined(_WIN64)
#endif // WEBCC_ENABLE_SSL
#include "boost/asio/connect.hpp"
#include "boost/asio/read.hpp"
#include "boost/asio/write.hpp"
#include "asio/connect.hpp"
#include "asio/read.hpp"
#include "asio/write.hpp"
#include "webcc/logger.h"
@@ -22,12 +22,12 @@ namespace webcc {
// -----------------------------------------------------------------------------
Socket::Socket(boost::asio::io_context& io_context) : socket_(io_context) {
Socket::Socket(asio::io_context& io_context) : socket_(io_context) {
}
bool Socket::Connect(const std::string& /*host*/, const Endpoints& endpoints) {
boost::system::error_code ec;
boost::asio::connect(socket_, endpoints, ec);
std::error_code ec;
asio::connect(socket_, endpoints, ec);
if (ec) {
LOG_ERRO("Socket connect error (%s).", ec.message().c_str());
@@ -37,25 +37,25 @@ bool Socket::Connect(const std::string& /*host*/, const Endpoints& endpoints) {
return true;
}
bool Socket::Write(const Payload& payload, boost::system::error_code* ec) {
boost::asio::write(socket_, payload, *ec);
bool Socket::Write(const Payload& payload, std::error_code* ec) {
asio::write(socket_, payload, *ec);
return !(*ec);
}
bool Socket::ReadSome(std::vector<char>* buffer, std::size_t* size,
boost::system::error_code* ec) {
*size = socket_.read_some(boost::asio::buffer(*buffer), *ec);
std::error_code* ec) {
*size = socket_.read_some(asio::buffer(*buffer), *ec);
return (*size != 0 && !(*ec));
}
void Socket::AsyncReadSome(ReadHandler&& handler, std::vector<char>* buffer) {
socket_.async_read_some(boost::asio::buffer(*buffer), std::move(handler));
socket_.async_read_some(asio::buffer(*buffer), std::move(handler));
}
bool Socket::Close() {
boost::system::error_code ec;
std::error_code ec;
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
socket_.shutdown(asio::ip::tcp::socket::shutdown_both, ec);
if (ec) {
LOG_WARN("Socket shutdown error (%s).", ec.message().c_str());
@@ -125,9 +125,9 @@ static bool UseSystemCertificateStore(SSL_CTX* ssl_ctx) {
#endif // defined(_WIN32) || defined(_WIN64)
namespace ssl = boost::asio::ssl;
namespace ssl = asio::ssl;
SslSocket::SslSocket(boost::asio::io_context& io_context, bool ssl_verify)
SslSocket::SslSocket(asio::io_context& io_context, bool ssl_verify)
: ssl_context_(ssl::context::sslv23),
ssl_socket_(io_context, ssl_context_),
ssl_verify_(ssl_verify) {
@@ -142,8 +142,8 @@ SslSocket::SslSocket(boost::asio::io_context& io_context, bool ssl_verify)
}
bool SslSocket::Connect(const std::string& host, const Endpoints& endpoints) {
boost::system::error_code ec;
boost::asio::connect(ssl_socket_.lowest_layer(), endpoints, ec);
std::error_code ec;
asio::connect(ssl_socket_.lowest_layer(), endpoints, ec);
if (ec) {
LOG_ERRO("Socket connect error (%s).", ec.message().c_str());
@@ -153,24 +153,24 @@ bool SslSocket::Connect(const std::string& host, const Endpoints& endpoints) {
return Handshake(host);
}
bool SslSocket::Write(const Payload& payload, boost::system::error_code* ec) {
boost::asio::write(ssl_socket_, payload, *ec);
bool SslSocket::Write(const Payload& payload, std::error_code* ec) {
asio::write(ssl_socket_, payload, *ec);
return !(*ec);
}
bool SslSocket::ReadSome(std::vector<char>* buffer, std::size_t* size,
boost::system::error_code* ec) {
*size = ssl_socket_.read_some(boost::asio::buffer(*buffer), *ec);
std::error_code* ec) {
*size = ssl_socket_.read_some(asio::buffer(*buffer), *ec);
return (*size != 0 && !(*ec));
}
void SslSocket::AsyncReadSome(ReadHandler&& handler,
std::vector<char>* buffer) {
ssl_socket_.async_read_some(boost::asio::buffer(*buffer), std::move(handler));
ssl_socket_.async_read_some(asio::buffer(*buffer), std::move(handler));
}
bool SslSocket::Close() {
boost::system::error_code ec;
std::error_code ec;
ssl_socket_.lowest_layer().close(ec);
return !ec;
}
@@ -185,7 +185,7 @@ bool SslSocket::Handshake(const std::string& host) {
ssl_socket_.set_verify_callback(ssl::rfc2818_verification(host));
// Use sync API directly since we don't need timeout control.
boost::system::error_code ec;
std::error_code ec;
ssl_socket_.handshake(ssl::stream_base::client, ec);
if (ec) {