-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathkcptun_client.h
54 lines (46 loc) · 1.42 KB
/
kcptun_client.h
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
#ifndef KCPTUN_KCPTUN_CLIENT_H
#define KCPTUN_KCPTUN_CLIENT_H
#include "config.h"
#include "encrypt.h"
#include "local.h"
#include "smux.h"
class snappy_stream_writer;
class snappy_stream_reader;
class kcptun_client_session final
: public std::enable_shared_from_this<kcptun_client_session>,
public kvar_,
public Destroy {
public:
kcptun_client_session(asio::io_service &io_service,
std::shared_ptr<asio::ip::tcp::socket> sock,
std::shared_ptr<smux_sess> sess);
~kcptun_client_session();
void run();
private:
void do_pipe1();
void do_pipe2();
void call_this_on_destroy() override;
private:
char buf1_[4096];
char buf2_[4096];
asio::io_service &service_;
std::shared_ptr<asio::ip::tcp::socket> sock_;
std::shared_ptr<smux_sess> sess_;
};
class kcptun_client final : public std::enable_shared_from_this<kcptun_client> {
public:
kcptun_client(asio::io_service &io_service,
asio::ip::tcp::endpoint local_endpoint,
asio::ip::udp::endpoint target_endpoint);
void run();
private:
void do_accept();
void async_choose_local(std::function<void(std::shared_ptr<Local>)> f);
private:
asio::io_service &service_;
asio::ip::tcp::socket socket_;
asio::ip::udp::endpoint target_endpoint_;
asio::ip::tcp::acceptor acceptor_;
std::vector<std::weak_ptr<Local>> locals_;
};
#endif