rippled
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 <vector>
14
15namespace xrpl {
16
23{
24public:
25 Session() = default;
26 Session(Session const&) = delete;
27 Session&
28 operator=(Session const&) = delete;
29 virtual ~Session() = default;
30
35 void* tag = nullptr;
36
38 virtual beast::Journal
39 journal() = 0;
40
42 virtual Port const&
43 port() = 0;
44
48
50 virtual http_request_type&
51 request() = 0;
52
55 void
57 {
58 if (!s.empty())
59 write(&s[0], std::distance(s.begin(), s.end()));
60 }
61
62 template <typename BufferSequence>
63 void
64 write(BufferSequence const& buffers)
65 {
66 for (typename BufferSequence::const_iterator iter(buffers.begin()); iter != buffers.end(); ++iter)
67 {
68 typename BufferSequence::value_type const& buffer(*iter);
69 write(buffer.data(), boost::asio::buffer_size(buffer));
70 }
71 }
72
73 virtual void
74 write(void const* buffer, std::size_t bytes) = 0;
75
76 virtual void
77 write(std::shared_ptr<Writer> const& writer, bool keep_alive) = 0;
78
87 detach() = 0;
88
95 virtual void
96 complete() = 0;
97
103 virtual void
104 close(bool graceful) = 0;
105
109};
110
111} // namespace xrpl
T begin(T... args)
A version-independent IP address and port combination.
Definition IPEndpoint.h:18
A generic endpoint for log messages.
Definition Journal.h:40
Persistent state information for a connection session.
Definition Session.h:23
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:64
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 void write(std::shared_ptr< Writer > const &writer, bool keep_alive)=0
virtual ~Session()=default
Session & operator=(Session const &)=delete
virtual std::shared_ptr< WSSession > websocketUpgrade()=0
Convert the connection to WebSocket.
void write(std::string const &s)
Send a copy of data asynchronously.
Definition Session.h:56
void * tag
A user-definable pointer.
Definition Session.h:35
T distance(T... args)
T empty(T... args)
T end(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
Configuration information for a Server listening port.
Definition Port.h:30