diff --git a/.travis.yml b/.travis.yml index 982b0b23..84d39ac6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,6 @@ arch: - cmake - gcc - clang - - boost script: - cd example diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index e1f1c595..3b704746 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -10,9 +10,6 @@ target_include_directories(${project_name} PRIVATE ${cinatra_SOURCE_DIR}/thirdparty/asio ) -if(LINUX) - target_link_libraries(${project_name} ${Boost_LIBRARIES} -lstdc++fs) -endif() if (ENABLE_SSL) target_link_libraries(${project_name} ${OPENSSL_LIBRARIES} pthread -ldl) endif() diff --git a/example/main.cpp b/example/main.cpp index 8ffd31ff..cb79f6a8 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -73,18 +73,18 @@ void test_sync_client() { #ifdef CINATRA_ENABLE_SSL response_data result2 = client->get(uri2); ////if you need to verify peer - // client->set_ssl_context_callback([](boost::asio::ssl::context& ctx) { - // ctx.set_verify_mode(boost::asio::ssl::context::verify_peer); + // client->set_ssl_context_callback([](asio::ssl::context& ctx) { + // ctx.set_verify_mode(asio::ssl::context::verify_peer); // ctx.load_verify_file("server.crt"); // //ctx.set_options( - // // boost::asio::ssl::context::default_workarounds - // // | boost::asio::ssl::context::no_sslv2 - // // | boost::asio::ssl::context::single_dh_use); + // // asio::ssl::context::default_workarounds + // // | asio::ssl::context::no_sslv2 + // // | asio::ssl::context::single_dh_use); // //ctx.use_certificate_chain_file("server.crt"); // //ctx.use_private_key_file("server.key", - // boost::asio::ssl::context::pem); + // asio::ssl::context::pem); // //ctx.use_tmp_dh_file("dh512.pem"); //}); @@ -191,7 +191,7 @@ void test_upload() { } void test_smtp_client() { - boost::asio::io_context io_context; + asio::io_context io_context; #ifdef CINATRA_ENABLE_SSL auto client = cinatra::smtp::get_smtp_client(io_context); #else @@ -216,7 +216,7 @@ void test_smtp_client() { client.start(); - boost::system::error_code ec; + std::error_code ec; io_context.run(ec); } diff --git a/include/cinatra/client_factory.hpp b/include/cinatra/client_factory.hpp index e89e9aab..c4626dff 100644 --- a/include/cinatra/client_factory.hpp +++ b/include/cinatra/client_factory.hpp @@ -32,8 +32,8 @@ class client_factory { client_factory(client_factory &&) = delete; client_factory &operator=(client_factory &&) = delete; - boost::asio::io_service ios_; - boost::asio::io_service::work work_; + asio::io_service ios_; + asio::io_service::work work_; std::shared_ptr thd_; }; diff --git a/include/cinatra/connection.hpp b/include/cinatra/connection.hpp index 866315d6..fabbfd52 100644 --- a/include/cinatra/connection.hpp +++ b/include/cinatra/connection.hpp @@ -14,7 +14,7 @@ namespace cinatra { using http_handler = std::function; using send_ok_handler = std::function; using send_failed_handler = - std::function; + std::function; class base_connection { public: @@ -32,7 +32,7 @@ class connection : public base_connection, private noncopyable { public: explicit connection( - boost::asio::io_service &io_service, ssl_configure ssl_conf, + asio::io_service &io_service, ssl_configure ssl_conf, std::size_t max_req_size, long keep_alive_timeout, http_handler &handler, std::string &static_dir, std::function *upload_check) @@ -49,11 +49,11 @@ class connection : public base_connection, void init_ssl_context(ssl_configure ssl_conf) { #ifdef CINATRA_ENABLE_SSL - unsigned long ssl_options = boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::no_sslv2 | - boost::asio::ssl::context::single_dh_use; + unsigned long ssl_options = asio::ssl::context::default_workarounds | + asio::ssl::context::no_sslv2 | + asio::ssl::context::single_dh_use; try { - boost::asio::ssl::context ssl_context(boost::asio::ssl::context::sslv23); + asio::ssl::context ssl_context(asio::ssl::context::sslv23); ssl_context.set_options(ssl_options); ssl_context.set_password_callback([](auto, auto) { return "123456"; }); @@ -64,11 +64,11 @@ class connection : public base_connection, if (fs::exists(ssl_conf.key_file, ec)) ssl_context.use_private_key_file(std::move(ssl_conf.key_file), - boost::asio::ssl::context::pem); + asio::ssl::context::pem); // ssl_context_callback(ssl_context); ssl_stream_ = std::make_unique< - boost::asio::ssl::stream>( + asio::ssl::stream>( socket_, ssl_context); } catch (const std::exception &e) { std::cout << e.what() << "\n"; @@ -99,7 +99,7 @@ class connection : public base_connection, } std::stringstream ss; - boost::system::error_code ec; + std::error_code ec; ss << socket_.local_endpoint(ec); if (ec) { return ""; @@ -113,7 +113,7 @@ class connection : public base_connection, } std::stringstream ss; - boost::system::error_code ec; + std::error_code ec; ss << socket_.remote_endpoint(ec); if (ec) { return ""; @@ -158,7 +158,7 @@ class connection : public base_connection, timer_.expires_from_now(std::chrono::seconds(KEEP_ALIVE_TIMEOUT_)); auto self = this->shared_from_this(); - timer_.async_wait([self](boost::system::error_code const &ec) { + timer_.async_wait([self](std::error_code const &ec) { if (ec) { return; } @@ -171,7 +171,7 @@ class connection : public base_connection, if (!enable_timeout_) return; - boost::system::error_code ec; + std::error_code ec; timer_.cancel(ec); } @@ -215,9 +215,9 @@ class connection : public base_connection, chunked_header_ = http_range_chunk_header + "Content-Type: " + std::string(mime.data(), mime.length()) + "\r\n\r\n"; } - boost::asio::async_write( - socket(), boost::asio::buffer(chunked_header_), - [self = this->shared_from_this()](const boost::system::error_code &ec, + asio::async_write( + socket(), asio::buffer(chunked_header_), + [self = this->shared_from_this()](const std::error_code &ec, std::size_t) { self->handle_chunked_header(ec); }); @@ -226,26 +226,26 @@ class connection : public base_connection, void write_ranges_header(std::string header_str) { reset_timer(); chunked_header_ = std::move(header_str); // reuse the variable - boost::asio::async_write(socket(), boost::asio::buffer(chunked_header_), + asio::async_write(socket(), asio::buffer(chunked_header_), [this, self = this->shared_from_this()]( - const boost::system::error_code &ec, + const std::error_code &ec, std::size_t) { handle_chunked_header(ec); }); } void write_chunked_data(std::string &&buf, bool eof) { reset_timer(); - std::vector buffers = + std::vector buffers = res_.to_chunked_buffers(buf.data(), buf.length(), eof); if (buffers.empty()) { - handle_write(boost::system::error_code{}); + handle_write(std::error_code{}); return; } auto self = this->shared_from_this(); - boost::asio::async_write(socket(), buffers, + asio::async_write(socket(), buffers, [this, self, buf = std::move(buf), eof]( - const boost::system::error_code &ec, size_t) { + const std::error_code &ec, size_t) { if (ec) { return; } @@ -268,9 +268,9 @@ class connection : public base_connection, chunked_header_ = std::move(buf); // reuse the variable auto self = this->shared_from_this(); - boost::asio::async_write( - socket(), boost::asio::buffer(chunked_header_), - [this, self, eof](const boost::system::error_code &ec, size_t) { + asio::async_write( + socket(), asio::buffer(chunked_header_), + [this, self, eof](const std::error_code &ec, size_t) { if (ec) { return; } @@ -326,9 +326,9 @@ class connection : public base_connection, void async_handshake() { #ifdef CINATRA_ENABLE_SSL - ssl_stream_->async_handshake(boost::asio::ssl::stream_base::server, + ssl_stream_->async_handshake(asio::ssl::stream_base::server, [this, self = this->shared_from_this()]( - const boost::system::error_code &error) { + const std::error_code &error) { if (error) { std::cout << error.message() << std::endl; return; @@ -353,9 +353,9 @@ class connection : public base_connection, #endif socket().async_read_some( - boost::asio::buffer(req_.buffer(), req_.left_size()), + asio::buffer(req_.buffer(), req_.left_size()), [this, self = this->shared_from_this()]( - const boost::system::error_code &e, std::size_t bytes_transferred) { + const std::error_code &e, std::size_t bytes_transferred) { if (e) { close(); has_shake_ = false; @@ -366,7 +366,7 @@ class connection : public base_connection, }); } - void handle_read(const boost::system::error_code &e, + void handle_read(const std::error_code &e, std::size_t bytes_transferred) { if (e) { close(); @@ -446,14 +446,14 @@ class connection : public base_connection, auto resp_vec = http_cache::get().get(std::string(raw_url.data(), raw_url.length())); if (!resp_vec.empty()) { - std::vector buffers; + std::vector buffers; for (auto &iter : resp_vec) { - buffers.emplace_back(boost::asio::buffer(iter.data(), iter.size())); + buffers.emplace_back(asio::buffer(iter.data(), iter.size())); } - boost::asio::async_write( + asio::async_write( socket(), buffers, [self = this->shared_from_this(), resp_vec = std::move(resp_vec)]( - const boost::system::error_code &ec, std::size_t) { + const std::error_code &ec, std::size_t) { self->handle_write(ec); }); } @@ -516,11 +516,11 @@ class connection : public base_connection, } res_.set_delay(false); - boost::asio::async_write( - socket(), boost::asio::buffer(rep_str.data(), rep_str.size()), + asio::async_write( + socket(), asio::buffer(rep_str.data(), rep_str.size()), [head_not_complete, body_not_complete, left_body_len, this, self = this->shared_from_this(), - &rep_str](const boost::system::error_code &ec, std::size_t) { + &rep_str](const std::error_code &ec, std::size_t) { rep_str.clear(); if (head_not_complete) { do_read_head(); @@ -541,9 +541,9 @@ class connection : public base_connection, reset_timer(); socket().async_read_some( - boost::asio::buffer(req_.buffer(), req_.left_size()), + asio::buffer(req_.buffer(), req_.left_size()), [this, self = this->shared_from_this()]( - const boost::system::error_code &e, std::size_t bytes_transferred) { + const std::error_code &e, std::size_t bytes_transferred) { handle_read(e, bytes_transferred); }); } @@ -552,9 +552,9 @@ class connection : public base_connection, reset_timer(); auto self = this->shared_from_this(); - boost::asio::async_read( - socket(), boost::asio::buffer(req_.buffer(), req_.left_body_len()), - [this, self](const boost::system::error_code &ec, + asio::async_read( + socket(), asio::buffer(req_.buffer(), req_.left_body_len()), + [this, self](const std::error_code &ec, size_t bytes_transferred) { if (ec) { // LOG_WARN << ec.message(); @@ -578,7 +578,7 @@ class connection : public base_connection, std::string &rep_str = res_.response_str(); if (rep_str.empty()) { - handle_write(boost::system::error_code{}); + handle_write(std::error_code{}); return; } @@ -592,14 +592,14 @@ class connection : public base_connection, // res_.raw_content()); // } - boost::asio::async_write( - socket(), boost::asio::buffer(rep_str.data(), rep_str.size()), + asio::async_write( + socket(), asio::buffer(rep_str.data(), rep_str.size()), [this, - self = this->shared_from_this()](const boost::system::error_code &ec, + self = this->shared_from_this()](const std::error_code &ec, std::size_t) { handle_write(ec); }); } - void handle_write(const boost::system::error_code &ec) { + void handle_write(const std::error_code &ec) { if (ec) { return; } @@ -647,7 +647,7 @@ class connection : public base_connection, void close(bool close_ssl = true) { #ifdef CINATRA_ENABLE_SSL if (close_ssl && ssl_stream_) { - boost::system::error_code ec; + std::error_code ec; ssl_stream_->shutdown(ec); ssl_stream_ = nullptr; } @@ -659,7 +659,7 @@ class connection : public base_connection, req_.close_upload_file(); shutdown(); - boost::system::error_code ec; + std::error_code ec; socket_.close(ec); has_closed_ = true; has_shake_ = false; @@ -726,9 +726,9 @@ class connection : public base_connection, void do_read_octet_stream_body() { auto self = this->shared_from_this(); - boost::asio::async_read( - socket(), boost::asio::buffer(req_.buffer(), req_.left_body_len()), - [this, self](const boost::system::error_code &ec, + asio::async_read( + socket(), asio::buffer(req_.buffer(), req_.left_body_len()), + [this, self](const std::error_code &ec, size_t bytes_transferred) { if (ec) { req_.set_state(data_proc_state::data_error); @@ -796,9 +796,9 @@ class connection : public base_connection, reset_timer(); auto self = this->shared_from_this(); - boost::asio::async_read( - socket(), boost::asio::buffer(req_.buffer(), req_.left_body_len()), - [this, self](const boost::system::error_code &ec, + asio::async_read( + socket(), asio::buffer(req_.buffer(), req_.left_body_len()), + [this, self](const std::error_code &ec, size_t bytes_transferred) { if (ec) { // LOG_WARN << ec.message(); @@ -953,9 +953,9 @@ class connection : public base_connection, req_.fit_size(); auto self = this->shared_from_this(); - boost::asio::async_read( - socket(), boost::asio::buffer(req_.buffer(), req_.left_body_len()), - [self, this](boost::system::error_code ec, std::size_t length) { + asio::async_read( + socket(), asio::buffer(req_.buffer(), req_.left_body_len()), + [self, this](std::error_code ec, std::size_t length) { if (ec) { req_.set_state(data_proc_state::data_error); call_back(); @@ -985,9 +985,9 @@ class connection : public base_connection, void do_read_part_data() { auto self = this->shared_from_this(); - boost::asio::async_read( - socket(), boost::asio::buffer(req_.buffer(), req_.left_body_size()), - [self, this](boost::system::error_code ec, std::size_t length) { + asio::async_read( + socket(), asio::buffer(req_.buffer(), req_.left_body_size()), + [self, this](std::error_code ec, std::size_t length) { if (ec) { req_.set_state(data_proc_state::data_error); call_back(); @@ -1043,16 +1043,16 @@ class connection : public base_connection, //-------------web socket----------------// void response_handshake() { - std::vector buffers = res_.to_buffers(); + std::vector buffers = res_.to_buffers(); if (buffers.empty()) { close(false); return; } auto self = this->shared_from_this(); - boost::asio::async_write( + asio::async_write( socket(), buffers, - [this, self](const boost::system::error_code &ec, std::size_t) { + [this, self](const std::error_code &ec, std::size_t) { if (ec) { close(false); return; @@ -1069,9 +1069,9 @@ class connection : public base_connection, void do_read_websocket_head(size_t length) { auto self = this->shared_from_this(); - boost::asio::async_read( - socket(), boost::asio::buffer(req_.buffer(), length), - [this, self](const boost::system::error_code &ec, + asio::async_read( + socket(), asio::buffer(req_.buffer(), length), + [this, self](const std::error_code &ec, size_t bytes_transferred) { if (ec) { cancel_timer(); @@ -1110,9 +1110,9 @@ class connection : public base_connection, void do_read_websocket_data(size_t length) { auto self = this->shared_from_this(); - boost::asio::async_read( - socket(), boost::asio::buffer(req_.buffer(), length), - [this, self](const boost::system::error_code &ec, + asio::async_read( + socket(), asio::buffer(req_.buffer(), length), + [this, self](const std::error_code &ec, size_t bytes_transferred) { if (ec) { req_.call_event(data_proc_state::data_error); @@ -1199,7 +1199,7 @@ class connection : public base_connection, void ws_ping() { timer_.expires_from_now(std::chrono::seconds(60)); timer_.async_wait( - [self = this->shared_from_this()](boost::system::error_code const &ec) { + [self = this->shared_from_this()](std::error_code const &ec) { if (ec) { self->close(false); return; @@ -1220,7 +1220,7 @@ class connection : public base_connection, } } - void handle_chunked_header(const boost::system::error_code &ec) { + void handle_chunked_header(const std::error_code &ec) { if (ec) { return; } @@ -1307,13 +1307,13 @@ class connection : public base_connection, } void shutdown_send() { - boost::system::error_code ignored_ec; - socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ignored_ec); + std::error_code ignored_ec; + socket_.shutdown(asio::ip::tcp::socket::shutdown_send, ignored_ec); } void shutdown() { - boost::system::error_code ignored_ec; - socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec); + std::error_code ignored_ec; + socket_.shutdown(asio::ip::tcp::socket::shutdown_both, ignored_ec); } //-----------------send message----------------// @@ -1337,13 +1337,13 @@ class connection : public base_connection, void do_write_msg() { active_buffer_ ^= 1; // switch buffers for (const auto &data : buffers_[active_buffer_]) { - buffer_seq_.push_back(boost::asio::buffer(data)); + buffer_seq_.push_back(asio::buffer(data)); } - boost::asio::async_write( + asio::async_write( socket(), buffer_seq_, [this, self = this->shared_from_this()]( - const boost::system::error_code &ec, size_t) { + const std::error_code &ec, size_t) { std::lock_guard lock(buffers_mtx_); buffers_[active_buffer_].clear(); buffer_seq_.clear(); @@ -1373,12 +1373,12 @@ class connection : public base_connection, static constexpr bool is_ssl_ = std::is_same_v; //-----------------send message----------------// - boost::asio::ip::tcp::socket socket_; + asio::ip::tcp::socket socket_; #ifdef CINATRA_ENABLE_SSL - std::unique_ptr> + std::unique_ptr> ssl_stream_ = nullptr; #endif - boost::asio::steady_timer timer_; + asio::steady_timer timer_; bool enable_timeout_ = true; response res_; request req_; @@ -1394,10 +1394,10 @@ class connection : public base_connection, // for writing message std::mutex buffers_mtx_; std::vector buffers_[2]; // a double buffer - std::vector buffer_seq_; + std::vector buffer_seq_; int active_buffer_ = 0; std::function send_ok_cb_ = nullptr; - std::function send_failed_cb_ = + std::function send_failed_cb_ = nullptr; std::string last_ws_str_; diff --git a/include/cinatra/define.h b/include/cinatra/define.h index f76ef16c..d82fa8cc 100644 --- a/include/cinatra/define.h +++ b/include/cinatra/define.h @@ -1,16 +1,6 @@ #pragma once -#if defined(__GNUC__) -#if __GNUC__ < 8 -#include -namespace fs = std::experimental::filesystem; -#else #include namespace fs = std::filesystem; -#endif -#else -#include -namespace fs = std::filesystem; -#endif namespace cinatra { enum class content_type { diff --git a/include/cinatra/http_client.hpp b/include/cinatra/http_client.hpp index 52b51ff2..068144c8 100644 --- a/include/cinatra/http_client.hpp +++ b/include/cinatra/http_client.hpp @@ -17,14 +17,12 @@ #ifdef CINATRA_ENABLE_SSL #ifdef ASIO_STANDALONE #include -#else -#include #endif #endif namespace cinatra { struct response_data { - boost::system::error_code ec; + std::error_code ec; int status; std::string_view resp_body; std::pair resp_headers; @@ -44,7 +42,7 @@ inline static std::string READ_TIMEOUT = "read timeout"; class http_client : public std::enable_shared_from_this { public: - http_client(boost::asio::io_service &ios) + http_client(asio::io_service &ios) : ios_(ios), resolver_(ios), socket_(ios), timer_(ios) { future_ = read_close_finished_.get_future(); } @@ -65,10 +63,10 @@ class http_client : public std::enable_shared_from_this { return; ios_.post([this] { - boost::system::error_code ec; + std::error_code ec; has_connected_ = false; timer_.cancel(ec); - socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); + socket_.shutdown(asio::ip::tcp::socket::shutdown_both, ec); socket_.close(ec); has_closed_ = true; }); @@ -139,8 +137,8 @@ class http_client : public std::enable_shared_from_this { in_progress_ = false; if (status == std::future_status::timeout) { promise_ = nullptr; - return {boost::asio::error::make_error_code( - boost::asio::error::basic_errors::invalid_argument), + return {asio::error::make_error_code( + asio::error::basic_errors::invalid_argument), 404, REQUEST_TIMEOUT}; } auto result = future.get(); @@ -302,7 +300,7 @@ class http_client : public std::enable_shared_from_this { } if (in_progress_) { - set_error_value(cb, boost::asio::error::basic_errors::in_progress, + set_error_value(cb, asio::error::basic_errors::in_progress, MULTIPLE_REQUEST); return; } else { @@ -310,7 +308,7 @@ class http_client : public std::enable_shared_from_this { } if (method != http_method::POST && !body.empty()) { - set_error_value(cb, boost::asio::error::basic_errors::invalid_argument, + set_error_value(cb, asio::error::basic_errors::invalid_argument, METHOD_ERROR); return; } @@ -332,7 +330,7 @@ class http_client : public std::enable_shared_from_this { auto [r, u] = get_uri(uri); if (!r) { - set_error_value(cb, boost::asio::error::basic_errors::invalid_argument, + set_error_value(cb, asio::error::basic_errors::invalid_argument, INVALID_URI); return; } @@ -376,8 +374,8 @@ class http_client : public std::enable_shared_from_this { fs::create_directories(parant_path, code); if (code) { cb_ = std::move(cb); - callback(boost::asio::error::make_error_code( - boost::asio::error::basic_errors::invalid_argument), + callback(asio::error::make_error_code( + asio::error::basic_errors::invalid_argument), INVALID_FILE_PATH); return; } @@ -399,8 +397,8 @@ class http_client : public std::enable_shared_from_this { dest_file, std::ios::binary | std::ios::app); if (!download_file_->is_open()) { cb_ = std::move(cb); - callback(boost::asio::error::make_error_code( - boost::asio::error::basic_errors::invalid_argument), + callback(asio::error::make_error_code( + asio::error::basic_errors::invalid_argument), OPEN_FAILED); return; } @@ -424,7 +422,7 @@ class http_client : public std::enable_shared_from_this { void download( std::string src_file, - std::function chunk, + std::function chunk, size_t seconds = 60) { on_chunk_ = std::move(chunk); async_get(std::move(src_file), nullptr, req_content_type::none, seconds); @@ -502,23 +500,23 @@ class http_client : public std::enable_shared_from_this { #ifdef CINATRA_ENABLE_SSL void set_ssl_context_callback( - std::function ssl_context_callback) { + std::function ssl_context_callback) { ssl_context_callback_ = std::move(ssl_context_callback); } #endif private: - void callback(const boost::system::error_code &ec) { callback(ec, 404, ""); } + void callback(const std::error_code &ec) { callback(ec, 404, ""); } - void callback(const boost::system::error_code &ec, std::string error_msg) { + void callback(const std::error_code &ec, std::string error_msg) { callback(ec, 404, std::move(error_msg)); } - void callback(const boost::system::error_code &ec, int status) { + void callback(const std::error_code &ec, int status) { callback(ec, status, ""); } - void callback(const boost::system::error_code &ec, int status, + void callback(const std::error_code &ec, int status, std::string_view result) { if (auto sp = weak_.lock(); sp) { sp->set_value({ec, status, result, get_resp_headers()}); @@ -565,21 +563,21 @@ class http_client : public std::enable_shared_from_this { void async_connect(context ctx) { reset_timer(); - boost::asio::ip::tcp::resolver::query query(ctx.host, ctx.port); + asio::ip::tcp::resolver::query query(ctx.host, ctx.port); resolver_.async_resolve( query, [this, self = this->shared_from_this(), ctx = std::move(ctx)]( - boost::system::error_code ec, - const boost::asio::ip::tcp::resolver::iterator &it) { + std::error_code ec, + const asio::ip::tcp::resolver::iterator &it) { if (ec) { callback(ec); return; } - boost::asio::async_connect( + asio::async_connect( socket_, it, [this, self = shared_from_this(), ctx = std::move(ctx)]( - boost::system::error_code ec, - const boost::asio::ip::tcp::resolver::iterator &) { + std::error_code ec, + const asio::ip::tcp::resolver::iterator &) { cancel_timer(); if (!ec) { has_connected_ = true; @@ -598,8 +596,8 @@ class http_client : public std::enable_shared_from_this { } void do_read_write(const context &ctx) { - boost::system::error_code error_ignored; - socket_.set_option(boost::asio::ip::tcp::no_delay(true), error_ignored); + std::error_code error_ignored; + socket_.set_option(asio::ip::tcp::no_delay(true), error_ignored); do_read(); do_write(ctx); } @@ -616,7 +614,7 @@ class http_client : public std::enable_shared_from_this { write_msg_ = build_write_msg(ctx); async_write(write_msg_, [this, self = shared_from_this()]( - const boost::system::error_code &ec, const size_t) { + const std::error_code &ec, const size_t) { if (ec) { callback(ec); close(); @@ -629,8 +627,8 @@ class http_client : public std::enable_shared_from_this { auto filename = std::move(multipart_str_); auto file = std::make_shared(filename, std::ios::binary); if (!file) { - callback(boost::asio::error::make_error_code( - boost::asio::error::basic_errors::invalid_argument), + callback(asio::error::make_error_code( + asio::error::basic_errors::invalid_argument), INVALID_FILE_PATH); return; } @@ -639,8 +637,8 @@ class http_client : public std::enable_shared_from_this { size_t size = fs::file_size(filename, ec); if (ec || start_ == -1) { file->close(); - callback(boost::asio::error::make_error_code( - boost::asio::error::basic_errors::invalid_argument), + callback(asio::error::make_error_code( + asio::error::basic_errors::invalid_argument), FILE_SIZE_ERROR); return; } @@ -664,9 +662,9 @@ class http_client : public std::enable_shared_from_this { void handshake(context ctx) { #ifdef CINATRA_ENABLE_SSL auto self = this->shared_from_this(); - ssl_stream_->async_handshake(boost::asio::ssl::stream_base::client, + ssl_stream_->async_handshake(asio::ssl::stream_base::client, [this, self, ctx = std::move(ctx)]( - const boost::system::error_code &ec) { + const std::error_code &ec) { if (!ec) { do_read_write(ctx); } else { @@ -762,13 +760,13 @@ class http_client : public std::enable_shared_from_this { if (!ec) { // parse header const char *data_ptr = - boost::asio::buffer_cast(read_buf_.data()); + asio::buffer_cast(read_buf_.data()); size_t buf_size = read_buf_.size(); int ret = parser_.parse_response(data_ptr, size, 0); read_buf_.consume(size); if (ret < 0) { - callback(boost::asio::error::make_error_code( - boost::asio::error::basic_errors::invalid_argument), + callback(asio::error::make_error_code( + asio::error::basic_errors::invalid_argument), 404, RESP_PARSE_ERROR); if (buf_size > size) { read_buf_.consume(buf_size - size); @@ -830,7 +828,7 @@ class http_client : public std::enable_shared_from_this { if (!ec) { size_t data_size = read_buf_.size(); const char *data_ptr = - boost::asio::buffer_cast(read_buf_.data()); + asio::buffer_cast(read_buf_.data()); callback(ec, status, {data_ptr, data_size}); @@ -860,13 +858,13 @@ class http_client : public std::enable_shared_from_this { /// simplify size_t additional_size = buf_size - size; const char *data_ptr = - boost::asio::buffer_cast(read_buf_.data()); + asio::buffer_cast(read_buf_.data()); std::string_view size_str(data_ptr, size - CRCF.size()); auto chunk_size = hex_to_int(size_str); read_buf_.consume(size); if (chunk_size < 0) { - callback(boost::asio::error::make_error_code( - boost::asio::error::basic_errors::invalid_argument), + callback(asio::error::make_error_code( + asio::error::basic_errors::invalid_argument), 404, INVALID_CHUNK_SIZE); read_or_close(keep_alive); return; @@ -890,7 +888,7 @@ class http_client : public std::enable_shared_from_this { void read_chunk(bool keep_alive, size_t length) { if (length > 0) { const char *data = - boost::asio::buffer_cast(read_buf_.data()); + asio::buffer_cast(read_buf_.data()); append_chunk(std::string_view(data, length)); read_buf_.consume(length + CRCF.size()); read_chunk_head(keep_alive); @@ -941,13 +939,13 @@ class http_client : public std::enable_shared_from_this { void async_read(size_t size_to_read, Handler handler) { if (is_ssl()) { #ifdef CINATRA_ENABLE_SSL - boost::asio::async_read(*ssl_stream_, read_buf_, - boost::asio::transfer_exactly(size_to_read), + asio::async_read(*ssl_stream_, read_buf_, + asio::transfer_exactly(size_to_read), std::move(handler)); #endif } else { - boost::asio::async_read(socket_, read_buf_, - boost::asio::transfer_exactly(size_to_read), + asio::async_read(socket_, read_buf_, + asio::transfer_exactly(size_to_read), std::move(handler)); } } @@ -956,11 +954,11 @@ class http_client : public std::enable_shared_from_this { void async_read_until(const std::string &delim, Handler handler) { if (is_ssl()) { #ifdef CINATRA_ENABLE_SSL - boost::asio::async_read_until(*ssl_stream_, read_buf_, delim, + asio::async_read_until(*ssl_stream_, read_buf_, delim, std::move(handler)); #endif } else { - boost::asio::async_read_until(socket_, read_buf_, delim, + asio::async_read_until(socket_, read_buf_, delim, std::move(handler)); } } @@ -969,11 +967,11 @@ class http_client : public std::enable_shared_from_this { void async_write(const std::string &msg, Handler handler) { if (is_ssl()) { #ifdef CINATRA_ENABLE_SSL - boost::asio::async_write(*ssl_stream_, boost::asio::buffer(msg), + asio::async_write(*ssl_stream_, asio::buffer(msg), std::move(handler)); #endif } else { - boost::asio::async_write(socket_, boost::asio::buffer(msg), + asio::async_write(socket_, asio::buffer(msg), std::move(handler)); } } @@ -985,7 +983,7 @@ class http_client : public std::enable_shared_from_this { auto self(this->shared_from_this()); timer_.expires_from_now(std::chrono::seconds(timeout_seconds_)); - timer_.async_wait([this, self](const boost::system::error_code &ec) { + timer_.async_wait([this, self](const std::error_code &ec) { if (ec || sync_) { return; } @@ -1022,15 +1020,15 @@ class http_client : public std::enable_shared_from_this { if (ssl_stream_) return; - boost::asio::ssl::context ssl_context(boost::asio::ssl::context::sslv23); + asio::ssl::context ssl_context(asio::ssl::context::sslv23); ssl_context.set_default_verify_paths(); - boost::system::error_code ec; - ssl_context.set_options(boost::asio::ssl::context::default_workarounds, ec); + std::error_code ec; + ssl_context.set_options(asio::ssl::context::default_workarounds, ec); if (ssl_context_callback_) { ssl_context_callback_(ssl_context); } ssl_stream_ = std::make_unique< - boost::asio::ssl::stream>(socket_, + asio::ssl::stream>(socket_, ssl_context); // verify peer TODO } @@ -1045,7 +1043,7 @@ class http_client : public std::enable_shared_from_this { auto self = this->shared_from_this(); async_write(multipart_str_, [this, self, file = std::move(file)]( - boost::system::error_code ec, std::size_t) mutable { + std::error_code ec, std::size_t) mutable { if (!ec) { multipart_str_.clear(); send_file_data(std::move(file)); @@ -1111,25 +1109,25 @@ class http_client : public std::enable_shared_from_this { } void reset_socket() { - boost::system::error_code igored_ec; + std::error_code igored_ec; socket_ = decltype(socket_)(ios_); if (!socket_.is_open()) { - socket_.open(boost::asio::ip::tcp::v4(), igored_ec); + socket_.open(asio::ip::tcp::v4(), igored_ec); } } void set_error_value(const callback_t &cb, - const boost::asio::error::basic_errors &, + const asio::error::basic_errors &, const std::string &error_msg) { if (promise_) { promise_->set_value( - {boost::asio::error::make_error_code( - boost::asio::error::basic_errors::invalid_argument), + {asio::error::make_error_code( + asio::error::basic_errors::invalid_argument), 404, error_msg}); } if (cb) { - cb({boost::asio::error::make_error_code( - boost::asio::error::basic_errors::invalid_argument), + cb({asio::error::make_error_code( + asio::error::basic_errors::invalid_argument), 404, error_msg}); } read_close_finished_ = {}; @@ -1141,17 +1139,17 @@ class http_client : public std::enable_shared_from_this { callback_t cb_; std::atomic_bool in_progress_ = false; - boost::asio::io_service &ios_; - boost::asio::ip::tcp::resolver resolver_; - boost::asio::ip::tcp::socket socket_; + asio::io_service &ios_; + asio::ip::tcp::resolver resolver_; + asio::ip::tcp::socket socket_; #ifdef CINATRA_ENABLE_SSL - std::unique_ptr> + std::unique_ptr> ssl_stream_; - std::function ssl_context_callback_; + std::function ssl_context_callback_; #endif - boost::asio::steady_timer timer_; + asio::steady_timer timer_; std::size_t timeout_seconds_ = 60; - boost::asio::streambuf read_buf_; + asio::streambuf read_buf_; http_parser parser_; std::vector> copy_headers_; @@ -1163,7 +1161,7 @@ class http_client : public std::enable_shared_from_this { std::string chunked_result_; std::shared_ptr download_file_ = nullptr; - std::function on_chunk_ = + std::function on_chunk_ = nullptr; std::string multipart_str_; diff --git a/include/cinatra/http_server.hpp b/include/cinatra/http_server.hpp index b7cbe366..08132dc9 100644 --- a/include/cinatra/http_server.hpp +++ b/include/cinatra/http_server.hpp @@ -38,16 +38,16 @@ class http_server_ : private noncopyable { void set_ssl_conf(ssl_configure conf) { ssl_conf_ = std::move(conf); } bool port_in_use(unsigned short port) { - using namespace boost::asio; + using namespace asio; using ip::tcp; io_service svc; tcp::acceptor acept(svc); - boost::system::error_code ec; + std::error_code ec; acept.open(tcp::v4(), ec); #ifndef _WIN32 - acept.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true), ec); + acept.set_option(asio::ip::tcp::acceptor::reuse_address(true), ec); #endif acept.bind({tcp::v4(), port}, ec); @@ -63,7 +63,7 @@ class http_server_ : private noncopyable { return false; } - boost::asio::ip::tcp::resolver::query query(address.data(), port.data()); + asio::ip::tcp::resolver::query query(address.data(), port.data()); auto [r, err_msg] = listen(query); return r; } @@ -75,7 +75,7 @@ class http_server_ : private noncopyable { return false; } - boost::asio::ip::tcp::resolver::query query(address.data(), port.data()); + asio::ip::tcp::resolver::query query(address.data(), port.data()); auto [r, err_msg] = listen(query); error_msg = std::move(err_msg); return r; @@ -87,27 +87,27 @@ class http_server_ : private noncopyable { return false; } - boost::asio::ip::tcp::resolver::query query(port.data()); + asio::ip::tcp::resolver::query query(port.data()); auto [r, err_msg] = listen(query); return r; } std::pair - listen(const boost::asio::ip::tcp::resolver::query &query) { - boost::asio::ip::tcp::resolver resolver(io_service_pool_.get_io_service()); - boost::asio::ip::tcp::resolver::iterator endpoints = + listen(const asio::ip::tcp::resolver::query &query) { + asio::ip::tcp::resolver resolver(io_service_pool_.get_io_service()); + asio::ip::tcp::resolver::iterator endpoints = resolver.resolve(query); bool r = false; std::string err_msg; - for (; endpoints != boost::asio::ip::tcp::resolver::iterator(); + for (; endpoints != asio::ip::tcp::resolver::iterator(); ++endpoints) { - boost::asio::ip::tcp::endpoint endpoint = *endpoints; + asio::ip::tcp::endpoint endpoint = *endpoints; - auto acceptor = std::make_shared( + auto acceptor = std::make_shared( io_service_pool_.get_io_service()); acceptor->open(endpoint.protocol()); - acceptor->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); + acceptor->set_option(asio::ip::tcp::acceptor::reuse_address(true)); try { acceptor->bind(endpoint); @@ -247,7 +247,7 @@ class http_server_ : private noncopyable { private: void start_accept( - std::shared_ptr const &acceptor) { + std::shared_ptr const &acceptor) { auto new_conn = std::make_shared>( io_service_pool_.get_io_service(), ssl_conf_, max_req_buf_size_, keep_alive_timeout_, http_handler_, upload_dir_, @@ -255,14 +255,14 @@ class http_server_ : private noncopyable { acceptor->async_accept( new_conn->tcp_socket(), - [this, new_conn, acceptor](const boost::system::error_code &e) { + [this, new_conn, acceptor](const std::error_code &e) { if (!acceptor->is_open()) { return; } if (!e) { new_conn->tcp_socket().set_option( - boost::asio::ip::tcp::no_delay(true)); + asio::ip::tcp::no_delay(true)); if (multipart_begin_) { new_conn->set_multipart_begin(multipart_begin_); } diff --git a/include/cinatra/io_service_pool.hpp b/include/cinatra/io_service_pool.hpp index 00dd2ca6..5e4a79eb 100644 --- a/include/cinatra/io_service_pool.hpp +++ b/include/cinatra/io_service_pool.hpp @@ -13,8 +13,8 @@ class io_service_pool : private noncopyable { pool_size = 1; // set default value as 1 for (std::size_t i = 0; i < pool_size; ++i) { - io_service_ptr io_service(new boost::asio::io_service); - work_ptr work(new boost::asio::io_service::work(*io_service)); + io_service_ptr io_service(new asio::io_service); + work_ptr work(new asio::io_service::work(*io_service)); io_services_.push_back(io_service); work_.push_back(work); } @@ -44,8 +44,8 @@ class io_service_pool : private noncopyable { io_services_[i]->stop(); } - boost::asio::io_service &get_io_service() { - boost::asio::io_service &io_service = *io_services_[next_io_service_]; + asio::io_service &get_io_service() { + asio::io_service &io_service = *io_services_[next_io_service_]; ++next_io_service_; if (next_io_service_ == io_services_.size()) next_io_service_ = 0; @@ -53,8 +53,8 @@ class io_service_pool : private noncopyable { } private: - using io_service_ptr = std::shared_ptr; - using work_ptr = std::shared_ptr; + using io_service_ptr = std::shared_ptr; + using work_ptr = std::shared_ptr; std::vector io_services_; std::vector work_; @@ -64,8 +64,8 @@ class io_service_pool : private noncopyable { class io_service_inplace : private noncopyable { public: explicit io_service_inplace() { - io_services_ = std::make_shared(); - work_ = std::make_shared(*io_services_); + io_services_ = std::make_shared(); + work_ = std::make_shared(*io_services_); } void run() { io_services_->run(); } @@ -83,11 +83,11 @@ class io_service_inplace : private noncopyable { io_services_->stop(); } - boost::asio::io_service &get_io_service() { return *io_services_; } + asio::io_service &get_io_service() { return *io_services_; } private: - using io_service_ptr = std::shared_ptr; - using work_ptr = std::shared_ptr; + using io_service_ptr = std::shared_ptr; + using work_ptr = std::shared_ptr; io_service_ptr io_services_; work_ptr work_; diff --git a/include/cinatra/response.hpp b/include/cinatra/response.hpp index 343ff239..e6f40b62 100644 --- a/include/cinatra/response.hpp +++ b/include/cinatra/response.hpp @@ -112,8 +112,8 @@ class response { rep_str_.append(std::move(content_)); } - std::vector to_buffers() { - std::vector buffers; + std::vector to_buffers() { + std::vector buffers; add_header("Host", "cinatra"); if (session_ != nullptr && session_->is_need_update()) { auto cookie_str = session_->get_cookie().to_string(); @@ -123,25 +123,25 @@ class response { buffers.reserve(headers_.size() * 4 + 5); buffers.emplace_back(to_buffer(status_)); for (auto const &h : headers_) { - buffers.emplace_back(boost::asio::buffer(h.first)); - buffers.emplace_back(boost::asio::buffer(name_value_separator)); - buffers.emplace_back(boost::asio::buffer(h.second)); - buffers.emplace_back(boost::asio::buffer(crlf)); + buffers.emplace_back(asio::buffer(h.first)); + buffers.emplace_back(asio::buffer(name_value_separator)); + buffers.emplace_back(asio::buffer(h.second)); + buffers.emplace_back(asio::buffer(crlf)); } - buffers.push_back(boost::asio::buffer(crlf)); + buffers.push_back(asio::buffer(crlf)); if (body_type_ == content_type::string) { buffers.emplace_back( - boost::asio::buffer(content_.data(), content_.size())); + asio::buffer(content_.data(), content_.size())); } if (http_cache::get().need_cache(raw_url_)) { cache_data.clear(); for (auto &buf : buffers) { cache_data.push_back( - std::string(boost::asio::buffer_cast(buf), - boost::asio::buffer_size(buf))); + std::string(asio::buffer_cast(buf), + asio::buffer_size(buf))); } } @@ -241,25 +241,25 @@ class response { add_header("Transfer-Encoding", "chunked"); } - std::vector + std::vector to_chunked_buffers(const char *chunk_data, size_t length, bool eof) { - std::vector buffers; + std::vector buffers; if (length > 0) { // convert bytes transferred count to a hex string. chunk_size_ = to_hex_string(length); // Construct chunk based on rfc2616 section 3.6.1 - buffers.push_back(boost::asio::buffer(chunk_size_)); - buffers.push_back(boost::asio::buffer(crlf)); - buffers.push_back(boost::asio::buffer(chunk_data, length)); - buffers.push_back(boost::asio::buffer(crlf)); + buffers.push_back(asio::buffer(chunk_size_)); + buffers.push_back(asio::buffer(crlf)); + buffers.push_back(asio::buffer(chunk_data, length)); + buffers.push_back(asio::buffer(crlf)); } // append last-chunk if (eof) { - buffers.push_back(boost::asio::buffer(last_chunk)); - buffers.push_back(boost::asio::buffer(crlf)); + buffers.push_back(asio::buffer(last_chunk)); + buffers.push_back(asio::buffer(crlf)); } return buffers; diff --git a/include/cinatra/response_cv.hpp b/include/cinatra/response_cv.hpp index ed929605..566f5274 100644 --- a/include/cinatra/response_cv.hpp +++ b/include/cinatra/response_cv.hpp @@ -243,63 +243,63 @@ struct explode<0, digits...> : to_chars {}; template struct num_to_string : detail::explode {}; -inline boost::asio::const_buffer to_buffer(status_type status) { +inline asio::const_buffer to_buffer(status_type status) { switch (status) { case status_type::switching_protocols: - return boost::asio::buffer(switching_protocols.data(), + return asio::buffer(switching_protocols.data(), switching_protocols.length()); case status_type::ok: - return boost::asio::buffer(rep_ok.data(), rep_ok.length()); + return asio::buffer(rep_ok.data(), rep_ok.length()); case status_type::created: - return boost::asio::buffer(rep_created.data(), rep_created.length()); + return asio::buffer(rep_created.data(), rep_created.length()); case status_type::accepted: - return boost::asio::buffer(rep_accepted.data(), rep_created.length()); + return asio::buffer(rep_accepted.data(), rep_created.length()); case status_type::no_content: - return boost::asio::buffer(rep_no_content.data(), rep_no_content.length()); + return asio::buffer(rep_no_content.data(), rep_no_content.length()); case status_type::partial_content: - return boost::asio::buffer(rep_partial_content.data(), + return asio::buffer(rep_partial_content.data(), rep_partial_content.length()); case status_type::multiple_choices: - return boost::asio::buffer(rep_multiple_choices.data(), + return asio::buffer(rep_multiple_choices.data(), rep_multiple_choices.length()); case status_type::moved_permanently: - return boost::asio::buffer(rep_moved_permanently.data(), + return asio::buffer(rep_moved_permanently.data(), rep_moved_permanently.length()); case status_type::temporary_redirect: - return boost::asio::buffer(rep_temporary_redirect.data(), + return asio::buffer(rep_temporary_redirect.data(), rep_temporary_redirect.length()); case status_type::moved_temporarily: - return boost::asio::buffer(rep_moved_temporarily.data(), + return asio::buffer(rep_moved_temporarily.data(), rep_moved_temporarily.length()); case status_type::not_modified: - return boost::asio::buffer(rep_not_modified.data(), + return asio::buffer(rep_not_modified.data(), rep_not_modified.length()); case status_type::bad_request: - return boost::asio::buffer(rep_bad_request.data(), + return asio::buffer(rep_bad_request.data(), rep_bad_request.length()); case status_type::unauthorized: - return boost::asio::buffer(rep_unauthorized.data(), + return asio::buffer(rep_unauthorized.data(), rep_unauthorized.length()); case status_type::forbidden: - return boost::asio::buffer(rep_forbidden.data(), rep_forbidden.length()); + return asio::buffer(rep_forbidden.data(), rep_forbidden.length()); case status_type::not_found: - return boost::asio::buffer(rep_not_found.data(), rep_not_found.length()); + return asio::buffer(rep_not_found.data(), rep_not_found.length()); case status_type::conflict: - return boost::asio::buffer(rep_conflict.data(), rep_conflict.length()); + return asio::buffer(rep_conflict.data(), rep_conflict.length()); case status_type::internal_server_error: - return boost::asio::buffer(rep_internal_server_error.data(), + return asio::buffer(rep_internal_server_error.data(), rep_internal_server_error.length()); case status_type::not_implemented: - return boost::asio::buffer(rep_not_implemented.data(), + return asio::buffer(rep_not_implemented.data(), rep_not_implemented.length()); case status_type::bad_gateway: - return boost::asio::buffer(rep_bad_gateway.data(), + return asio::buffer(rep_bad_gateway.data(), rep_bad_gateway.length()); case status_type::service_unavailable: - return boost::asio::buffer(rep_service_unavailable.data(), + return asio::buffer(rep_service_unavailable.data(), rep_service_unavailable.length()); default: - return boost::asio::buffer(rep_internal_server_error.data(), + return asio::buffer(rep_internal_server_error.data(), rep_internal_server_error.length()); } } diff --git a/include/cinatra/smtp_client.hpp b/include/cinatra/smtp_client.hpp index 88602085..29e402e4 100644 --- a/include/cinatra/smtp_client.hpp +++ b/include/cinatra/smtp_client.hpp @@ -20,7 +20,7 @@ struct email_data { template class client { public: static constexpr bool IS_SSL = std::is_same_v; - client(boost::asio::io_service &io_service) + client(asio::io_service &io_service) : io_context_(io_service), socket_(io_service), resolver_(io_service) {} ~client() { close(); } @@ -35,12 +35,12 @@ template class client { host.erase(0, pos + 3); } - boost::asio::ip::tcp::resolver::query qry( + asio::ip::tcp::resolver::query qry( host, server_.port, - boost::asio::ip::resolver_query_base::numeric_service); - boost::system::error_code ec; + asio::ip::resolver_query_base::numeric_service); + std::error_code ec; auto endpoint_iterator = resolver_.resolve(qry, ec); - boost::asio::connect(socket_, endpoint_iterator, ec); + asio::connect(socket_, endpoint_iterator, ec); if (ec) { return; } @@ -51,13 +51,13 @@ template class client { build_request(); - boost::asio::write(socket(), request_, ec); + asio::write(socket(), request_, ec); if (ec) { return; } while (true) { - boost::asio::read(socket(), response_, boost::asio::transfer_at_least(1), + asio::read(socket(), response_, asio::transfer_at_least(1), ec); if (ec) { return; @@ -87,13 +87,13 @@ template class client { } void upgrade_to_ssl() { #ifdef CINATRA_ENABLE_SSL - boost::asio::ssl::context ctx(boost::asio::ssl::context::sslv23); + asio::ssl::context ctx(asio::ssl::context::sslv23); ctx.set_default_verify_paths(); ctx.set_verify_mode(ctx.verify_fail_if_no_peer_cert); ssl_socket_ = std::make_unique< - boost::asio::ssl::stream>(socket_, ctx); - ssl_socket_->set_verify_mode(boost::asio::ssl::verify_none); + asio::ssl::stream>(socket_, ctx); + ssl_socket_->set_verify_mode(asio::ssl::verify_none); ssl_socket_->set_verify_callback([](auto preverified, auto &ctx) { char subject_name[256]; X509 *cert = X509_STORE_CTX_get_current_cert(ctx.native_handle()); @@ -102,8 +102,8 @@ template class client { return preverified; }); - boost::system::error_code ec; - ssl_socket_->handshake(boost::asio::ssl::stream_base::client, ec); + std::error_code ec; + ssl_socket_->handshake(asio::ssl::stream_base::client, ec); #endif } @@ -178,35 +178,35 @@ template class client { } void close() { - boost::system::error_code ignore_ec; + std::error_code ignore_ec; if constexpr (IS_SSL) { #ifdef CINATRA_ENABLE_SSL ssl_socket_->shutdown(ignore_ec); #endif } - socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignore_ec); + socket_.shutdown(asio::ip::tcp::socket::shutdown_both, ignore_ec); socket_.close(ignore_ec); } private: - boost::asio::io_context &io_context_; - boost::asio::ip::tcp::socket socket_; + asio::io_context &io_context_; + asio::ip::tcp::socket socket_; #ifdef CINATRA_ENABLE_SSL - std::unique_ptr> + std::unique_ptr> ssl_socket_; #endif - boost::asio::ip::tcp::resolver resolver_; + asio::ip::tcp::resolver resolver_; email_server server_; email_data data_; - boost::asio::streambuf request_; - boost::asio::streambuf response_; + asio::streambuf request_; + asio::streambuf response_; }; template -static inline auto get_smtp_client(boost::asio::io_service &io_service) { +static inline auto get_smtp_client(asio::io_service &io_service) { return smtp::client(io_service); } diff --git a/include/cinatra/use_asio.hpp b/include/cinatra/use_asio.hpp index b2e0a163..9a4d9689 100644 --- a/include/cinatra/use_asio.hpp +++ b/include/cinatra/use_asio.hpp @@ -9,23 +9,9 @@ #include #endif #include -namespace boost { -namespace asio { -using namespace ::asio; -} -namespace system { -using ::std::error_code; -} -} // namespace boost -#else -#include -#ifdef CINATRA_ENABLE_SSL -#include -#endif -#include -using tcp_socket = boost::asio::ip::tcp::socket; +using tcp_socket = asio::ip::tcp::socket; #ifdef CINATRA_ENABLE_SSL -using ssl_socket = boost::asio::ssl::stream; +using ssl_socket = asio::ssl::stream; #endif #endif diff --git a/include/cinatra/utils.hpp b/include/cinatra/utils.hpp index 7a05f25c..08e52d59 100644 --- a/include/cinatra/utils.hpp +++ b/include/cinatra/utils.hpp @@ -11,8 +11,6 @@ #include #if defined(ASIO_STANDALONE) #include "use_asio.hpp" -#else -#include #endif #include #include //std::byte @@ -365,7 +363,7 @@ template inline void print(Args... args) { std::cout << "\n"; } -inline void print(const boost::system::error_code &ec) { +inline void print(const std::error_code &ec) { print(ec.value(), ec.message()); } diff --git a/include/cinatra/websocket.hpp b/include/cinatra/websocket.hpp index 77f6926e..086d3440 100644 --- a/include/cinatra/websocket.hpp +++ b/include/cinatra/websocket.hpp @@ -163,11 +163,11 @@ class websocket { return {msg_header_, header_length}; } - std::vector + std::vector format_message(const char *src, size_t length, opcode code) { size_t header_length = encode_header(length, code); - return {boost::asio::buffer(msg_header_, header_length), - boost::asio::buffer(src, length)}; + return {asio::buffer(msg_header_, header_length), + asio::buffer(src, length)}; } close_frame parse_close_payload(char *src, size_t length) { diff --git a/lang/english/README.md b/lang/english/README.md index 10b40d33..58313ad9 100644 --- a/lang/english/README.md +++ b/lang/english/README.md @@ -31,8 +31,6 @@ Cinatra is a header-only library. So you can immediately use it in your code wit To compile your code with Cinatra, you need the following: 1. C++20 compiler (gcc 10.2, clang 13, Visual Studio 2022, or later versions) -2. Boost.Asio (or standalone Asio) -3. Boost.System ## Examples