FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
fastmm::net::HttpClient< Stream > Class Template Referencefinal

#include <fastmm/net/http_client.hpp>

Inheritance diagram for fastmm::net::HttpClient< Stream >:
fastmm::net::IoHandler

Public Member Functions

 HttpClient (Reactor &reactor, Stream &&stream, std::string host, std::uint16_t port, bool tls, const HttpClientConfig &cfg={})
 
 ~HttpClient () override
 
 HttpClient (const HttpClient &)=delete
 
HttpClient & operator= (const HttpClient &)=delete
 
bool start ()
 
bool request (std::string_view method, std::string_view target, std::string_view extra_headers, std::string_view body, HttpResponseCallback cb)
 Queues a request.
 
bool request (std::string_view method, HttpTargetMaker make_target, std::string_view extra_headers, std::string_view body, HttpResponseCallback cb)
 The same, with the target made by make_target when the request is written rather than now: a request waiting behind others (one in flight per connection) carries what is true when it leaves, such as a signed query's timestamp, which the venue checks against a window.
 
void close () noexcept
 Tears the connection down; every queued/in-flight request gets NetError::Canceled.
 
HttpClientState state () const noexcept
 
bool is_ready () const noexcept
 
bool in_flight () const noexcept
 
std::size_t queued () const noexcept
 
void set_max_queue (std::size_t n) noexcept
 Requests queued already stay queued when this is lowered below their number.
 
const HttpClientStats & stats () const noexcept
 
Stream & stream () noexcept
 
void on_readable () override
 
void on_writable () override
 
void on_error (int) override
 POLLERR (or a poll request the kernel refused).
 
- Public Member Functions inherited from fastmm::net::IoHandler
virtual ~IoHandler ()=default
 

Constructor & Destructor Documentation

◆ HttpClient() [1/2]

template<ByteStream Stream>
fastmm::net::HttpClient< Stream >::HttpClient ( Reactor &  reactor,
Stream &&  stream,
std::string  host,
std::uint16_t  port,
bool  tls,
const HttpClientConfig &  cfg = {} 
)
inline

◆ ~HttpClient()

template<ByteStream Stream>
fastmm::net::HttpClient< Stream >::~HttpClient ( )
inlineoverride

◆ HttpClient() [2/2]

template<ByteStream Stream>
fastmm::net::HttpClient< Stream >::HttpClient ( const HttpClient< Stream > &  )
delete

Member Function Documentation

◆ operator=()

template<ByteStream Stream>
HttpClient & fastmm::net::HttpClient< Stream >::operator= ( const HttpClient< Stream > &  )
delete

◆ start()

template<ByteStream Stream>
bool fastmm::net::HttpClient< Stream >::start ( )
inline

The connect and the TLS handshake are bounded like a request: a peer that accepts the TCP connection and never answers the ClientHello would otherwise hold every request queued.

◆ request() [1/2]

template<ByteStream Stream>
bool fastmm::net::HttpClient< Stream >::request ( std::string_view  method,
std::string_view  target,
std::string_view  extra_headers,
std::string_view  body,
HttpResponseCallback  cb 
)
inline

Queues a request.

extra_headers is a pre-formatted "Name: value\\r\\n" block. Returns false if the client is closed or the queue is full (callback not invoked).

◆ request() [2/2]

template<ByteStream Stream>
bool fastmm::net::HttpClient< Stream >::request ( std::string_view  method,
HttpTargetMaker  make_target,
std::string_view  extra_headers,
std::string_view  body,
HttpResponseCallback  cb 
)
inline

The same, with the target made by make_target when the request is written rather than now: a request waiting behind others (one in flight per connection) carries what is true when it leaves, such as a signed query's timestamp, which the venue checks against a window.

◆ close()

template<ByteStream Stream>
void fastmm::net::HttpClient< Stream >::close ( )
inlinenoexcept

Tears the connection down; every queued/in-flight request gets NetError::Canceled.

◆ state()

template<ByteStream Stream>
HttpClientState fastmm::net::HttpClient< Stream >::state ( ) const
inlinenoexcept

◆ is_ready()

template<ByteStream Stream>
bool fastmm::net::HttpClient< Stream >::is_ready ( ) const
inlinenoexcept

◆ in_flight()

template<ByteStream Stream>
bool fastmm::net::HttpClient< Stream >::in_flight ( ) const
inlinenoexcept

◆ queued()

template<ByteStream Stream>
std::size_t fastmm::net::HttpClient< Stream >::queued ( ) const
inlinenoexcept

◆ set_max_queue()

template<ByteStream Stream>
void fastmm::net::HttpClient< Stream >::set_max_queue ( std::size_t  n)
inlinenoexcept

Requests queued already stay queued when this is lowered below their number.

◆ stats()

template<ByteStream Stream>
const HttpClientStats & fastmm::net::HttpClient< Stream >::stats ( ) const
inlinenoexcept

◆ stream()

template<ByteStream Stream>
Stream & fastmm::net::HttpClient< Stream >::stream ( )
inlinenoexcept

◆ on_readable()

template<ByteStream Stream>
void fastmm::net::HttpClient< Stream >::on_readable ( )
inlineoverridevirtual

◆ on_writable()

template<ByteStream Stream>
void fastmm::net::HttpClient< Stream >::on_writable ( )
inlineoverridevirtual

◆ on_error()

template<ByteStream Stream>
void fastmm::net::HttpClient< Stream >::on_error ( int  err)
inlineoverridevirtual

POLLERR (or a poll request the kernel refused).

err is the socket's SO_ERROR when retrievable (the refused request's errno for the latter), else 0.

Implements fastmm::net::IoHandler.