forked from fastio/1store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.hh
99 lines (96 loc) · 3 KB
/
server.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Pedis is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* Copyright (c) 2016-2026, Peng Jian, pstack@163.com. All rights reserved.
*
*/
#pragma once
#include "redis.hh"
#include "db.hh"
#include "redis.hh"
#include "core/metrics_registration.hh"
#include "core/thread.hh"
#include "reply_wrapper.hh"
#include "protocol_parser.hh"
namespace redis {
class server {
public:
lw_shared_ptr<server_socket> _listener;
uint16_t _port;
bool _use_native_parser;
struct connection {
static constexpr size_t reply_queue_size = 16;
connected_socket _socket;
socket_address _addr;
input_stream<char> _in;
output_stream<char> _out;
protocol_parser _parser;
bool _done = false;
bool _use_native_parser;
queue<reply_wrapper> _replies { reply_queue_size };
future<> process()
{
// Luanch request & reply fiblers simultaneously.
return when_all(request(), reply()).then([] (std::tuple<future<>, future<>> joined) {
std::get<0>(joined).ignore_ready_future();
std::get<1>(joined).ignore_ready_future();
return make_ready_future<>();
});
}
future<scattered_message_ptr> handle();
future<scattered_message_ptr> do_handle_one(request_wrapper& req);
future<scattered_message_ptr> do_unexpect_request(request_wrapper& req);
future<> request();
future<> reply();
connection(connected_socket&& socket, socket_address addr, bool use_native_parser)
: _socket(std::move(socket))
, _addr(addr)
, _in(_socket.input())
, _out(_socket.output())
, _parser(make_ragel_protocol_parser())
{
}
~connection() {
}
};
seastar::metrics::metric_groups _metrics;
void setup_metrics();
struct stats {
uint64_t _connections_current = 0;
uint64_t _connections_total = 0;
};
stats _stats;
public:
server(uint16_t port = 6379, bool use_native_parser = false)
: _port(port)
, _use_native_parser(use_native_parser)
{
setup_metrics();
}
void start();
future<> stop() {
return make_ready_future<>();
}
};
extern distributed<server> _server;
inline distributed<server>& get_server() {
return _server;
}
inline server& get_local_server() {
return _server.local();
}
} /* namespace redis */