Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split recipe03 in chapter06 into two
- Loading branch information
Showing
11 changed files
with
211 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Helper heade file | ||
extern bool g_authed; | ||
const unsigned short g_port_num = 65001; | ||
|
||
void send_auth(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Chapter06/04_tasks_processor_network_accept/04_tasks_processor_network_accept.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
if (!include(../../config.txt)) { | ||
error("Failed to open config.txt") | ||
} | ||
|
||
HEADERS += \ | ||
../01_tasks_processor_base/tasks_processor_base.hpp \ | ||
../02_tasks_processor_timers/tasks_processor_timers.hpp \ | ||
../03_tasks_processor_network_client/tasks_processor_network_client.hpp \ | ||
../03_tasks_processor_network_client/client.hpp \ | ||
04_tasks_processor_network_accept.hpp | ||
|
||
SOURCES += \ | ||
../03_tasks_processor_network_client/client.cpp \ | ||
main.cpp | ||
|
||
QMAKE_CXXFLAGS += $$CPP11FLAG | ||
!msvc:LIBS += -lboost_thread -lboost_system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.