Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
http
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
>
21
#include <
toolbox/net/StreamAcceptor.hpp
>
22
23
namespace
toolbox
{
24
inline
namespace
http {
25
26
template
<
typename
ConnT,
typename
AppT>
27
class
BasicServ
:
public
StreamAcceptor
<BasicServ<ConnT, AppT>> {
28
29
friend
StreamAcceptor<BasicServ<ConnT, AppT>
>;
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
38
using
typename
StreamAcceptor<BasicServ<ConnT, AppT>
>::Endpoint;
39
40
public
:
41
BasicServ
(
CyclTime
/*now*/
,
Reactor
&
r
,
const
Endpoint&
ep
, App&
app
)
42
:
StreamAcceptor
<
BasicServ
<
ConnT
,
AppT
>>{
r
,
ep
}
43
, reactor_{
r
}
44
, app_{
app
}
45
{
46
}
47
~BasicServ
()
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
;
59
BasicServ
&
operator=
(
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
75
using
Serv
=
BasicServ<Conn, App>
;
76
77
}
// namespace http
78
}
// namespace toolbox
79
80
#endif
// TOOLBOX_HTTP_SERV_HPP
Conn.hpp
StreamAcceptor.hpp
toolbox::App
Definition
App.hpp:28
toolbox::BasicConn
Definition
Conn.hpp:36
toolbox::http::BasicConn::list_hook
boost::intrusive::list_member_hook< AutoUnlinkOption > list_hook
Definition
Conn.hpp:78
toolbox::BasicServ
Definition
Serv.hpp:27
toolbox::http::BasicServ::BasicServ
BasicServ(CyclTime, Reactor &r, const Endpoint &ep, App &app)
Definition
Serv.hpp:41
toolbox::http::BasicServ::BasicServ
BasicServ(BasicServ &&)=delete
toolbox::http::BasicServ::BasicServ
BasicServ(const BasicServ &)=delete
toolbox::http::BasicServ::~BasicServ
~BasicServ()
Definition
Serv.hpp:47
toolbox::http::BasicServ::operator=
BasicServ & operator=(const BasicServ &)=delete
toolbox::http::BasicServ::operator=
BasicServ & operator=(BasicServ &&)=delete
toolbox::Reactor
Definition
Reactor.hpp:34
toolbox::StreamAcceptor
Definition
StreamAcceptor.hpp:27
toolbox::CyclTime
Definition
Time.hpp:126
toolbox::util::bind
constexpr auto bind() noexcept
Definition
Slot.hpp:92
toolbox
Definition
Benchmark.cpp:26
toolbox::IoSock
Definition
IoSock.hpp:27
Generated by
1.9.8