-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcp_server.hpp
More file actions
35 lines (26 loc) · 749 Bytes
/
tcp_server.hpp
File metadata and controls
35 lines (26 loc) · 749 Bytes
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
#pragma once
#include <functional>
#include <memory>
#include "tcp_socket.hpp"
/// a simple TCP server:
/// - accepts all connections
/// - calls the registered callback when a new connection is accepted
/// - the callback will be passed an instance of tcp_socket
/// - the callback will happen in a thread context owned by server
class tcp_server
{
public:
using callback_t = std::function<void(tcp_socket&&)>;
tcp_server();
~tcp_server();
/// start listening
bool start(uint16_t port);
bool stop();
/// are we running?
bool is_running() const;
/// set callback to be invoked on client connections
void set_callback(callback_t callback);
private:
class impl;
std::unique_ptr<impl> _impl;
};