xrpld
Loading...
Searching...
No Matches
Session.h
1#pragma once
2
3#include <xrpl/beast/net/IPEndpoint.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/server/WSSession.h>
6#include <xrpl/server/Writer.h>
7
8#include <boost/beast/http/message.hpp>
9
10#include <functional>
11#include <memory>
12#include <ostream>
13#include <string_view>
14#include <vector>
15
16namespace xrpl {
17
24{
25public:
26 Session() = default;
27 Session(Session const&) = delete;
28 Session&
29 operator=(Session const&) = delete;
30 virtual ~Session() = default;
31
36 void* tag = nullptr;
37
39 virtual beast::Journal
40 journal() = 0;
41
43 virtual Port const&
44 port() = 0;
45
49
51 virtual http_request_type&
52 request() = 0;
53
56 void
58 {
59 if (!s.empty())
60 write(s.data(), s.size());
61 }
62
63 template <typename BufferSequence>
64 void
65 write(BufferSequence const& buffers)
66 {
67 for (typename BufferSequence::const_iterator iter(buffers.begin()); iter != buffers.end();
68 ++iter)
69 {
70 typename BufferSequence::value_type const& buffer(*iter);
71 write(buffer.data(), boost::asio::buffer_size(buffer));
72 }
73 }
74
75 virtual void
76 write(void const* buffer, std::size_t bytes) = 0;
77
78 virtual void
79 write(std::shared_ptr<Writer> const& writer, bool keepAlive) = 0;
80
82
89 detach() = 0;
90
97 virtual void
98 complete() = 0;
99
105 virtual void
106 close(bool graceful) = 0;
107
111};
112
113} // namespace xrpl
A version-independent IP address and port combination.
Definition IPEndpoint.h:17
A generic endpoint for log messages.
Definition Journal.h:38
virtual void write(std::shared_ptr< Writer > const &writer, bool keepAlive)=0
virtual beast::Journal journal()=0
Returns the Journal to use for logging.
Session(Session const &)=delete
virtual Port const & port()=0
Returns the Port settings for this connection.
virtual void write(void const *buffer, std::size_t bytes)=0
virtual void close(bool graceful)=0
Close the session.
virtual std::shared_ptr< Session > detach()=0
Detach the session.
void write(BufferSequence const &buffers)
Definition Session.h:65
void write(std::string_view s)
Send a copy of data asynchronously.
Definition Session.h:57
virtual beast::IP::Endpoint remoteAddress()=0
Returns the remote address of the connection.
Session()=default
virtual void complete()=0
Indicate that the response is complete.
virtual http_request_type & request()=0
Returns the current HTTP request.
virtual ~Session()=default
Session & operator=(Session const &)=delete
virtual std::shared_ptr< WSSession > websocketUpgrade()=0
Convert the connection to WebSocket.
void * tag
A user-definable pointer.
Definition Session.h:36
T data(T... args)
T empty(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition Handoff.h:12
T size(T... args)
Configuration information for a Server listening port.
Definition Port.h:28