-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathudpclient.cpp
More file actions
82 lines (70 loc) · 1.8 KB
/
udpclient.cpp
File metadata and controls
82 lines (70 loc) · 1.8 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "udpclient.h"
UDPClient::UDPClient(Socket& socket, const std::string& ip, unsigned short port):socket(socket)
{
this->port = port;
this->ip = ip;
transfer.setRecieveFunction([&](Buffer& buff, size_t size)
{
std::string ip;
unsigned short port;
return this->socket.RecieveFrom(buff, size, ip, port);
});
transfer.setSendFunction([&](Buffer& buff, size_t size)
{
return this->socket.SendTo(buff, size, this->ip, this->port);
});
}
OperationResult UDPClient::Send(size_t size, Buffer& buff, bool confirm)
{
if (confirm)
transfer.Start(TransferType::Send, size, genericConfirmCondition);
else
transfer.Start(TransferType::Send, size, false);
return transfer.Execute(buff);
}
OperationResult UDPClient::Send(size_t size, bool confirm)
{
return Send(size, state->buff, confirm);
}
OperationResult UDPClient::Recieve(size_t size, Buffer& buff, bool confirm)
{
if (confirm)
transfer.Start(TransferType::Recieve, size, genericConfirmCondition);
else
transfer.Start(TransferType::Recieve, size, false);
return transfer.Execute(buff);
}
OperationResult UDPClient::Recieve(size_t size, bool confirm)
{
return Recieve(size, state->buff, confirm);
}
OperationResult UDPClient::Peek(size_t size, Buffer& buff)
{
std::string ip;
unsigned short port;
return this->socket.RecieveFrom(buff, size, ip, port, true);
}
OperationResult UDPClient::Peek(size_t size)
{
return Peek(size, state->buff);
}
Socket& UDPClient::getSocket()
{
return socket;
}
bool UDPClient::isReachable()
{
return true;
}
void UDPClient::endTransfer()
{
transfer.End();
}
void UDPClient::setIp(const std::string& ip)
{
this->ip = ip;
}
void UDPClient::setPort(unsigned short port)
{
this->port = port;
}