rippled
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 <ripple/beast/net/IPEndpoint.h>
24 #include <ripple/beast/utility/Journal.h>
25 #include <ripple/server/WSSession.h>
26 #include <ripple/server/Writer.h>
27 #include <boost/beast/http/message.hpp>
28 #include <functional>
29 #include <memory>
30 #include <ostream>
31 #include <vector>
32 
33 namespace ripple {
34 
40 class Session
41 {
42 public:
43  Session() = default;
44  Session(Session const&) = delete;
45  Session&
46  operator=(Session const&) = delete;
47  virtual ~Session() = default;
48 
53  void* tag = nullptr;
54 
56  virtual beast::Journal
57  journal() = 0;
58 
60  virtual Port const&
61  port() = 0;
62 
64  virtual beast::IP::Endpoint
65  remoteAddress() = 0;
66 
68  virtual http_request_type&
69  request() = 0;
70 
73  void
74  write(std::string const& s)
75  {
76  if (!s.empty())
77  write(&s[0], std::distance(s.begin(), s.end()));
78  }
79 
80  template <typename BufferSequence>
81  void
82  write(BufferSequence const& buffers)
83  {
84  for (typename BufferSequence::const_iterator iter(buffers.begin());
85  iter != buffers.end();
86  ++iter)
87  {
88  typename BufferSequence::value_type const& buffer(*iter);
89  write(
90  boost::asio::buffer_cast<void const*>(buffer),
91  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 
130  websocketUpgrade() = 0;
131 };
132 
133 } // namespace ripple
134 
135 #endif
ripple::Session::~Session
virtual ~Session()=default
std::string
STL class.
std::shared_ptr
STL class.
ripple::Session::websocketUpgrade
virtual std::shared_ptr< WSSession > websocketUpgrade()=0
Convert the connection to WebSocket.
functional
vector
ripple::Session::Session
Session()=default
std::distance
T distance(T... args)
ripple::Session::tag
void * tag
A user-definable pointer.
Definition: Session.h:53
ripple::Session
Persistent state information for a connection session.
Definition: Session.h:40
ripple::Session::write
void write(std::string const &s)
Send a copy of data asynchronously.
Definition: Session.h:74
ripple::Session::write
void write(BufferSequence const &buffers)
Definition: Session.h:82
ripple::Session::remoteAddress
virtual beast::IP::Endpoint remoteAddress()=0
Returns the remote address of the connection.
ripple::Session::request
virtual http_request_type & request()=0
Returns the current HTTP request.
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::Session::operator=
Session & operator=(Session const &)=delete
ripple::Port
Configuration information for a Server listening port.
Definition: Port.h:48
ripple::Session::complete
virtual void complete()=0
Indicate that the response is complete.
ripple::Session::detach
virtual std::shared_ptr< Session > detach()=0
Detach the session.
memory
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std::string::begin
T begin(T... args)
ripple::Session::port
virtual Port const & port()=0
Returns the Port settings for this connection.
std::string::empty
T empty(T... args)
ripple::Session::close
virtual void close(bool graceful)=0
Close the session.
ripple::Session::journal
virtual beast::Journal journal()=0
Returns the Journal to use for logging.
std::size_t
beast::IP::Endpoint
A version-independent IP address and port combination.
Definition: IPEndpoint.h:38
std::string::end
T end(T... args)
ostream
ripple::http_request_type
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition: Handshake.h:47