From 8f626357d5ebee1bf8039ad6e85f5e02c64c9076 Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Wed, 19 Dec 2018 14:51:54 -0800 Subject: bmcweb: Remove deprecatd ASIO interfaces boost::asio::io_service is removed in leiu of io_context, which is a closer match to the networking TS. Move us to that implementatio. This was an automated move using the following command: git grep -l 'io_service' | xargs sed -i 's/io_service/io_context/g' Change-Id: I46605521c01f79f86f6901ddf69ddc8c4bc24103 Signed-off-by: Ed Tanous --- README.md | 2 +- crow/include/crow/app.h | 6 +++--- crow/include/crow/http_connection.h | 4 ++-- crow/include/crow/http_request.h | 4 ++-- crow/include/crow/http_server.h | 14 +++++++------- crow/include/crow/socket_adaptors.h | 18 +++++++++--------- crow/include/crow/websocket.h | 4 ++-- include/ast_video_puller.hpp | 2 +- src/crow_test.cpp | 10 +++++----- src/kvm_websocket_test.cpp | 2 +- src/security_headers_middleware_test.cpp | 2 +- src/token_authorization_middleware_test.cpp | 14 +++++++------- src/webassets_test.cpp | 4 ++-- src/webserver_main.cpp | 4 ++-- 14 files changed, 45 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 77ac92e71a..e5e8ca1f48 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ The crow project has had a number of additions to make it more useful for use in + Move most uses of std::unordered_map to boost::flat_map to lower memory consumption, and (in some cases) to improve memory locality. + Adjust the addHeaders mechanism to use a fixed string instead of a full map implementation to avoid unnecessary mallocs and reduce the number of scatter gather buffers on an http response. + Change server name header from Crow/0.1 to iBMC -+ Starts the http server io_service inside the main thread, instead of creating a new thread. ++ Starts the http server io_context inside the main thread, instead of creating a new thread. + Removes all BMCWEB_MSVC_WORKAROUND flags. + Removes the behavior that causes a 301 redirect for paths that end in "/", and simply returns the endpoint requested. This was done for redfish compatibility. + Removes the built in crow/json.hpp package and adds nlohmann json package as the first class json package for crow. diff --git a/crow/include/crow/app.h b/crow/include/crow/app.h index 428705d223..9a2281afb9 100644 --- a/crow/include/crow/app.h +++ b/crow/include/crow/app.h @@ -36,8 +36,8 @@ template class Crow using server_t = Server; #endif - explicit Crow(std::shared_ptr io = - std::make_shared()) : + explicit Crow(std::shared_ptr io = + std::make_shared()) : io(std::move(io)) { } @@ -225,7 +225,7 @@ template class Crow } private: - std::shared_ptr io; + std::shared_ptr io; #ifdef BMCWEB_ENABLE_SSL uint16_t portUint = 443; #else diff --git a/crow/include/crow/http_connection.h b/crow/include/crow/http_connection.h index 51bc9febfc..297648e95a 100644 --- a/crow/include/crow/http_connection.h +++ b/crow/include/crow/http_connection.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include @@ -247,7 +247,7 @@ template class Connection { public: - Connection(boost::asio::io_service& ioService, Handler* handler, + Connection(boost::asio::io_context& ioService, Handler* handler, const std::string& server_name, std::tuple* middlewares, std::function& get_cached_date_str_f, diff --git a/crow/include/crow/http_request.h b/crow/include/crow/http_request.h index e66ad4be27..ac5f78d0ca 100644 --- a/crow/include/crow/http_request.h +++ b/crow/include/crow/http_request.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -19,7 +19,7 @@ struct Request const std::string& body; void* middlewareContext{}; - boost::asio::io_service* ioService{}; + boost::asio::io_context* ioService{}; Request(boost::beast::http::request& req) : req(req), body(req.body()) diff --git a/crow/include/crow/http_server.h b/crow/include/crow/http_server.h index d8fedf3bcd..ebf55707bc 100644 --- a/crow/include/crow/http_server.h +++ b/crow/include/crow/http_server.h @@ -32,8 +32,8 @@ class Server Server(Handler* handler, std::unique_ptr&& acceptor, std::tuple* middlewares = nullptr, typename Adaptor::context* adaptor_ctx = nullptr, - std::shared_ptr io = - std::make_shared()) : + std::shared_ptr io = + std::make_shared()) : ioService(std::move(io)), acceptor(std::move(acceptor)), signals(*ioService, SIGINT, SIGTERM), tickTimer(*ioService), handler(handler), middlewares(middlewares), @@ -44,8 +44,8 @@ class Server Server(Handler* handler, const std::string& bindaddr, uint16_t port, std::tuple* middlewares = nullptr, typename Adaptor::context* adaptor_ctx = nullptr, - std::shared_ptr io = - std::make_shared()) : + std::shared_ptr io = + std::make_shared()) : Server(handler, std::make_unique( *io, @@ -58,8 +58,8 @@ class Server Server(Handler* handler, int existing_socket, std::tuple* middlewares = nullptr, typename Adaptor::context* adaptor_ctx = nullptr, - std::shared_ptr io = - std::make_shared()) : + std::shared_ptr io = + std::make_shared()) : Server(handler, std::make_unique(*io, boost::asio::ip::tcp::v6(), existing_socket), @@ -181,7 +181,7 @@ class Server } private: - std::shared_ptr ioService; + std::shared_ptr ioService; detail::TimerQueue timerQueue; std::function getCachedDateStr; std::unique_ptr acceptor; diff --git a/crow/include/crow/socket_adaptors.h b/crow/include/crow/socket_adaptors.h index a47697f2a5..16ebe1f762 100644 --- a/crow/include/crow/socket_adaptors.h +++ b/crow/include/crow/socket_adaptors.h @@ -17,14 +17,14 @@ struct SocketAdaptor using streamType = tcp::socket; using secure = std::false_type; using context = void; - SocketAdaptor(boost::asio::io_service& ioService, context* /*unused*/) : + SocketAdaptor(boost::asio::io_context& ioService, context* /*unused*/) : socketCls(ioService) { } - boost::asio::io_service& getIoService() + boost::asio::io_context& getIoService() { - return socketCls.get_io_service(); + return socketCls.get_io_context(); } tcp::socket& rawSocket() @@ -71,14 +71,14 @@ struct TestSocketAdaptor { using secure = std::false_type; using context = void; - TestSocketAdaptor(boost::asio::io_service& ioService, context* /*unused*/) : + TestSocketAdaptor(boost::asio::io_context& ioService, context* /*unused*/) : socketCls(ioService) { } - boost::asio::io_service& getIoService() + boost::asio::io_context& getIoService() { - return socketCls.get_io_service(); + return socketCls.get_io_context(); } tcp::socket& rawSocket() @@ -121,7 +121,7 @@ struct SSLAdaptor using secure = std::true_type; using context = boost::asio::ssl::context; using ssl_socket_t = boost::asio::ssl::stream; - SSLAdaptor(boost::asio::io_service& ioService, context* ctx) : + SSLAdaptor(boost::asio::io_context& ioService, context* ctx) : sslSocket(new ssl_socket_t(ioService, *ctx)) { } @@ -182,9 +182,9 @@ struct SSLAdaptor this->sslSocket->lowest_layer().close(); } - boost::asio::io_service& getIoService() + boost::asio::io_context& getIoService() { - return rawSocket().get_io_service(); + return rawSocket().get_io_context(); } template void start(F f) diff --git a/crow/include/crow/websocket.h b/crow/include/crow/websocket.h index 1596b8d80b..c435d336b7 100644 --- a/crow/include/crow/websocket.h +++ b/crow/include/crow/websocket.h @@ -27,7 +27,7 @@ struct Connection : std::enable_shared_from_this virtual void sendText(const boost::beast::string_view msg) = 0; virtual void sendText(std::string&& msg) = 0; virtual void close(const boost::beast::string_view msg = "quit") = 0; - virtual boost::asio::io_service& getIoService() = 0; + virtual boost::asio::io_context& getIoService() = 0; virtual ~Connection() = default; void userdata(void* u) @@ -65,7 +65,7 @@ template class ConnectionImpl : public Connection BMCWEB_LOG_DEBUG << "Creating new connection " << this; } - boost::asio::io_service& getIoService() override + boost::asio::io_context& getIoService() override { return adaptor.getIoService(); } diff --git a/include/ast_video_puller.hpp b/include/ast_video_puller.hpp index 520fc68e18..c97ca4860a 100644 --- a/include/ast_video_puller.hpp +++ b/include/ast_video_puller.hpp @@ -141,7 +141,7 @@ class AsyncVideoPuller public: using video_callback = std::function; - explicit AsyncVideoPuller(boost::asio::io_service &ioService) : + explicit AsyncVideoPuller(boost::asio::io_context &ioService) : imageInfo(), devVideo(ioService, open("/dev/video", O_RDWR)) { videobuf = std::make_shared(); diff --git a/src/crow_test.cpp b/src/crow_test.cpp index 96b90b0ed2..beefdeee2a 100644 --- a/src/crow_test.cpp +++ b/src/crow_test.cpp @@ -398,7 +398,7 @@ TEST(Crow, server_handling_error_request) Server server(&app, LOCALHOST_ADDRESS, 45451); auto _ = async(launch::async, [&] { server.run(); }); std::string sendmsg = "POX"; - asio::io_service is; + asio::io_context is; { asio::ip::tcp::socket c(is); c.connect(asio::ip::tcp::endpoint( @@ -436,7 +436,7 @@ TEST(Crow, multi_server) std::string sendmsg = "POST /\r\nContent-Length:3\r\nX-HeaderTest: 123\r\n\r\nA=b\r\n"; - asio::io_service is; + asio::io_context is; { asio::ip::tcp::socket c(is); c.connect(asio::ip::tcp::endpoint( @@ -645,7 +645,7 @@ TEST(Crow, middlewareContext) decltype(app)::server_t server(&app, LOCALHOST_ADDRESS, 45451); auto _ = async(launch::async, [&] { server.run(); }); std::string sendmsg = "GET /\r\n\r\n"; - asio::io_service is; + asio::io_context is; { asio::ip::tcp::socket c(is); c.connect(asio::ip::tcp::endpoint( @@ -701,7 +701,7 @@ TEST(Crow, bug_quick_repeated_request) decltype(app)::server_t server(&app, LOCALHOST_ADDRESS, 45451); auto _ = async(launch::async, [&] { server.run(); }); std::string sendmsg = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"; - asio::io_service is; + asio::io_context is; { std::vector> v; for (int i = 0; i < 5; i++) @@ -744,7 +744,7 @@ TEST(Crow, simple_url_params) decltype(app)::server_t server(&app, LOCALHOST_ADDRESS, 45451); auto _ = async(launch::async, [&] { server.run(); }); - asio::io_service is; + asio::io_context is; std::string sendmsg; // check empty params diff --git a/src/kvm_websocket_test.cpp b/src/kvm_websocket_test.cpp index 1ddaad9b35..40470a9212 100644 --- a/src/kvm_websocket_test.cpp +++ b/src/kvm_websocket_test.cpp @@ -24,7 +24,7 @@ TEST(Kvm, BasicRfb) BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); auto _ = async(std::launch::async, [&] { app.run(); }); auto routes = app.getRoutes(); - asio::io_service is; + asio::io_context is; { // Retry a couple of times waiting for the server to come up diff --git a/src/security_headers_middleware_test.cpp b/src/security_headers_middleware_test.cpp index 2af15c6d07..4fa3003e71 100644 --- a/src/security_headers_middleware_test.cpp +++ b/src/security_headers_middleware_test.cpp @@ -16,7 +16,7 @@ TEST(SecurityHeaders, TestHeadersExist) BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); auto _ = async(launch::async, [&] { app.run(); }); - asio::io_service is; + asio::io_context is; std::array buf; std::string sendmsg; diff --git a/src/token_authorization_middleware_test.cpp b/src/token_authorization_middleware_test.cpp index 812a6d193e..8f4c5c8252 100644 --- a/src/token_authorization_middleware_test.cpp +++ b/src/token_authorization_middleware_test.cpp @@ -15,14 +15,14 @@ class TokenAuth : public ::testing::Test public: TokenAuth() : lk(std::unique_lock(m)), - io(std::make_shared()) + io(std::make_shared()) { } std::mutex m; std::condition_variable cv; std::unique_lock lk; - std::shared_ptr io; + std::shared_ptr io; int testPort = 45451; }; @@ -38,7 +38,7 @@ TEST_F(TokenAuth, SpecialResourcesAreAcceptedWithoutAuth) io->run(); }); - asio::io_service is; + asio::io_context is; std::string sendmsg; static char buf[2048]; @@ -80,7 +80,7 @@ TEST(TokenAuthentication, TestRejectedResource) BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); auto _ = async(std::launch::async, [&] { app.run(); }); - asio::io_service is; + asio::io_context is; static char buf[2048]; // Other resources should not be passed @@ -116,7 +116,7 @@ TEST(TokenAuthentication, TestGetLoginUrl) BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); auto _ = async(std::launch::async, [&] { app.run(); }); - asio::io_service is; + asio::io_context is; static char buf[2048]; // Other resources should not be passed @@ -152,7 +152,7 @@ TEST(TokenAuthentication, TestPostBadLoginUrl) BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); auto _ = async(std::launch::async, [&] { app.run(); }); - asio::io_service is; + asio::io_context is; std::array buf; std::string sendmsg; @@ -244,7 +244,7 @@ TEST(TokenAuthentication, TestSuccessfulLogin) BMCWEB_ROUTE(app, "/")([]() { return boost::beast::http::status::ok; }); auto _ = async(std::launch::async, [&] { app.run(); }); - asio::io_service is; + asio::io_context is; std::array buf; std::string sendmsg; diff --git a/src/webassets_test.cpp b/src/webassets_test.cpp index a3106f2796..3df754220b 100644 --- a/src/webassets_test.cpp +++ b/src/webassets_test.cpp @@ -25,7 +25,7 @@ TEST(Webassets, StaticFilesFixedRoutes) // get the homepage std::string sendmsg = "GET /\r\n\r\n"; - asio::io_service is; + asio::io_context is; asio::ip::tcp::socket c(is); c.connect(asio::ip::tcp::endpoint( @@ -100,7 +100,7 @@ TEST(Webassets, EtagIsSane) // get the homepage std::string sendmsg = "GET /\r\n\r\n"; - asio::io_service is; + asio::io_context is; asio::ip::tcp::socket c(is); c.connect(asio::ip::tcp::endpoint( diff --git a/src/webserver_main.cpp b/src/webserver_main.cpp index b4d36efb4e..7c64f4c748 100644 --- a/src/webserver_main.cpp +++ b/src/webserver_main.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include #include #include @@ -57,7 +57,7 @@ int main(int argc, char** argv) { crow::logger::setLogLevel(crow::LogLevel::DEBUG); - auto io = std::make_shared(); + auto io = std::make_shared(); CrowApp app(io); #ifdef BMCWEB_ENABLE_SSL -- cgit v1.2.3