{"id":196888,"date":"2013-10-09T10:10:03","date_gmt":"2013-10-09T06:10:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=196888"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=196888","title":{"rendered":"<span class=\"post_title\">\u00abBoost.Asio C++ Network Programming\u00bb. \u0413\u043b\u0430\u0432\u0430 6: \u2013 \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<br \/>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043a\u043d\u0438\u0433\u0438 John Torjo \u00abBoost.Asio C++ Network Programming\u00bb.<\/p>\n<p>  \u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435:  <\/p>\n<ul>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/192284\/\">\u0413\u043b\u0430\u0432\u0430 1: \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u044f \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Boost.Asio<\/a><\/li>\n<li>\u0413\u043b\u0430\u0432\u0430 2: \u041e\u0441\u043d\u043e\u0432\u044b Boost.Asio<br \/> \n<ul>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/193038\/\"> \u0427\u0430\u0441\u0442\u044c 1: \u041e\u0441\u043d\u043e\u0432\u044b Boost.Asio<\/a><\/li>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/195006\/\"> \u0427\u0430\u0441\u0442\u044c 2: \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/195386\/\">\u0413\u043b\u0430\u0432\u0430 3: Echo \u0421\u0435\u0440\u0432\u0435\u0440\/\u041a\u043b\u0438\u0435\u043d\u0442<\/a><\/li>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/195794\/\">\u0413\u043b\u0430\u0432\u0430 4: \u041a\u043b\u0438\u0435\u043d\u0442 \u0438 \u0421\u0435\u0440\u0432\u0435\u0440<\/a><\/li>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/196354\/\">\u0413\u043b\u0430\u0432\u0430 5: \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0442\u0438\u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e<\/a><\/li>\n<li><b>\u0413\u043b\u0430\u0432\u0430 6: Boost.Asio \u2013 \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438<\/b><\/li>\n<li>\u0413\u043b\u0430\u0432\u0430 7: Boost.Asio \u2013 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0435\u043c\u044b<\/li>\n<\/ul>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0433\u043b\u0430\u0432\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 Boost.Asio. \u041e\u0431\u044a\u0435\u043a\u0442\u044b std streams \u0438 streambuf \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438, \u043d\u043e, \u043a\u0430\u043a \u0432\u044b \u0441\u0430\u043c\u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0443 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0437\u0434\u043d\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 Boost.Asio \u2014 co-routines, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c \u0438\u043c\u0435\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 (\u043a\u0430\u043a \u0431\u0443\u0434-\u0442\u043e \u0431\u044b \u043e\u043d \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439). \u042d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h4>std \u043f\u043e\u0442\u043e\u043a\u0438 \u0438 std \u0431\u0443\u0444\u0435\u0440\u044b \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430<\/h4>\n<p>  \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043a\u0430\u043a STL streams \u0438 STL streambuf \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0432\u0435\u0449\u0438, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435.<br \/>  \u0412 Boost.Asio \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0442\u0438\u043f\u0430 \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u0432\u043e\u0434\u043e\u043c\/\u0432\u044b\u0432\u043e\u0434\u043e\u043c:  <\/p>\n<ul>\n<li> boost::asio::buffer()<\/li>\n<li> boost::asio::streambuf<\/li>\n<\/ul>\n<p>  \u041d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0439 \u043a\u043d\u0438\u0433\u0438 \u0432\u044b \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"cpp\">size_t read_complete(boost::system::error_code, size_t bytes){ ... } char buff[1024]; read(sock, buffer(buff), read_complete); write(sock, buffer(&quot;echo\\n&quot;)); <\/code><\/pre>\n<p>  \u041e\u0431\u044b\u0447\u043d\u043e \u0432\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u041d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438, \u0442\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>streambuf<\/code>. \u0412\u043e\u0442 \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438 \u0445\u0443\u0434\u0448\u0435\u0435, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c <code>streambuf<\/code>:<\/p>\n<pre><code class=\"cpp\">streambuf buf; read(sock, buf); <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0447\u0442\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0434\u0442\u0438 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 <code>streambuf<\/code>, \u0430 \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 streambuf \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0435\u0431\u044f, \u0447\u0442\u043e\u0431\u044b \u0432\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u0441\u0435\u0431\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043c\u0435\u0441\u0442\u0430, \u0442\u043e, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c, \u0447\u0442\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0434\u0442\u0438 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u043e. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>read_until<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0437\u043d\u0430\u043a\u0430:<\/p>\n<pre><code class=\"cpp\">streambuf buf; read_until(sock, buf, &quot;\\n&quot;); <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0447\u0442\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0434\u0442\u0438 \u0434\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u2018\\n\u2019, \u0437\u0430\u0442\u0435\u043c \u0432 \u0431\u0443\u0444\u0435\u0440 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u043e \u0438 \u0432\u044b\u0439\u0434\u0435\u0442 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0447\u0442\u0435\u043d\u0438\u044f. \u0427\u0442\u043e\u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 <code>streambuf <\/code>\u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u043e\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"cpp\">streambuf buf; std::ostream out(&buf); out &lt;&lt; &quot;echo&quot; &lt;&lt; std::endl; write(sock, buf); <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u0432\u0430\u043c \u043d\u0430\u0434\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a STL, \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0442\u0443\u0434\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 streambuf \u043f\u0440\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043d\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u0430 \u0437\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>write <\/code>\u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430.<\/p>\n<h4>Boost.Asio \u0438 \u043f\u043e\u0442\u043e\u043a\u0438 STL<\/h4>\n<p>  C Boost.Asio \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 STL \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0438 \u0441\u0435\u0442\u0435\u0439. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0443\u0436\u0435 \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 STL, \u0442\u043e \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438 &gt;&gt; \u0438 &lt;&lt;. \u0427\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0441\u043e\u043a\u0435\u0442\u044b \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0432\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043f\u0440\u043e\u0433\u0443\u043b\u043a\u0430 \u043f\u043e \u043f\u0430\u0440\u043a\u0443.<br \/>  \u0421\u043a\u0430\u0436\u0435\u043c, \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"cpp\">struct person  { \tstd::string first_name, last_name; \tint age; }; std::ostream& operator&lt;&lt;(std::ostream & out, const person & p)  { \treturn out &lt;&lt; p.first_name &lt;&lt; &quot; &quot; &lt;&lt; p.last_name &lt;&lt; &quot; &quot; &lt;&lt; p.age; } std::istream& operator&gt;&gt;(std::istream & in, person & p)  { \treturn in &gt;&gt; p.first_name &gt;&gt; p.last_name &gt;&gt; p.age; } <\/code><\/pre>\n<p>  \u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u043f\u043e \u0441\u0435\u0442\u0438 \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"cpp\">streambuf buf; std::ostream out(&buf); person p; \/\/ ... initialize p out &lt;&lt; p &lt;&lt; std::endl; write(sock, buf); <\/code><\/pre>\n<p>  \u0414\u0440\u0443\u0433\u0430\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c:<\/p>\n<pre><code class=\"cpp\">read_until(sock, buf, &quot;\\n&quot;); std::istream in(&buf); person p; in &gt;&gt; p; <\/code><\/pre>\n<p>  \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <code>streambuf <\/code>\u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 <code>std::ostream<\/code> \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u043b\u0438 <code>std::istream<\/code> \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f, \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0432\u044b \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u043c:  <\/p>\n<ul>\n<li> \u041f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0447\u0435\u0433\u043e-\u0442\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0441\u0435\u0442\u0438, \u043e\u0447\u0435\u043d\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u043c\u0435\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u0432\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0443\u0444\u0435\u0440. \u0415\u0441\u043b\u0438 \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0439, \u0442\u043e \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443. \u0412\u0441\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 &lt;&lt;.<\/li>\n<li> \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435, \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f; \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0435\u0433\u043e, \u0442\u043e \u0435\u0441\u0442\u044c, \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0447\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0438, \u0435\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u043e\u0439, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c. \u0412\u0441\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 &gt;&gt;.<\/li>\n<\/ul>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043a\u0440\u0443\u0442\u043e\u0439 \u0442\u0440\u044e\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>streambuf <\/code>\u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">streambuf buf; ... std::cout &lt;&lt; &buf &lt;&lt; std::endl; \/\/ dumps all content to the console <\/code><\/pre>\n<p>  \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0432 \u0441\u0442\u0440\u043e\u043a\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"cpp\">std::string to_string(streambuf &buf)  { \tstd::ostringstream out; \tout &lt;&lt; &buf; \treturn out.str(); } <\/code><\/pre>\n<h4>\u041a\u043b\u0430\u0441\u0441 streambuf<\/h4>\n<p>  \u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, <code>streambuf <\/code>\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d \u043e\u0442 <code>std::streambuf.<\/code> \u041a\u0430\u043a \u0438 std::streambuf \u0443 \u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<br \/>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0443 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a:  <\/p>\n<ul>\n<li> <code>streambuf ([max_size,] [allocator])<\/code>: \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 <b>streambuf<\/b>. \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430 \u0438 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f\/\u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438.<\/li>\n<li> <code>prepare(n)<\/code>: \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0434-\u0431\u0443\u0444\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u0437<code> n<\/code> \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u0438. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0441 \u043b\u044e\u0431\u043e\u0439 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0438\u0437 Boost.Asio \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0449\u0435\u0439 \u0447\u0442\u0435\u043d\u0438\u0435\/\u0437\u0430\u043f\u0438\u0441\u044c, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0442\u0435\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 <code>streambuf<\/code>.<\/li>\n<li> <code>data()<\/code>: \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0435\u0441\u044c \u0431\u0443\u0444\u0435\u0440 \u0432 \u0432\u0438\u0434\u0435 \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0441 \u043b\u044e\u0431\u043e\u0439 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0438\u0437 Boost.Asio, \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0449\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u044c, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0442\u0435\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 <code>streambuf<\/code>.<\/li>\n<li> <code>consume(n)<\/code>: \u0432 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0437 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 (\u0438\u0437 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0447\u0442\u0435\u043d\u0438\u044f).<\/li>\n<li><code> commit(n)<\/code>: \u0432 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0437 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 (\u0438\u0437 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u0438) \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 (\u0432 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0447\u0442\u0435\u043d\u0438\u044f).<\/li>\n<li> <code>size()<\/code>: \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u0445 \u0432\u0441\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>streambuf<\/code>.<\/li>\n<li> <code>max_size()<\/code>: \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 <code>streambuf<\/code>.<\/li>\n<\/ul>\n<p>  \u0417\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0434\u0432\u0443\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043d\u0435 \u0442\u0430\u043a \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043d\u044f\u0442\u044c. \u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>streambuf <\/code>\u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f\/\u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"cpp\">read_until(sock, buf, &quot;\\n&quot;); \/\/ reads into buf write(sock, buf); \/\/ writes from buf <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442\u0435 \u0432\u0435\u0441\u044c \u0431\u0443\u0444\u0435\u0440 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435, \u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u0434\u043e \u043b\u0438 \u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430, \u0438\u0441\u043a\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f, \u0442\u043e \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0445 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c.<br \/>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">read_until(sock, buf, '\\n'); std::cout &lt;&lt; &buf &lt;&lt; std::endl; <\/code><\/pre>\n<p>  \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u0432\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0438\u0437 \u0441\u043e\u043a\u0435\u0442\u0430. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u043c\u043f\u043e\u043c \u0447\u0435\u0433\u043e-\u0442\u043e:<\/p>\n<pre><code class=\"cpp\">read(sock, buf.prepare(16), transfer_exactly(16) ); std::cout &lt;&lt; &buf &lt;&lt; std::endl; <\/code><\/pre>\n<p>  \u0411\u0430\u0439\u0442\u044b \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f, \u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f. \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0434\u0432\u0438\u0433\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"cpp\">read(sock, buf.prepare(16), transfer_exactly(16) ); buf.commit(16); std::cout &lt;&lt; &buf &lt;&lt; std::endl; <\/code><\/pre>\n<p>  \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 <code>streambuf <\/code>\u0438 \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0437\u0430\u043f\u0438\u0441\u0438, \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"cpp\">streambuf buf; std::ostream out(&buf); out &lt;&lt; &quot;hi there&quot; &lt;&lt; std::endl; write(sock, buf); <\/code><\/pre>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u043f\u043e\u0448\u043b\u0435\u0442 <code>hi there<\/code> \u0442\u0440\u0438 \u0440\u0430\u0437\u0430:<\/p>\n<pre><code class=\"cpp\">streambuf buf; std::ostream out(&buf); out &lt;&lt; &quot;hi there&quot; &lt;&lt; std::endl; for ( int i = 0; i &lt; 3; ++i)  \twrite(sock, buf.data()); <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0431\u0443\u0444\u0435\u0440 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442\u0441\u044f \u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043c. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u043b\u0438\u0441\u044c, \u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"cpp\">streambuf buf; std::ostream out(&buf); out &lt;&lt; &quot;hi there&quot; &lt;&lt; std::endl; write(sock, buf.data()); buf.consume(9); <\/code><\/pre>\n<p>  \u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438, \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0435\u0441\u0442\u044c \u0438\u043c\u0435\u0442\u044c \u0434\u0435\u043b\u043e \u0441 \u0446\u0435\u043b\u044b\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c <code>streambuf<\/code>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0442\u043e\u043d\u043a\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438.<br \/>  \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 streambuf \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438, \u0442\u043e \u044f \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0432\u0430\u043c \u0434\u0432\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430, \u043e\u0434\u0438\u043d \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f, \u0434\u0440\u0443\u0433\u043e\u0439 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438. \u042d\u0442\u043e \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0449\u0435 \u0438 \u044f\u0441\u043d\u0435\u0435, \u0438 \u0432\u044b \u0438\u0437\u0431\u0435\u0436\u0438\u0442\u0435 \u043c\u043d\u043e\u0433\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<h4>\u041d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 <code>streambuf<\/code><\/h4>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 Boost.Asio, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 <code>streambuf<\/code>:  <\/p>\n<ul>\n<li><code> read (sock, buf [, completion_function])<\/code>: \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0437 \u0441\u043e\u043a\u0435\u0442\u0430 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 <code>streambuf<\/code>. \u0417\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439. \u0415\u0441\u043b\u0438 \u0436\u0435 \u043e\u043d\u0430 \u0435\u0441\u0442\u044c, \u0442\u043e \u043e\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 Boost.Asio, \u0435\u0441\u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 (\u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0447\u0438\u0442\u0430\u0442\u044c). \u0415\u0435 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <code>size_t completion(const boost::system::error_code & err, size_t bytes_transfered)<\/code>;. \u041f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 0, \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0443, \u0435\u0441\u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0430\u0441\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e; \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442\u043e \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0435\u0440\u043d\u0443\u043b\u043e\u0441\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0439\u0442 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>read_some<\/code>.<\/li>\n<li><code> read_at(radom_stream, offset, buf [, completion_function])<\/code>: \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0437 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u043e\u043a\u0435\u0442\u0430\u043c (\u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0438 \u043d\u0435 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u044e\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430).<\/li>\n<li> <code>read_until(sock, buf, char | string | regex | match_condition)<\/code>: \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0447\u0438\u0442\u0430\u0435\u0442 \u043f\u043e\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435. \u041b\u0438\u0431\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b, \u043b\u0438\u0431\u043e \u043a\u0430\u043a\u0430\u044f-\u043b\u0438\u0431\u043e \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u043b\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u0442 \u0441 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a, \u043b\u0438\u0431\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>match_condition<\/code> \u0441\u043a\u0430\u0436\u0435\u0442 \u043d\u0430\u043c, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u0432\u044b\u0439\u0442\u0438 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0421\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>match_condition <\/code>\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f: <code>match_conditionis pair&lt;iterator,bool&gt;match(iterator begin, iterator end)<\/code>; \u0433\u0434\u0435 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u044d\u0442\u043e <code>buffers_iterator &lt;streambuf::const_buffers_type&gt;<\/code>. \u0415\u0441\u043b\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e, \u0442\u043e \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430 (<code>passed-end-of-match<\/code> \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u0432 <code>true<\/code>), \u0435\u0441\u043b\u0438 \u0436\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439 \u043d\u0435 \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u043e, \u0442\u043e \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u0430\u044f \u043f\u0430\u0440\u0430 (<code>begin <\/code>\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432 <code>false<\/code>).<\/li>\n<li><code> write(sock, buf [, completion_function])<\/code>: \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 <code>streambuf<\/code>. \u0417\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438 \u0435\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>read()<\/code>: \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f 0, \u043a\u043e\u0433\u0434\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 \u0438\u043b\u0438 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0439\u0442, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>write_some<\/code>.<\/li>\n<li> <code>write_at(random_stream,offset, buf [, completion_function])<\/code>: \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a. \u041e\u043f\u044f\u0442\u044c \u0436\u0435 \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u043e\u043a\u0435\u0442\u0430\u043c.<\/li>\n<li> <code>async_read(sock, buf [, competion_function], handler)<\/code>: \u044d\u0442\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0434\u0432\u043e\u0439\u043d\u0438\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>read()<\/code>. \u0421\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f: <code>void handler(const boost::system::error_code, size_t bytes)<\/code>.<\/li>\n<li> <code>async_read_at(radom_stream, offset, buf [, completion_function] ,handler)<\/code>: \u044d\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0434\u0432\u043e\u0439\u043d\u0438\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>read_at()<\/code>.<\/li>\n<li><code>async_read_until (sock, buf, char | string | regex | match_condition, handler)<\/code>: \u044d\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0434\u0432\u043e\u0439\u043d\u0438\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>read_until()<\/code>.<\/li>\n<li> <code>async_write(sock, buf [, completion_function] , handler)<\/code>: \u044d\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0434\u0432\u043e\u0439\u043d\u0438\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>write()<\/code>.<\/li>\n<li> <code>async_write_at(random_stream,offset, buf [, completion_function], handler)<\/code>: \u044d\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0434\u0432\u043e\u0439\u043d\u0438\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>write_at()<\/code>.<\/li>\n<\/ul>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043e \u0433\u043b\u0430\u0441\u043d\u043e\u0439 \u0431\u0443\u043a\u0432\u044b:<\/p>\n<pre><code class=\"cpp\">streambuf buf; bool is_vowel(char c)  { \treturn c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'; } size_t read_complete(boost::system::error_code, size_t bytes)  { \tconst char * begin = buffer_cast&lt;const char*&gt;( buf.data()); \tif ( bytes == 0)  \t\treturn 1; \twhile ( bytes &gt; 0) \t{ \t\tif ( is_vowel(*begin++))  \t\t\treturn 0; \t\telse  \t\t\t--bytes; \t} \treturn 1; } ... read(sock, buf, read_complete); <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u043e \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"cpp\">read_until(sock, buf, boost::regex(&quot;^[aeiou]+&quot;) ); <\/code><\/pre>\n<p>  \u0418\u043b\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044c\u0442\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440, \u0438 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>match_condition <\/code>\u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<pre><code class=\"cpp\">streambuf buf; bool is_vowel(char c)  { \treturn c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'; } typedef buffers_iterator&lt;streambuf::const_buffers_type&gt; iterator; std::pair&lt;iterator,bool&gt; match_vowel(iterator b, iterator e)  { \twhile ( b != e) \t{ \t\tif ( is_vowel(*b++))  \t\t\treturn std::make_pair(b, true); \t} \treturn std::make_pair(e, false); } ... size_t bytes = read_until(sock, buf, match_vowel); <\/code><\/pre>\n<h4>\u0421\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/h4>\n<p>  \u0410\u0432\u0442\u043e\u0440\u044b Boost.Asio, \u043e\u043a\u043e\u043b\u043e 2009-2010 \u0433\u043e\u0434\u043e\u0432, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u043a\u043b\u0430\u0441\u0441\u043d\u0443\u044e \u0438\u0434\u0435\u044e \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0435\u0449\u0435 \u043f\u0440\u043e\u0449\u0435.<br \/>  \u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u0430\u043c \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c \u0434\u0432\u0435 \u0432\u0435\u0449\u0438, \u0442\u043e \u0435\u0441\u0442\u044c \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0442\u0430\u043a \u0436\u0435 \u043b\u0435\u0433\u043a\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u043f\u043e\u0447\u0442\u0438 \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage3\/56c\/3b2\/1ba\/56c3b21ba43b330abb6f703efa78d87f.png\"\/><\/p>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0432\u044b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u0441\u044c \u043a\u043e \u0432\u0442\u043e\u0440\u043e\u043c\u0443 \u0441\u043b\u0443\u0447\u0430\u044e.<br \/>  \u041f\u0440\u043e\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0438 \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<br \/>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0442\u043e \u0432\u0430\u043c \u043d\u0430\u0434\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0434\u0432\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 <code>boost\/libs\/asio\/example\/http\/server4: yield.hpp<\/code> \u0438 <code>coroutine.hpp<\/code>. \u0417\u0434\u0435\u0441\u044c \u0432 Boost.Asio \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0434\u0432\u0430 \u043c\u0430\u043a\u0440\u043e\u0441\u0430 \u0438 \u043a\u043b\u0430\u0441\u0441:  <\/p>\n<ul>\n<li> <code>coroutine<\/code>: \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0430\u044f \u043e\u0442 \u0432\u0430\u0448\u0435\u0433\u043e \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432\u0430\u043c\u0438 <code>connection <\/code>\u043a\u043b\u0430\u0441\u0441 \u0432 \u0446\u0435\u043b\u044f\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c.<\/li>\n<li><code> reenter(entry)<\/code>: \u044d\u0442\u043e \u0442\u0435\u043b\u043e \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0412\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u043b\u043e\u043a\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0446\u0435\u043b\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/li>\n<li> yield code: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/li>\n<\/ul>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u0437 4 \u0433\u043b\u0430\u0432\u044b, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043b\u0438\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u043f\u0438\u043d\u0433\u0443\u0435\u0442\u0441\u044f \u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u043a\u0430\u043a\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0437\u0430\u043d\u0435\u0441\u0435\u043d\u044b \u0432 \u0436\u0443\u0440\u043d\u0430\u043b.<br \/>  \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430:<\/p>\n<pre><code class=\"cpp\">class talk_to_svr : public boost::enable_shared_from_this&lt;talk_to_svr&gt; \t, public coroutine, boost::noncopyable  { \t... \tvoid step(const error_code & err = error_code(), size_t bytes = 0)  \t{ \t\treenter(this)  \t\t{  \t\t\tfor (;;)  \t\t\t{ \t\t\t\tyield async_write(sock_, write_buffer_,  \t\t\t\t\tMEM_FN2(step,_1,_2) ); \t\t\t\tyield async_read_until( sock_, read_buffer_,&quot;\\n&quot;, MEM_ \t\t\t\t\tFN2(step,_1,_2)); \t\t\t\tyield service.post( MEM_FN(on_answer_from_server)); \t\t\t} \t\t} \t} }; <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u043f\u0430\u043b\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u0447\u043b\u0435\u043d\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <code>connect(), on_connect(), on_read(),do_read(), on_write(), do_write()<\/code> \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435, \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>step()<\/code>.<br \/>  \u0422\u0435\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 <code>reenter(this) { for (;;) { }}<\/code>. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u0443\u043c\u0430\u0442\u044c \u043e <code>reenter(this)<\/code> \u043a\u0430\u043a \u043e \u043a\u043e\u0434\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0438 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0440\u0430\u0437, \u0442\u0430\u043a \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434.<br \/>  \u0412\u043d\u0443\u0442\u0440\u0438 \u0431\u043b\u043e\u043a\u0430 <code>reenter <\/code>\u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u041f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0432\u0445\u043e\u0434\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>async_write<\/code>, \u043f\u0440\u0438 \u0432\u0442\u043e\u0440\u043e\u043c \u0432\u0445\u043e\u0434\u0435 \u2013 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>async_read_until<\/code>, \u043f\u0440\u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u2013 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>service.post<\/code>, \u043f\u0440\u0438 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u043e\u043c \u2013 \u043e\u043f\u044f\u0442\u044c <code>async_write <\/code>\u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<br \/>  \u0412\u044b \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>for(;;) {}.<\/code> \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">void step(const error_code & err = error_code(), size_t bytes = 0)  { \treenter(this)  \t{  \t\tyield async_write(sock_, write_buffer_, MEM_FN2(step,_1,_2) ); \t\tyield async_read_until( sock_, read_buffer_, &quot;\\n&quot;,MEM_FN2(step,_1,_2)); \t\tyield service.post( MEM_FN(on_answer_from_server)); \t} } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0432 \u0442\u0440\u0435\u0442\u0438\u0439 \u0440\u0430\u0437, \u043c\u044b \u0431\u044b \u0432\u043e\u0448\u043b\u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0438 <code>service.post<\/code>. \u0412 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u0439 \u0440\u0430\u0437 \u043c\u044b \u0431\u044b \u043f\u0440\u043e\u0448\u043b\u0438 \u043c\u0438\u043c\u043e <code>service.post<\/code> \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0438. \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0438 \u043d\u0430 \u043f\u044f\u0442\u044b\u0439 \u0440\u0430\u0437 \u0438 \u043d\u0430 \u0432\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435:<\/p>\n<pre><code class=\"cpp\">class talk_to_svr : public boost::enable_shared_from_this&lt;talk_to_svr&gt;  \t, public coroutine, boost::noncopyable  { \ttalk_to_svr(const std::string & username) : ... {} \tvoid start(ip::tcp::endpoint ep)  \t{ \t\tsock_.async_connect(ep, MEM_FN2(step,_1,0) ); \t} \tstatic ptr start(ip::tcp::endpoint ep, const std::string & username)  \t{ \t\tptr new_(new talk_to_svr(username));  \t\tnew_-&gt;start(ep);  \t\treturn new_; \t} \tvoid step(const error_code & err = error_code(), size_t bytes = 0)  \t{ \t\treenter(this)  \t\t{  \t\t\tfor (;;)  \t\t\t{ \t\t\t\tif ( !started_)  \t\t\t\t{ \t\t\t\t\tstarted_ = true;  \t\t\t\t\tstd::ostream out(&write_buf_); \t\t\t\t\tout &lt;&lt; &quot;login &quot; &lt;&lt; username_ &lt;&lt; &quot;\\n&quot;; \t\t\t\t} \t\t\t\tyield async_write(sock_, write_buf_, MEM_FN2(step,_1,_2) ); \t\t\t\tyield async_read_until( sock_,read_buf_,&quot;\\n&quot;, MEM_FN2(step,_1,_2)); \t\t\t\tyield service.post( MEM_FN(on_answer_from_server)); \t\t\t} \t\t} \t} \tvoid on_answer_from_server()  \t{ \t\tstd::istream in(&read_buf_);  \t\tstd::string word;  \t\tin &gt;&gt; word; \t\tif ( word == &quot;login&quot;)  \t\t\ton_login(); \t\telse if ( word == &quot;ping&quot;)  \t\t\ton_ping(); \t\telse if ( word == &quot;clients&quot;)  \t\t\ton_clients(); \t\tread_buf_.consume( read_buf_.size()); \t\tif (write_buf_.size() &gt; 0)  \t\t\tservice.post( MEM_FN2(step,error_code(),0)); \t} \t... private: \tip::tcp::socket sock_;  \tstreambuf read_buf_, write_buf_; \tbool started_;  \tstd::string username_;  \tdeadline_timer timer_; }; <\/code><\/pre>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>start()<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443. \u041a\u043e\u0433\u0434\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e, \u043c\u044b \u0432\u0445\u043e\u0434\u0438\u043c \u0432 <code>step()<\/code> \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437. \u042d\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 \u043d\u0430\u0448\u0438\u043c \u043b\u043e\u0433\u0438\u043d\u043e\u043c.<br \/>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0442 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>async_write<\/code>, \u0437\u0430\u0442\u0435\u043c <code>async_read_until<\/code> \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 (<code>on_answer_from_server<\/code>).<br \/>  \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>on_answer_from_server <\/code>\u043c\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f; \u043c\u044b \u0447\u0438\u0442\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043c\u044b \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c (\u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435):<\/p>\n<pre><code class=\"cpp\">class talk_to_svr : ...  { \t... \tvoid on_login()  \t{  \t\tdo_ask_clients();  \t} \tvoid on_ping()  \t{ \t\tstd::istream in(&read_buf_); \t\tstd::string answer; in &gt;&gt; answer; \t\tif ( answer == &quot;client_list_changed&quot;)  \t\t\tdo_ask_clients(); \t\telse  \t\t\tpostpone_ping(); \t} \tvoid on_clients()  \t{ \t\tstd::ostringstream clients;  \t\tclients &lt;&lt; &read_buf_; \t\tstd::cout &lt;&lt; username_ &lt;&lt; &quot;, new client list:&quot; &lt;&lt; clients. \t\tstr(); \t\tpostpone_ping(); \t} \tvoid do_ping()  \t{ \t\tstd::ostream out(&write_buf_);  \t\tout &lt;&lt; &quot;ping\\n&quot;; \t\tservice.post( MEM_FN2(step,error_code(),0)); \t} \tvoid postpone_ping()  \t{ \t\ttimer_.expires_from_now(boost::posix_time::millisec(rand() % 7000)); \t\ttimer_.async_wait( MEM_FN(do_ping)); \t} \tvoid do_ask_clients()  \t{ \t\tstd::ostream out(&write_buf_);  \t\tout &lt;&lt; &quot;ask_clients\\n&quot;; \t} }; <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u0432\u044f\u0437\u044c \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0432 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0427\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e, \u043c\u044b \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u0438\u043d\u0433\u043e\u0432\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437. \u0417\u0430\u0442\u0435\u043c \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0442\u0432\u0435\u0442\u043d\u044b\u0439 \u043f\u0438\u043d\u0433 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043c\u044b \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0434\u0440\u0443\u0433\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u0438\u043d\u0433\u043e\u0432\u043a\u0438.<br \/>  \u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"cpp\">int main(int argc, char* argv[])  { \tip::tcp::endpoint ep( ip::address::from_string(&quot;127.0.0.1&quot;), 8001); \ttalk_to_svr::start(ep, &quot;John&quot;); \tservice.run(); } <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u044b \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u0438 \u043a\u043e\u0434 \u043d\u0430 15 \u0441\u0442\u0440\u043e\u043a, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043e\u043d \u0441\u0442\u0430\u043b \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u0435\u0435. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0435\u0434\u0432\u0430 \u043a\u043e\u0441\u043d\u0443\u043b\u0438\u0441\u044c \u0442\u0435\u043c\u044b \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443, \u0442\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u044c \u044d\u0442\u0443 <a href=\"http:\/\/blog.think-async.com\/2010_03_01_archive.html\">\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443<\/a>.<\/p>\n<h4>\u0420\u0435\u0437\u044e\u043c\u0435<\/h4>\n<p>  \u041c\u044b \u0443\u0432\u0438\u0434\u0435\u043b\u0438, \u043a\u0430\u043a \u043b\u0435\u0433\u043a\u043e Boost.Asio \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 STL \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 streambuf. \u0422\u0430\u043a \u0436\u0435 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0434\u0435\u043b\u0430\u044e\u0442 \u043d\u0430\u0448 \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u044b\u043c \u0438 \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u0442 \u0435\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<br \/>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0433\u043b\u0430\u0432\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0430\u043a\u0438\u0435 \u0442\u0435\u043c\u044b \u043a\u0430\u043a Asio \u043f\u0440\u043e\u0442\u0438\u0432 Boost.Asio, \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u0430\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0430, SSL, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0443\u0440\u0443\u0433\u0438\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0435 \u043e\u0442 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>  \u0420\u0435\u0441\u0443\u0440\u0441\u044b \u043a \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435: \u0441\u0441\u044b\u043b\u043a\u0430<\/p>\n<p>  \u0412\u0441\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0434\u043e \u043d\u043e\u0432\u044b\u0445 \u0432\u0441\u0442\u0440\u0435\u0447!    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/196888\/\"> http:\/\/habrahabr.ru\/post\/196888\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<br \/>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043a\u043d\u0438\u0433\u0438 John Torjo \u00abBoost.Asio C++ Network Programming\u00bb.<\/p>\n<p>  \u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435:  <\/p>\n<ul>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/192284\/\">\u0413\u043b\u0430\u0432\u0430 1: \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u044f \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Boost.Asio<\/a><\/li>\n<li>\u0413\u043b\u0430\u0432\u0430 2: \u041e\u0441\u043d\u043e\u0432\u044b Boost.Asio<br \/> \n<ul>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/193038\/\"> \u0427\u0430\u0441\u0442\u044c 1: \u041e\u0441\u043d\u043e\u0432\u044b Boost.Asio<\/a><\/li>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/195006\/\"> \u0427\u0430\u0441\u0442\u044c 2: \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/195386\/\">\u0413\u043b\u0430\u0432\u0430 3: Echo \u0421\u0435\u0440\u0432\u0435\u0440\/\u041a\u043b\u0438\u0435\u043d\u0442<\/a><\/li>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/195794\/\">\u0413\u043b\u0430\u0432\u0430 4: \u041a\u043b\u0438\u0435\u043d\u0442 \u0438 \u0421\u0435\u0440\u0432\u0435\u0440<\/a><\/li>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/196354\/\">\u0413\u043b\u0430\u0432\u0430 5: \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0442\u0438\u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e<\/a><\/li>\n<li><b>\u0413\u043b\u0430\u0432\u0430 6: Boost.Asio \u2013 \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438<\/b><\/li>\n<li>\u0413\u043b\u0430\u0432\u0430 7: Boost.Asio \u2013 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0442\u0435\u043c\u044b<\/li>\n<\/ul>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0433\u043b\u0430\u0432\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 Boost.Asio. \u041e\u0431\u044a\u0435\u043a\u0442\u044b std streams \u0438 streambuf \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438, \u043d\u043e, \u043a\u0430\u043a \u0432\u044b \u0441\u0430\u043c\u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0443 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0437\u0434\u043d\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 Boost.Asio \u2014 co-routines, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c \u0438\u043c\u0435\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 (\u043a\u0430\u043a \u0431\u0443\u0434-\u0442\u043e \u0431\u044b \u043e\u043d \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439). \u042d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-196888","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/196888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=196888"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/196888\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=196888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=196888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=196888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}