-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.hpp
50 lines (36 loc) · 1.13 KB
/
Client.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
48
49
50
#pragma once
#ifndef CLIENT_HPP
#define CLIENT_HPP
#include "Sockets.hpp"
namespace SocketTCP
{
namespace Client
{
class Client
{
SocketAddr_in address_;
Socket socket_;
mutex handle_mutex_;
std::function<void(DataBuffer)> handler_;
std::jthread thread;
u32 timeout_;
ClientSocketStatus status_ = ClientSocketStatus::kDisconnected;
void handle();
public:
using HandlerFunctionType = std::function<void(DataBuffer)>;
Client() noexcept;
~Client();
ClientSocketStatus connectTo(u32 host, u16 port) noexcept;
ClientSocketStatus disconnect() noexcept;
u32 getHost() const;
u16 getPort() const;
ClientSocketStatus getStatus() const { return status_; }
DataBuffer loadData();
bool setHandler(HandlerFunctionType handler);
void joinHandler();
bool sendData(const string& data) const;
ISocketCalls* sockets = new SocketCalls();
};
}
}
#endif // !CLIENT_HPP