asio::
namespace, while Boost.Asio is defined in boost::asio::
asio.hpp
and boost/asio.hpp
in Boost.Asioboost::thread
)asio::error_code
instead of boost::system::error_cod
and asio::system_error
instead of boost::system::system_error
)BOOST_ASIO_ENABLE_HANDLER_TRACKING
macro is BOOST_ASIO_ENABLE_HANDLER_TRACKING
. If this is the case, then Boost.Asio contributes to the output of information to the standard error output stream, recording the time, asynchronous operation and, related to it, the final handler. @asio|<timestamp>|<action>|<description>.
@asio
, you can use it to easily filter messages coming from Boost.Asio in case other sources write to the standard error stream (equivalent to std::cerr
). The timestamp
instance is counted in seconds and microseconds, starting January 1, 1970 UTC. An action
instance can be one of the following:>n
: used when we enter handler number n. The description
instance contains the arguments passed to the handler.<n
: Used when handler number n is closed.!n
: used when we left handler n due to an exception.~n
: used when handler number n is destroyed without a call; probably because the io_service
instance is io_service
destroyed too early (before n gets a chance to call out).n*m
: used when handler n creates a new asynchronous operation with a trailing handler numbered m. After the start, the started asynchronous operation will be displayed in the description
instance. The final handler will be called when you see >m(start)
and <m(end)
.n
: used when handler number n performs an operation that is displayed on description
(which can be a close
or a cancel
operation). Usually, you can safely ignore them.!n
and ~n
, which occur when there are errors in the code. In the first case, the asynchronous function did not throw an exception, so the exception must be generated by you; you should not allow exceptions when exiting your final handler. In the latter case, you probably destroyed the io_service
instance too early, before all the called handlers were completed.#define
before enabling boost/asio.hpp
: #define BOOST_ASIO_ENABLE_HANDLER_TRACKING #include <boost/asio.hpp> ...
@asio|1355603116.602867|0*1|socket@008D4EF8.async_connect @asio|1355603116.604867|>1|ec=system:0 @asio|1355603116.604867|1*2|socket@008D4EF8.async_send @asio|1355603116.604867|<1| @asio|1355603116.604867|>2|ec=system:0,bytes_transferred=11 @asio|1355603116.604867|2*3|socket@008D4EF8.async_receive @asio|1355603116.604867|<2| @asio|1355603116.605867|>3|ec=system:0,bytes_transferred=9 @asio|1355603116.605867|3*4|io_service@008D4BC8.post @asio|1355603116.605867|<3| @asio|1355603116.605867|>4| John logged in @asio|1355603116.606867|4*5|io_service@008D4BC8.post @asio|1355603116.606867|<4| @asio|1355603116.606867|>5| @asio|1355603116.606867|5*6|socket@008D4EF8.async_send @asio|1355603116.606867|<5| @asio|1355603116.606867|>6|ec=system:0,bytes_transferred=12 @asio|1355603116.606867|6*7|socket@008D4EF8.async_receive @asio|1355603116.606867|<6| @asio|1355603116.606867|>7|ec=system:0,bytes_transferred=14 @asio|1355603116.606867|7*8|io_service@008D4BC8.post @asio|1355603116.607867|<7| @asio|1355603116.607867|>8| John, new client list: John
async_connect
, which creates handler 1 (in our case, everyone processes talk_to_svr::step
)async_send
, which creates handler 2 (here we send a message with login to the server)login John
)async_receive
, which creates handler 3 (we are waiting for the server to respond to our login message)login ok
)on_answer_from_server
(where handler 4 is created)John logged in
to the dump John logged in
step
(handler 5), which will write ask_clients
async_send
ask_clients
, creates handler 6ask_clients
(we have successfully sent ask_clients
server)async_receive
, which creates handler 7 (we are waiting for the server to send us a list of existing clients)on_answer_from_serve
(where handler 8 is created)on_clients
, and a list of clients is written to the dump ( on_clients
)std::cerr
). It is very likely that you will want to redirect this output to another location. On the one hand, by default, for console applications, the output and reset of errors occurs in one place, that is, in the console. But for Windows (non-console) applications, the default error flow is empty. some_application 2>err.txt
// for Windows HANDLE h = CreateFile("err.txt", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL , 0); SetStdHandle(STD_ERROR_HANDLE, h); // for Unix int err_file = open("err.txt", O_WRONLY); dup2(err_file, STDERR_FILENO);
OpenSSL
. So if you want to use SSL, first download and build OpenSSL . It should be noted that, as a rule, building OpenSSL
is no easy task, especially if you do not have popular compilers, such as Visual Studio.OpenSSL
, then Boost.Asio has some add-on classes over it:ssl::stream
: used instead of class ip::::socket
ssl::context
: this is the context for starting a sessionssl::rfc2818_verification
: this class is an easy way to verify a certificate for a host name in accordance with RFC 2818 rulesSource: https://habr.com/ru/post/197392/
All Articles