-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientCode.cpp
More file actions
59 lines (49 loc) · 1.53 KB
/
Copy pathClientCode.cpp
File metadata and controls
59 lines (49 loc) · 1.53 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
#include "ClientCode.h"
void ClientCode::start_receive()
{
socket.async_receive_from(
boost::asio::buffer(recvBuffer), recvEP,
boost::bind(&ClientCode::handle_receive, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}
const boost::array<unsigned char, 1> ClientCode::BufferFactory()
{
const boost::array<unsigned char, 1> immuBuffer = recvBuffer;
return immuBuffer;
}
void ClientCode::PushQueue(const boost::array<unsigned char, 1> bufferToPush)
{
std::lock_guard<std::mutex> lg(*mMutex);
bufferQueues->push(bufferToPush);
}
void ClientCode::handle_receive(const boost::system::error_code& error,
std::size_t /*bytes_transferred*/)
{
if (!error)
{
PushQueue(BufferFactory());
(bufferPointer->operator())();
start_receive();
}
}
void ClientCode::HandleSend(boost::shared_ptr<boost::array<unsigned char, 1>> /*message*/,
const boost::system::error_code& /*error*/,
std::size_t /*bytes_transferred*/)
{
}
void ClientCode::StartSend()
{
sendEP.address(boost::asio::ip::address::from_string("127.0.0.1"));
sendEP.port(23000);
boost::shared_ptr<boost::array<unsigned char, 1>> msg(new boost::array<unsigned char, 1>);
msg.get()->elems[0] = 254;
socket.async_send_to(boost::asio::buffer(msg.get(), 1), sendEP,
boost::bind(&ClientCode::HandleSend, this, msg,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}
boost::array<unsigned char, 1> ClientCode::getRecv_Buffer()
{
return recvBuffer;
}