Seastar
High performance C++ framework for concurrent servers
server.hh
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
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,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18/*
19 * Copyright 2021 ScyllaDB
20 */
21
22#pragma once
23
24#include <map>
25
26#include <seastar/http/request_parser.hh>
27#include <seastar/core/seastar.hh>
28#include <seastar/core/sstring.hh>
29#include <seastar/core/gate.hh>
30#include <seastar/core/queue.hh>
31#include <seastar/core/when_all.hh>
32#include <seastar/websocket/common.hh>
33
34namespace seastar::experimental::websocket {
35
38
43
44 server& _server;
45 http_request_parser _http_parser;
46
47public:
53 : connection(std::move(fd))
54 , _server(server) {
55 on_new_connection();
56 }
58
63
64protected:
65 future<> read_loop();
66 future<> read_http_upgrade_request();
67 void on_new_connection();
68};
69
76class server {
77 std::vector<server_socket> _listeners;
78 boost::intrusive::list<server_connection> _connections;
79 std::map<std::string, handler_t> _handlers;
80 gate _task_gate;
81public:
93
98
99 bool is_handler_registered(std::string const& name);
100
107 void register_handler(const std::string& name, handler_t handler);
108
109 friend class server_connection;
110protected:
111 void accept(server_socket &listener);
112 future<stop_iteration> accept_one(server_socket &listener);
113};
114
116
117}
Definition: api.hh:183
a server WebSocket connection
Definition: common.hh:58
a server WebSocket connection
Definition: server.hh:42
a WebSocket server
Definition: server.hh:76
A representation of a possibly not-yet-computed value.
Definition: future.hh:1219
Definition: gate.hh:61
A listening socket, waiting to accept incoming network connections.
Definition: api.hh:326
Definition: socket_defs.hh:47
future process()
serve WebSocket protocol on a server_connection
void listen(socket_address addr)
listen for a WebSocket connection on given address
void register_handler(const std::string &name, handler_t handler)
Register a handler for specific subprotocol.
void listen(socket_address addr, listen_options lo)
listen for a WebSocket connection on given address with custom options
server_connection(server &server, connected_socket &&fd)
Definition: server.hh:52
STL namespace.
Definition: api.hh:397