]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | |
2 | // vim: ts=8 sw=2 smarttab | |
3 | #ifndef RGW_ASIO_CLIENT_H | |
4 | #define RGW_ASIO_CLIENT_H | |
5 | ||
6 | #include <boost/asio/ip/tcp.hpp> | |
7 | #include <boost/beast/core.hpp> | |
8 | #include <boost/beast/http.hpp> | |
9 | #include "include/assert.h" | |
10 | ||
11 | #include "rgw_client_io.h" | |
12 | ||
13 | namespace rgw { | |
14 | namespace asio { | |
15 | ||
16 | namespace beast = boost::beast; | |
17 | using parser_type = beast::http::request_parser<beast::http::buffer_body>; | |
18 | ||
19 | class ClientIO : public io::RestfulClient, | |
20 | public io::BuffererSink { | |
21 | private: | |
22 | using tcp = boost::asio::ip::tcp; | |
23 | tcp::socket& socket; | |
24 | parser_type& parser; | |
25 | beast::flat_buffer& buffer; //< parse buffer | |
26 | ||
27 | RGWEnv env; | |
28 | ||
29 | rgw::io::StaticOutputBufferer<> txbuf; | |
30 | ||
31 | size_t write_data(const char *buf, size_t len) override; | |
32 | size_t read_data(char *buf, size_t max); | |
33 | ||
34 | public: | |
35 | ClientIO(tcp::socket& socket, parser_type& parser, | |
36 | beast::flat_buffer& buffer); | |
37 | ~ClientIO() override; | |
38 | ||
39 | void init_env(CephContext *cct) override; | |
40 | size_t complete_request() override; | |
41 | void flush() override; | |
42 | size_t send_status(int status, const char *status_name) override; | |
43 | size_t send_100_continue() override; | |
44 | size_t send_header(const boost::string_ref& name, | |
45 | const boost::string_ref& value) override; | |
46 | size_t send_content_length(uint64_t len) override; | |
47 | size_t complete_header() override; | |
48 | ||
49 | size_t recv_body(char* buf, size_t max) override { | |
50 | return read_data(buf, max); | |
51 | } | |
52 | ||
53 | size_t send_body(const char* buf, size_t len) override { | |
54 | return write_data(buf, len); | |
55 | } | |
56 | ||
57 | RGWEnv& get_env() noexcept override { | |
58 | return env; | |
59 | } | |
60 | }; | |
61 | ||
62 | } // namespace asio | |
63 | } // namespace rgw | |
64 | ||
65 | #endif // RGW_ASIO_CLIENT_H |