roar
|
#include <client.hpp>
Classes | |
struct | ConstructionArguments |
struct | SslOptions |
Public Member Functions | |
Client (ConstructionArguments &&args) | |
ROAR_PIMPL_SPECIAL_FUNCTIONS_NO_MOVE (Client) | |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen< std::size_t >, Detail::PromiseTypeBindFail< Error > > | send (std::string message, std::chrono::seconds timeout=defaultTimeout) |
Sends a string to the server. | |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen< std::string_view, std::size_t >, Detail::PromiseTypeBindFail< Error > > | read (std::chrono::seconds timeout=defaultTimeout) |
Reads something from the server. | |
template<typename T > | |
void | attachState (std::string const &tag, T &&state) |
Attach some state to the client lifetime. | |
template<typename T , typename... ConstructionArgs> | |
void | emplaceState (std::string const &tag, ConstructionArgs &&... args) |
Create state in place. | |
template<typename T > | |
T & | state (std::string const &tag) |
Retrieve attached state by tag. | |
void | removeState (std::string const &tag) |
Remove attached state. | |
template<typename BodyT > | |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen<>, Detail::PromiseTypeBindFail< Error > > | request (Request< BodyT > &&request, std::chrono::seconds timeout=defaultTimeout) |
Connects the client to a server and performs a request. | |
template<typename ResponseBodyT > | |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen<>, Detail::PromiseTypeBindFail< Error > > | readHeader (boost::beast::http::response_parser< ResponseBodyT > &parser, std::chrono::seconds timeout=defaultTimeout) |
Reads only the header, will need be followed up by a readResponse. | |
template<typename ResponseBodyT > | |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen< Detail::PromiseReferenceWrap< Response< ResponseBodyT > > >, Detail::PromiseTypeBindFail< Error > > | readResponse (std::chrono::seconds timeout=defaultTimeout) |
Read a response from the server. | |
template<typename ResponseBodyT > | |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen<>, Detail::PromiseTypeBindFail< Error > > | readResponse (boost::beast::http::response_parser< ResponseBodyT > &parser, std::chrono::seconds timeout=defaultTimeout) |
Read a response using a beast response parser. You are responsible for keeping the parser alive! | |
template<typename ResponseBodyT , typename RequestBodyT > | |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen< Detail::PromiseReferenceWrap< Response< ResponseBodyT > > >, Detail::PromiseTypeBindFail< Error > > | requestAndReadResponse (Request< RequestBodyT > &&request, std::chrono::seconds timeout=defaultTimeout) |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen<>, Detail::PromiseTypeBindFail< Error > > | close () |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen<>, Detail::PromiseTypeBindFail< Error > > | shutdownSsl (std::chrono::seconds timeout=defaultTimeout) |
template<typename FunctionT > | |
void | withStreamDo (FunctionT &&func) |
template<typename FunctionT > | |
void | withStreamDo (FunctionT &&func) const |
template<typename FunctionT > | |
void | withLowerLayerDo (FunctionT &&func) |
template<typename FunctionT > | |
void | withLowerLayerDo (FunctionT &&func) const |
Static Public Attributes | |
static constexpr std::chrono::seconds | defaultTimeout {10} |
Private Member Functions | |
void | doResolve (std::string const &host, std::string const &port, std::function< void(boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type results)> onResolve) |
template<typename BodyT > | |
void | onConnect (Request< BodyT > &&request, promise::Defer &&d, std::chrono::seconds timeout) |
template<typename BodyT > | |
void | performRequest (Request< BodyT > &&request, promise::Defer &&d, std::chrono::seconds timeout) |
std::optional< Error > | setupSsl (std::string const &host) |
Private Attributes | |
std::optional< SslOptions > | sslOptions_ |
boost::asio::ip::tcp::resolver | resolver_ |
std::shared_ptr< boost::beast::flat_buffer > | buffer_ |
std::variant< boost::beast::ssl_stream< boost::beast::tcp_stream >, boost::beast::tcp_stream > | socket_ |
boost::asio::ip::tcp::resolver::results_type::endpoint_type | endpoint_ |
std::unordered_map< std::string, std::any > | attachedState_ |
Roar::Client::Client | ( | ConstructionArguments && | args | ) |
|
inline |
Attach some state to the client lifetime.
tag | A tag name, to retrieve it back with. |
state | The state. |
|
inline |
|
private |
|
inline |
Create state in place.
ConstructionArgs |
tag | |
args |
|
inlineprivate |
|
inlineprivate |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen< std::string_view, std::size_t >, Detail::PromiseTypeBindFail< Error > > Roar::Client::read | ( | std::chrono::seconds | timeout = defaultTimeout | ) |
Reads something from the server.
|
inline |
Reads only the header, will need be followed up by a readResponse.
ResponseBodyT |
parser | |
timeout |
|
inline |
Read a response using a beast response parser. You are responsible for keeping the parser alive!
ResponseBodyT |
parser | Passed in by reference, must be alive until the promise is resolved. |
timeout |
|
inline |
Read a response from the server.
ResponseBodyT |
timeout |
|
inline |
Remove attached state.
tag | The tag of the state to remove. |
|
inline |
Connects the client to a server and performs a request.
requestParameters | see RequestParameters |
|
inline |
Roar::Client::ROAR_PIMPL_SPECIAL_FUNCTIONS_NO_MOVE | ( | Client | ) |
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen< std::size_t >, Detail::PromiseTypeBindFail< Error > > Roar::Client::send | ( | std::string | message, |
std::chrono::seconds | timeout = defaultTimeout |
||
) |
Sends a string to the server.
message | A message to send. |
|
private |
|
inline |
|
inline |
Retrieve attached state by tag.
T | Type of the attached state. |
tag | The tag of the state. |
|
inline |
|
inline |
|
inline |
|
inline |
|
private |
|
private |
|
staticconstexpr |
|
private |
|
private |
|
private |
|
private |