-
Notifications
You must be signed in to change notification settings - Fork 107
/
client.cpp
54 lines (45 loc) · 1.34 KB
/
client.cpp
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
// Big part of code for this recipe
// in in this header:
#include "tasks_processor_network_client.hpp"
#include "client.hpp"
using namespace tp_network_client;
bool g_authed = false;
void process_server_response(
connection_ptr&& soc,
const boost::system::error_code& err)
{
if (err && err != boost::asio::error::eof) {
std::cerr << "process_server_response: Client error on receive: " << err.message() << '\n';
assert(false);
}
if (soc->data.size() != 2) {
std::cerr << "process_server_response: wrong bytes count\n";
assert(false);
}
if (soc->data != "OK") {
std::cerr << "process_server_response: wrong response: " << soc->data << '\n';
assert(false);
}
g_authed = true;
soc->shutdown();
tasks_processor::stop();
}
void receive_auth_response(connection_ptr&& soc, const boost::system::error_code& err) {
if (err) {
std::cerr << "receive_auth_response: error on sending data: " << err.message() << '\n';
assert(false);
}
async_read_data(
std::move(soc),
&process_server_response,
2
);
}
void send_auth() {
connection_ptr soc = tasks_processor::create_connection("127.0.0.1", g_port_num);
soc->data = "auth_name";
async_write_data(
std::move(soc),
&receive_auth_response
);
}