Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Serv.hpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2022 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#ifndef TOOLBOX_HTTP_SERV_HPP
18#define TOOLBOX_HTTP_SERV_HPP
19
20#include <toolbox/http/Conn.hpp>
22
23namespace toolbox {
24inline namespace http {
25
26template <typename ConnT, typename AppT>
27class BasicServ : public StreamAcceptor<BasicServ<ConnT, AppT>> {
28
30
31 using Conn = ConnT;
32 using App = AppT;
33 using ConstantTimeSizeOption = boost::intrusive::constant_time_size<false>;
34 using MemberHookOption
35 = boost::intrusive::member_hook<Conn, decltype(Conn::list_hook), &Conn::list_hook>;
36 using ConnList = boost::intrusive::list<Conn, ConstantTimeSizeOption, MemberHookOption>;
37
39
40 public:
41 BasicServ(CyclTime /*now*/, Reactor& r, const Endpoint& ep, App& app)
43 , reactor_{r}
44 , app_{app}
45 {
46 }
48 {
49 const auto now = CyclTime::current();
50 conn_list_.clear_and_dispose([now](auto* conn) { conn->dispose(now); });
51 }
52
53 // Copy.
54 BasicServ(const BasicServ&) = delete;
55 BasicServ& operator=(const BasicServ&) = delete;
56
57 // Move.
58 BasicServ(BasicServ&&) = delete;
60
61 private:
62 void on_sock_prepare(CyclTime /*now*/, IoSock& /*sock*/) {}
63 void on_sock_accept(CyclTime now, IoSock&& sock, const Endpoint& ep)
64 {
65 auto* const conn = new Conn{now, reactor_, std::move(sock), ep, app_};
66 conn_list_.push_back(*conn);
67 }
68
69 Reactor& reactor_;
70 App& app_;
71 // List of active connections.
72 ConnList conn_list_;
73};
74
76
77} // namespace http
78} // namespace toolbox
79
80#endif // TOOLBOX_HTTP_SERV_HPP
boost::intrusive::list_member_hook< AutoUnlinkOption > list_hook
Definition Conn.hpp:78
BasicServ(CyclTime, Reactor &r, const Endpoint &ep, App &app)
Definition Serv.hpp:41
BasicServ(BasicServ &&)=delete
BasicServ(const BasicServ &)=delete
BasicServ & operator=(const BasicServ &)=delete
BasicServ & operator=(BasicServ &&)=delete
constexpr auto bind() noexcept
Definition Slot.hpp:92