lichao
2021-05-25 5d8aa35858eea622e0e8e4a1f111fd408c483a31
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
/*
 * =====================================================================================
 *
 *       Filename:  tcp_server.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2021年05月19日 15时06分01秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Li Chao (), lichao@aiotlink.com
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef TCP_SERVER_795VXR94
#define TCP_SERVER_795VXR94
 
#include "tcp_common.h"
#include <thread>
 
class TcpServer
{
public:
    explicit TcpServer(int port);
    ~TcpServer();
    bool Start();
    void Stop();
 
private:
    void Accept();
    std::thread worker_;
    std::atomic<bool> run_;
    boost::asio::io_context io_;
    tcp::acceptor listener_;
};
 
#endif // end of include guard: TCP_SERVER_795VXR94