-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathechoserver_movable.hpp
47 lines (41 loc) · 1.28 KB
/
echoserver_movable.hpp
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
//
// Copyright (c) 2022 Youyuan Wu
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "boost/asio.hpp"
#include "boost/winasio/named_pipe/named_pipe_protocol.hpp"
#include "echoserver_session.hpp"
#include <cstdlib>
#include <iostream>
#include <memory>
#include <utility>
// Used as example and testing
class server_movable {
public:
server_movable(
net::io_context &io_context,
winnet::named_pipe_protocol<net::io_context::executor_type>::endpoint ep)
: acceptor_(io_context, ep) {
do_accept();
}
private:
void do_accept() {
std::cout << "do_accept" << std::endl;
acceptor_.async_accept(
[this](boost::system::error_code ec,
winnet::named_pipe_protocol<net::io_context::executor_type>::pipe
socket) {
if (!ec) {
std::cout << "do_accept handler ok. making session" << std::endl;
std::make_shared<session>(std::move(socket))->start();
} else {
std::cout << "accept handler error: " << ec.message() << std::endl;
}
do_accept();
});
}
winnet::named_pipe_protocol<net::io_context::executor_type>::acceptor
acceptor_;
};