From: Radoslaw Zarzynski Date: Wed, 3 Aug 2016 16:42:30 +0000 (+0200) Subject: rgw: port the ASIO frontend to the new RGWStreamIOEngine infrastructure. X-Git-Tag: v11.1.0~454^2~42 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2825cc7c614483dcf42eb920bfe35ae26428344e;p=ceph.git rgw: port the ASIO frontend to the new RGWStreamIOEngine infrastructure. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_asio_client.cc b/src/rgw/rgw_asio_client.cc index 8b584799a74f..679b3078aef5 100644 --- a/src/rgw/rgw_asio_client.cc +++ b/src/rgw/rgw_asio_client.cc @@ -12,8 +12,10 @@ #define dout_prefix (*_dout << "asio: ") -RGWAsioClientIO::RGWAsioClientIO(tcp::socket&& socket, request_type&& request) - : socket(std::move(socket)), request(std::move(request)) +RGWAsioClientIO::RGWAsioClientIO(tcp::socket&& socket, + request_type&& request) + : socket(std::move(socket)), + request(std::move(request)) {} RGWAsioClientIO::~RGWAsioClientIO() = default; @@ -76,7 +78,7 @@ void RGWAsioClientIO::init_env(CephContext *cct) // TODO: set REMOTE_USER if authenticated } -int RGWAsioClientIO::write_data(const char *buf, int len) +int RGWAsioClientIO::write_data(const char* const buf, const int len) { boost::system::error_code ec; auto bytes = boost::asio::write(socket, boost::asio::buffer(buf, len), ec); @@ -87,7 +89,7 @@ int RGWAsioClientIO::write_data(const char *buf, int len) return bytes; } -int RGWAsioClientIO::read_data(char *buf, int max) +int RGWAsioClientIO::read_data(char* const buf, const int max) { // read data from the body's bufferlist auto bytes = std::min(max, body_iter.get_remaining()); @@ -102,46 +104,68 @@ int RGWAsioClientIO::complete_request() void RGWAsioClientIO::flush() { + return; } -int RGWAsioClientIO::send_status(int status, const char *status_name) +int RGWAsioClientIO::send_status(const int status, + const char* const status_name) { - return print("HTTP/1.1 %d %s\r\n", status, status_name); + static constexpr size_t STATUS_BUF_SIZE = 128; + + char statusbuf[STATUS_BUF_SIZE]; + const auto statuslen = snprintf(statusbuf, sizeof(statusbuf), + "HTTP/1.1 %d %s\r\n", status, status_name); + + return write_data(statusbuf, statuslen); } int RGWAsioClientIO::send_100_continue() { - return print("HTTP/1.1 100 CONTINUE\r\n\r\n"); + const char HTTTP_100_CONTINUE[] = "HTTP/1.1 100 CONTINUE\r\n\r\n"; + return write_data(HTTTP_100_CONTINUE, sizeof(HTTTP_100_CONTINUE) - 1); } static constexpr size_t TIME_BUF_SIZE = 128; -static int dump_date_header(char *timestr, size_t size) +static size_t dump_date_header(char (×tr)[TIME_BUF_SIZE]) { const time_t gtime = time(nullptr); struct tm result; struct tm const * const tmp = gmtime_r(>ime, &result); - if (tmp == nullptr) + if (tmp == nullptr) { return 0; - return strftime(timestr, size, "Date: %a, %d %b %Y %H:%M:%S %Z\r\n", tmp); + } + return strftime(timestr, sizeof(timestr), + "Date: %a, %d %b %Y %H:%M:%S %Z\r\n", tmp); } int RGWAsioClientIO::complete_header() { + size_t sent = 0; + char timestr[TIME_BUF_SIZE]; - if (dump_date_header(timestr, sizeof(timestr))) { - print(timestr); + if (dump_date_header(timestr)) { + sent += write_data(timestr, strlen(timestr)); } if (conn_keepalive) { - print("Connection: Keep-Alive\r\n"); + constexpr char CONN_KEEP_ALIVE[] = "Connection: Keep-Alive\r\n"; + sent += write_data(CONN_KEEP_ALIVE, sizeof(CONN_KEEP_ALIVE) - 1); } else if (conn_close) { - print("Connection: close\r\n"); + constexpr char CONN_KEEP_CLOSE[] = "Connection: close\r\n"; + sent += write_data(CONN_KEEP_CLOSE, sizeof(CONN_KEEP_CLOSE) - 1); } - print("\r\n"); - return 0; + + constexpr char HEADER_END[] = "\r\n"; + return sent + write_data(HEADER_END, sizeof(HEADER_END) - 1); } -int RGWAsioClientIO::send_content_length(uint64_t len) +int RGWAsioClientIO::send_content_length(const uint64_t len) { - return print("Content-Length: %" PRIu64 "\r\n", len); + static constexpr size_t CONLEN_BUF_SIZE = 128; + + char sizebuf[CONLEN_BUF_SIZE]; + const auto sizelen = snprintf(sizebuf, sizeof(sizebuf), + "Content-Length: %" PRIu64 "\r\n", len); + + return write_data(sizebuf, sizelen); } diff --git a/src/rgw/rgw_asio_client.h b/src/rgw/rgw_asio_client.h index d6426b78a473..11ae0443d4fe 100644 --- a/src/rgw/rgw_asio_client.h +++ b/src/rgw/rgw_asio_client.h @@ -24,7 +24,7 @@ class RGWBufferlistBody { Headers>; }; -class RGWAsioClientIO : public RGWStreamIO { +class RGWAsioClientIO : public RGWStreamIOEngine { using tcp = boost::asio::ip::tcp; tcp::socket socket; @@ -36,6 +36,7 @@ class RGWAsioClientIO : public RGWStreamIO { bool conn_keepalive{false}; bool conn_close{false}; + RGWEnv env; void init_env(CephContext *cct) override; int write_data(const char *buf, int len) override; @@ -51,6 +52,10 @@ class RGWAsioClientIO : public RGWStreamIO { int send_100_continue() override; int complete_header() override; int send_content_length(uint64_t len) override; + + RGWEnv& get_env() override { + return env; + } }; // used by beast::http::read() to read the body into a bufferlist diff --git a/src/rgw/rgw_asio_frontend.cc b/src/rgw/rgw_asio_frontend.cc index a89ec7711dad..6d7b1b12699a 100644 --- a/src/rgw/rgw_asio_frontend.cc +++ b/src/rgw/rgw_asio_frontend.cc @@ -92,7 +92,8 @@ class AsioConnection : public std::enable_shared_from_this { return; } RGWRequest req{env.store->get_new_req_id()}; - RGWAsioClientIO client{std::move(socket), std::move(request)}; + RGWAsioClientIO real_client{std::move(socket), std::move(request)}; + RGWStreamIOLegacyWrapper client(&real_client); process_request(env.store, env.rest, &req, &client, env.olog); }