connection.h
1 // Copyright 2020, Beeri 15. All rights reserved.
2 // Author: Roman Gershman (romange@gmail.com)
3 //
4 #pragma once
5 
6 #include <boost/intrusive/slist.hpp>
7 #include <functional>
8 #include "util/uring/fiber_socket.h"
9 
10 namespace util {
11 namespace uring {
12 
13 class Proactor;
14 class ListenerInterface;
15 
16 class Connection {
17  using connection_hook_t = ::boost::intrusive::slist_member_hook<
18  ::boost::intrusive::link_mode<::boost::intrusive::normal_link>>;
19  connection_hook_t hook_;
20 
21 
22  void SetSocket(FiberSocket&& s) { socket_ = std::move(s); }
23 
24  auto native_handle() const { return socket_.native_handle(); }
25 
26  public:
27  using member_hook_t =
28  ::boost::intrusive::member_hook<Connection, connection_hook_t, &Connection::hook_>;
29 
30  virtual ~Connection() {}
31 
32  protected:
33 
34  // The main loop for a connection. Runs in the same proactor thread as of socket_.
35  virtual void HandleRequests() = 0;
36 
37  FiberSocket socket_;
38  friend class ListenerInterface;
39 };
40 
41 } // namespace uring
42 } // namespace util
Abstracts away connections implementation and their life-cycle.
Definition: accept_server.h:69