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/server/Writer.h>
24 #include <ripple/server/WSSession.h>
25 #include <boost/beast/http/message.hpp>
26 #include <ripple/beast/net/IPEndpoint.h>
27 #include <ripple/beast/utility/Journal.h>
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& operator=(Session const&) = delete;
46  virtual ~Session () = default;
47 
52  void* tag = nullptr;
53 
55  virtual
57  journal() = 0;
58 
60  virtual
61  Port const&
62  port() = 0;
63 
65  virtual
67  remoteAddress() = 0;
68 
70  virtual
72  request() = 0;
73 
76  void
77  write (std::string const& s)
78  {
79  if (! s.empty())
80  write (&s[0],
81  std::distance (s.begin(), s.end()));
82  }
83 
84  template <typename BufferSequence>
85  void
86  write (BufferSequence const& buffers)
87  {
88  for (typename BufferSequence::const_iterator iter (buffers.begin());
89  iter != buffers.end(); ++iter)
90  {
91  typename BufferSequence::value_type const& buffer (*iter);
92  write (boost::asio::buffer_cast <void const*> (buffer),
93  boost::asio::buffer_size (buffer));
94  }
95  }
96 
97  virtual
98  void
99  write (void const* buffer, std::size_t bytes) = 0;
100 
101  virtual
102  void
103  write (std::shared_ptr <Writer> const& writer,
104  bool keep_alive) = 0;
105 
113  virtual
115  detach() = 0;
116 
123  virtual
124  void
125  complete() = 0;
126 
132  virtual
133  void
134  close (bool graceful) = 0;
135 
137  virtual
139  websocketUpgrade() = 0;
140 };
141 
142 } // ripple
143 
144 #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
ripple::http_request_type
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition: Handoff.h:31
vector
ripple::Session::Session
Session()=default
std::distance
T distance(T... args)
ripple::Session::tag
void * tag
A user-definable pointer.
Definition: Session.h:52
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:77
ripple::Session::write
void write(BufferSequence const &buffers)
Definition: Session.h:86
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:60
ripple::Session::operator=
Session & operator=(Session const &)=delete
ripple::Port
Configuration information for a Server listening port.
Definition: Port.h:38
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:39
std::string::end
T end(T... args)
ostream