forked from domoticz/domoticz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCPClient.h
58 lines (44 loc) · 1.29 KB
/
TCPClient.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
55
56
57
58
#pragma once
#include "../main/Noncopyable.h"
#include <boost/asio.hpp>
namespace tcp {
namespace server {
class CTCPServerIntBase;
class CTCPClientBase :
private domoticz::noncopyable
{
public:
explicit CTCPClientBase(CTCPServerIntBase *pManager);
~CTCPClientBase();
virtual void start() = 0;
virtual void stop() = 0;
virtual void write(const char *pData, size_t Length) = 0;
std::string m_username;
std::string m_endpoint;
bool m_bIsLoggedIn;
// usual tcp parameters
boost::asio::ip::tcp::socket *socket() { return socket_; }
protected:
/// The manager for this connection.
CTCPServerIntBase *pConnectionManager;
// usual tcp parameters
boost::asio::ip::tcp::socket *socket_;
};
class CTCPClient : public CTCPClientBase,
public std::enable_shared_from_this<CTCPClient>
{
public:
CTCPClient(boost::asio::io_service& ios, CTCPServerIntBase *pManager);
~CTCPClient() = default;
void start() override;
void stop() override;
void write(const char *pData, size_t Length) override;
private:
void handleRead(const boost::system::error_code& error, size_t length);
void handleWrite(const boost::system::error_code& error);
/// Buffer for incoming data.
std::array<char, 8192> buffer_;
};
typedef std::shared_ptr<CTCPClientBase> CTCPClient_ptr;
} // namespace server
} // namespace tcp