rippled
Loading...
Searching...
No Matches
Session.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_SERVER_SESSION_H_INCLUDED
21#define RIPPLE_SERVER_SESSION_H_INCLUDED
22
23#include <xrpl/beast/net/IPEndpoint.h>
24#include <xrpl/beast/utility/Journal.h>
25#include <xrpl/server/WSSession.h>
26#include <xrpl/server/Writer.h>
27
28#include <boost/beast/http/message.hpp>
29
30#include <functional>
31#include <memory>
32#include <ostream>
33#include <vector>
34
35namespace ripple {
36
43{
44public:
45 Session() = default;
46 Session(Session const&) = delete;
47 Session&
48 operator=(Session const&) = delete;
49 virtual ~Session() = default;
50
55 void* tag = nullptr;
56
58 virtual beast::Journal
59 journal() = 0;
60
62 virtual Port const&
63 port() = 0;
64
68
70 virtual http_request_type&
71 request() = 0;
72
75 void
77 {
78 if (!s.empty())
79 write(&s[0], std::distance(s.begin(), s.end()));
80 }
81
82 template <typename BufferSequence>
83 void
84 write(BufferSequence const& buffers)
85 {
86 for (typename BufferSequence::const_iterator iter(buffers.begin());
87 iter != buffers.end();
88 ++iter)
89 {
90 typename BufferSequence::value_type const& buffer(*iter);
91 write(buffer.data(), boost::asio::buffer_size(buffer));
92 }
93 }
94
95 virtual void
96 write(void const* buffer, std::size_t bytes) = 0;
97
98 virtual void
99 write(std::shared_ptr<Writer> const& writer, bool keep_alive) = 0;
100
109 detach() = 0;
110
117 virtual void
118 complete() = 0;
119
125 virtual void
126 close(bool graceful) = 0;
127
131};
132
133} // namespace ripple
134
135#endif
T begin(T... args)
A version-independent IP address and port combination.
Definition IPEndpoint.h:38
A generic endpoint for log messages.
Definition Journal.h:60
Persistent state information for a connection session.
Definition Session.h:43
virtual std::shared_ptr< WSSession > websocketUpgrade()=0
Convert the connection to WebSocket.
virtual beast::IP::Endpoint remoteAddress()=0
Returns the remote address of the connection.
virtual Port const & port()=0
Returns the Port settings for this connection.
virtual std::shared_ptr< Session > detach()=0
Detach the session.
Session(Session const &)=delete
virtual void close(bool graceful)=0
Close the session.
virtual http_request_type & request()=0
Returns the current HTTP request.
virtual ~Session()=default
virtual void write(std::shared_ptr< Writer > const &writer, bool keep_alive)=0
void write(std::string const &s)
Send a copy of data asynchronously.
Definition Session.h:76
void * tag
A user-definable pointer.
Definition Session.h:55
virtual beast::Journal journal()=0
Returns the Journal to use for logging.
void write(BufferSequence const &buffers)
Definition Session.h:84
Session & operator=(Session const &)=delete
virtual void write(void const *buffer, std::size_t bytes)=0
virtual void complete()=0
Indicate that the response is complete.
Session()=default
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:25
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition Handoff.h:33
Configuration information for a Server listening port.
Definition Port.h:50