{"id":166139,"date":"2013-01-17T15:48:03","date_gmt":"2013-01-17T11:48:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=166139"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=166139","title":{"rendered":"<span class=\"post_title\">\u041f\u0438\u043d\u0433\u0435\u0440 \u043d\u0430 Boost.Asio \u0438 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<a href=\"http:\/\/habrahabr.ru\/company\/pt\/blog\/166139\/\"><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/911\/38b\/b30\/91138bb305a4e889e17a99be4176eb16.jpg\" align=\"left\"\/><\/a>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0412 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043d\u0430\u0448\u0438\u0445 <a href=\"http:\/\/habrahabr.ru\/company\/pt\/blog\/156795\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b\u0438 \u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0438\u043d\u0433\u0430 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u00ab\u043f\u0438\u043d\u0433\u0435\u0440\u0430\u00bb \u0434\u043b\u044f \u0435\u0433\u043e \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438 \u043f\u0435\u043d\u0442\u0435\u0441\u0442\u0430\u0445 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0439 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u0441\u0442\u0430\u043d\u0446\u0438\u0439. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0438\u043d\u0433\u0435\u0440\u0430 (\u043b\u043e\u0433\u0438\u043a\u0430 \u0438 \u0441\u0435\u0442\u0435\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c) \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u043c\u0438 \u0442\u0435\u0441\u0442\u0430\u043c\u0438.<\/p>\n<p>  \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u2014 \u0434\u0438\u0441\u0446\u0438\u043f\u043b\u0438\u043d\u0438\u0440\u0443\u0435\u0442 \u0438 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u0435\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043f\u0435\u0440\u0432\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u043e \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0438 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430 Boost.Asio \u0431\u044b\u043b\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u0430\u044f: \u00ab\u0427\u0442\u043e?! \u042d\u0442\u043e \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e! \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u0443\u0437\u043b\u0430?\u00bb<a name=\"habracut\"><\/a><\/p>\n<p>  \u041f\u043e\u0442\u043e\u043c \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0438\u0434\u0435\u044f \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u044d\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0439 \u0443\u0437\u0435\u043b \u0438 \u0435\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0438\u043d\u0433\u0435\u0440\u0430. \u041f\u0440\u0438 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 \u0438\u0437 Boost.Asio \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u043c\u044b\u0441\u043b\u044c \u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u043d\u0430\u0448\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<p>  \u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u0430\u044f \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u043e\u043a\u0435\u0442\u0430 \u0432 Boost.Asio. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/446\/77d\/dcc\/44677ddccd04bc066f4d81e88b80781d.png\"\/><\/p>\n<p>  \u0412 \u043a\u043e\u0434\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">template &lt;typename Protocol,     typename StreamSocketService = stream_socket_service&lt;Protocol&gt; &gt; class basic_stream_socket   : public basic_socket&lt;Protocol, StreamSocketService&gt; { } <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u0441\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0432 boost::asio::basic_stream_socket \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u0443 StreamSocketService. \u0412\u043e\u0442 \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Boost.Asio, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044d\u0442\u043e \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442:<\/p>\n<pre><code class=\"cpp\">  template &lt;typename ConnectHandler&gt;   void async_connect(const endpoint_type& peer_endpoint,       BOOST_ASIO_MOVE_ARG(ConnectHandler) handler)   { \t.....     this-&gt;get_service().async_connect(this-&gt;get_implementation(),         peer_endpoint, BOOST_ASIO_MOVE_CAST(ConnectHandler)(handler));   } <\/code><\/pre>\n<p>  \u0414\u0440\u0443\u0433\u0438\u043c \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u043a\u0435\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f, \u043f\u043e \u0441\u0443\u0442\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0440\u0442\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0438\u043f\u0430\u043c\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430; \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0430. \u0418\u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u00ab\u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c\u00bb \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0441\u043e\u043a\u0435\u0442\u0430, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0441\u043e\u043a\u0435\u0442\u0430 \u043d\u0430\u0448\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u0435\u0440\u0432\u0438\u0441\u0430. \u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u0430 \u0431\u044b \u044d\u0442\u0430 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u0441\u043e\u043a\u0435\u0442\u0430 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u0430 \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/8a8\/ffe\/c33\/8a8ffec339695ace6d93428e0ba5bd52.png\"\/><\/p>\n<p>  \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u043c \u0441\u043e\u0431\u043e\u0439 \u043d\u0435 \u0447\u0442\u043e \u0438\u043d\u043e\u0435, \u043a\u0430\u043a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Dependency_injection\">Compile time dependency injection<\/a>, \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u0430\u044f \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u043e\u043a\u0435\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/f8c\/bb0\/071\/f8cbb00715a6f5d1911660d42f705504.png\"\/><\/p>\n<p>  \u0412 \u043a\u043e\u0434\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0438 \u0440\u0430\u0431\u043e\u0447\u0438\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">class BoostPrimitives { public: \ttypedef boost::asio::ip::tcp::socket TCPSocket; \ttypedef boost::asio::ip::icmp::socket ICMPSocket; \ttypedef boost::asio::ip::tcp::resolver Resolver; \ttypedef boost::asio::deadline_timer Timer; }; <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">class Primitives { public: \ttypedef ba::basic_stream_socket \t&lt; \t\tba::ip::tcp,  \t\tSocketService&lt;ba::ip::tcp&gt;  \t&gt; TCPSocket;  \ttypedef ba::basic_raw_socket \t&lt; \t\tba::ip::icmp,  \t\tSocketService&lt;ba::ip::icmp&gt;  \t&gt; ICMPSocket;  \ttypedef ba::basic_deadline_timer \t&lt; \t\tboost::posix_time::ptime,  \t\tba::time_traits&lt;boost::posix_time::ptime&gt;,  \t\tTimerService \t\t&lt; \t\t\tboost::posix_time::ptime,  \t\t\tba::time_traits&lt;boost::posix_time::ptime&gt;  \t\t&gt;  \t&gt; Timer;  \ttypedef ba::ip::basic_resolver \t&lt; \t\tba::ip::tcp,  \t\tResolverService&lt;ba::ip::tcp&gt;  \t&gt; Resolver; };   <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  SocketService, TimerService \u0438 ResolverService \u2014 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0438 \u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440\u0430 \u0438\u043c\u0435\u043d, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0438\u043c\u0435\u044e\u0442 \u0441\u0445\u043e\u0436\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c\u0441\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u0438 \u0438\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432.<\/p>\n<p>  \u0410 \u0432\u043e\u0442 \u0442\u0430\u043a \u0432 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0438\u043d\u0433\u0435\u0440\u0430.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/4b6\/965\/7fb\/4b69657fb02cedbb9ea5e62a95714f7a.png\"\/><\/p>\n<p>  \u0412 \u043a\u043e\u0434\u0435 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0438\u043d\u0433\u0435\u0440\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">template&lt;typename Traits&gt; class PingerImpl { \t..... \t\/\/! Socket type \ttypedef typename Traits::TCPSocket TCPSocket; \t..... } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0438\u043d\u0433\u0435\u0440 \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">class Pinger { \t\/\/! Implementation type \ttypedef PingerImpl&lt;BoostPrimitives&gt; Impl; \t.... \tprivate:  \t\/\/! Implementation \tstd::auto_ptr&lt;Impl&gt; m_Impl; }; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0438\u043d\u0433\u0435\u0440 \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">class BaseTest : boost::noncopyable { protected:  \t\/\/! Pinger implementation type \ttypedef Net::PingerImpl&lt;Test::Primitives&gt; TestPinger; \t.... }; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0441 \u0438\u0445 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0438\u043d\u0433\u0430. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 (\u043f\u0438\u043d\u0433 \u0443\u0437\u043b\u0430) \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Boost.Asio. \u041d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043d\u0435\u043a\u0430\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043a\u043e\u043c\u0430\u043d\u0434, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f \u0438 \u043e\u043f\u0443\u0441\u0442\u043e\u0448\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0438\u043d\u0433\u0430. \u0412\u043e\u0442 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0443 \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/394\/636\/cc5\/394636cc505b2cdd9d1331042345f1fc.png\"\/><\/p>\n<p>  \u0412\u0432\u0435\u0434\u0435\u043c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e ICommand, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 Boost.Asio, \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u044b \u2014 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 (\u043a\u043b\u0430\u0441\u0441 Connect \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0443\u0437\u043b\u043e\u043c, \u043a\u043b\u0430\u0441\u0441 Receive \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0442. \u0434.).<\/p>\n<p>  UML-\u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0435\u0441\u0442\u043e\u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0438\u0436\u0435.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/379\/651\/612\/379651612ad55f50f4ec529cea77993a.png\"\/><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/\/! Pinger test command interface class ICommand : boost::noncopyable { public:  \t\/\/! Command pointer \ttypedef boost::shared_ptr&lt;ICommand&gt; Ptr;  \t\/\/! Error callback type \ttypedef boost::function&lt;void(const boost::system::error_code&)&gt; ErrorCallback;  \t\/\/! Error and size callback \ttypedef boost::function&lt;void(const boost::system::error_code&, std::size_t)&gt; ErrorAndSizeCallback;  \t\/\/! Resolver callback \ttypedef boost::function&lt;void(const boost::system::error_code&, boost::asio::ip::tcp::resolver::iterator)&gt; ResolverCallback;  public:  \tICommand(const Status::Enum status) : m_Status(status) {}  \t\/\/! Timer wait \tvirtual void AsyncWait(ErrorCallback& callback, boost::asio::io_service& io);  \t\/\/! Async connect \tvirtual void AsyncConnect(ErrorCallback& callback, boost::asio::io_service& io);  \t\/\/! Async receive \tvirtual void AsyncReceive(ErrorAndSizeCallback& callback, const std::vector&lt;char&gt;& sended, const boost::asio::mutable_buffer& buffer, boost::asio::io_service& io);  \t\/\/! Async resolve \tvirtual void AsyncResolve(ResolverCallback& callback, boost::asio::io_service& io);  \t\/\/! Dtor \tvirtual ~ICommand() {} protected: \tStatus::Enum m_Status; }; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u044b, \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439, \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f: \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">void Connect::AsyncConnect(ErrorCallback& callback, boost::asio::io_service& io) { \tif (m_Status != Status::Pending) \t{ \t\tio.post(boost::bind(callback, m_Code)); \t\tcallback = ErrorCallback(); \t} } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u00ab\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e\u00bb \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0430 \u043d\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c:<\/p>\n<pre><code class=\"cpp\">void ICommand::AsyncConnect(ErrorCallback& \/*callback*\/, boost::asio::io_service& \/*io*\/) { \tassert(false); } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 \u2014 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0447\u0435\u0440\u0435\u0434\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0449\u0438\u0439, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u0430 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043d\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043a\u043e\u043c\u0430\u043d\u0434.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u00ab\u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f\u00bb, \u0438\u043c\u0435\u044e\u0449\u0435\u0433\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043a\u043e\u043c\u0430\u043d\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/\/! Test fixture class Fixture { \t\/\/! Commands list \ttypedef std::list&lt;ICommand::Ptr&gt; Commands;  public: \tFixture(); \t~Fixture();  \tstatic void Push(ICommand* cmd); \tstatic ICommand::Ptr Pop();  private:  \tstatic Commands s_Commands; };  Fixture::Commands Fixture::s_Commands;  Fixture::Fixture() { \tassert(s_Commands.empty()); \/\/ \u0443\u0431\u0435\u0436\u0434\u0430\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043d\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043a\u043e\u043c\u0430\u043d\u0434 \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0442\u0435\u0441\u0442-\u043a\u0435\u0439\u0441\u0430 }  Fixture::~Fixture() { \tassert(s_Commands.empty()); \/\/ \u0432\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u044b \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 }  void Fixture::Push(ICommand* cmd) { \ts_Commands.push_back(ICommand::Ptr(cmd)); }  ICommand::Ptr Fixture::Pop() { \tassert(!s_Commands.empty());  \tconst ICommand::Ptr result = s_Commands.front(); \ts_Commands.pop_front(); \treturn result; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0427\u0430\u0441\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">template&lt;typename T&gt; \tvoid async_connect(implementation_type& \/*impl*\/, const endpoint& \/*ep*\/, const T& callback) \t{ \t\tm_ConnectCallback = callback; \t\tFixture::Pop()-&gt;AsyncConnect(m_ConnectCallback, m_Service); \/\/ \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \t} <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u042e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u043d\u0430 <a href=\"http:\/\/ru.wikipedia.org\/wiki\/Google_C%2B%2B_Testing_Framework\">\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 Google<\/a>, \u0432\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0435\u0441\u0442\u0430 \u0434\u043b\u044f ICMP-\u043f\u0438\u043d\u0433\u0430:<\/p>\n<pre><code class=\"cpp\">class BaseTest : boost::noncopyable { protected:  \t\/\/! Pinger implementation type \ttypedef Net::PingerImpl&lt;Test::Primitives&gt; TestPinger;  \tBaseTest() \t{ \t\tm_Pinger.reset(new TestPinger(boost::bind(&BaseTest::Callback, this, _1, _2))); \t}  \tvirtual ~BaseTest() \t{ \t\tm_Pinger-&gt;AddRequest(m_Command); \t\twhile (m_Pinger-&gt;IsActive()) \t\t\tboost::this_thread::interruptible_wait(100); \t}  \ttemplate&lt;typename T&gt; \tvoid Cmd(const Status::Enum status) \t{ \t\tm_Fixture.Push(new T(status)); \t}  \ttemplate&lt;typename T, typename A&gt; \tvoid Cmd(const Status::Enum status, const A& arg) \t{ \t\tm_Fixture.Push(new T(status, arg)); \t}  \tvoid Callback(const Net::PingCommand& \/*cmd*\/, const Net::PingResult& \/*rslt*\/) \t{ \/\/ \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0438\u043d\u0433\u0430 \u043d\u0430\u043c \u043d\u0435 \u0432\u0430\u0436\u0435\u043d, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \t}  \tFixture m_Fixture; \tstd::auto_ptr&lt;TestPinger&gt; m_Pinger; \tNet::PingCommand m_Command; }; \/\/ \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0437\u0430\u043c\u0435\u043d\u0435\u043d\u044b \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \/\/ \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c\u0441\u044f.  class ICMPTest :  public testing::Test, public BaseTest { };  TEST(ICMPTest, ICMPSuccess) { \tm_Command.m_HostName = &quot;ptsecurity.ru&quot;;  \tCmd&lt;Resolve&gt;(Status::Success,  m_Command.m_HostName); \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c IP \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \tCmd&lt;Wait&gt;(Status::Pending);  \/\/ \u0432\u0437\u0432\u043e\u0434\u0438\u043c \u0442\u0430\u0439\u043c\u0435\u0440 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 Status::Pending \u2013 \u0433\u043e\u0432\u043e\u0440\u0438\u043c, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c  \tCmd&lt;Receive&gt;(Status::Success); \/\/ \u0443\u0437\u0435\u043b \u043f\u0440\u0438\u0441\u043b\u0430\u043b \u043f\u0430\u043a\u0435\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u043e\u0442\u0432\u0435\u0442  \tm_Command.m_Flags = SCANMGR_PING_ICMP; \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434 \u043f\u0438\u043d\u0433\u0435\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 BaseTest } TEST(ICMPTest, ICMPFail) { \tm_Command.m_HostName = &quot;ptsecurity.ru&quot;;  \tCmd&lt;Resolve&gt;(Status::Success,  m_Command.m_HostName);  \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c IP \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \tCmd&lt;Wait&gt;(Status::Success);  \/\/ \u0432\u0437\u0432\u043e\u0434\u0438\u043c \u0442\u0430\u0439\u043c\u0435\u0440 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 Status::Success \u2013 \u0433\u043e\u0432\u043e\u0440\u0438\u043c, \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c  \tCmd&lt;Receive&gt;(Status::Pending);  \/\/ \u0436\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0443\u0437\u043b\u0430  \tm_Command.m_Flags = SCANMGR_PING_ICMP; \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434 \u043f\u0438\u043d\u0433\u0435\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 BaseTest  } <\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u0441 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u0438\u043d\u0433\u0435\u0440\u0430 \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e: \u043d\u0443\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432 \u043f\u0438\u043d\u0433\u0430. \u041d\u0430\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0438\u043d\u0433\u0435\u0440\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0445 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 PingerImpl. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0442\u0432\u044f\u0437\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u0442 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/681\/77b\/098\/68177b098e0f48336d2797aa29a56ae1.png\"\/><\/p>\n<p>  \u041d\u0430 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435 \u043a\u043b\u0430\u0441\u0441 TestLogic \u0441\u043e\u0437\u0434\u0430\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"http:\/\/code.google.com\/p\/googlemock\/\">google mock<\/a>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432 \u0442\u0435\u0441\u0442\u0430\u0445 \u043b\u043e\u0433\u0438\u043a\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u044b, \u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445. <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">class TestLogic : public Net::PingerLogic { public:  \tTestLogic(const Net::PingCommand& cmd, const Net::Pinger::Callback& callback) \t\t: Net::PingerLogic(cmd, callback) \t{ \t} \t \tMOCK_METHOD1(InitPorts, void (const std::string& ports)); \tMOCK_METHOD1(ResolveIP, bool (const std::string& name)); \tMOCK_METHOD1(StartResolveNameByIp, void (unsigned long ip)); \tMOCK_METHOD1(StartResolveIpByName, void (const std::string& name)); \tMOCK_METHOD1(StartTCPPing, void (std::size_t timeout)); \tMOCK_METHOD1(StartICMPPing, void (std::size_t timeout)); \tMOCK_METHOD1(StartGetNetBiosName, void (const std::string& name)); \tMOCK_METHOD0(Cancel, void ());  }; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0430\u0440\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u043e\u0432<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">TEST(Logic, Start) { \tconst std::string host = &quot;ptsecurity.ru&quot;;  \tEXPECT_CALL(*m_Logic, InitPorts(g_TargetPorts)).Times(Exactly(1)); \tEXPECT_CALL(*m_Logic, ResolveIP(host)).Times(Exactly(1)).WillOnce(Return(true)); \tEXPECT_CALL(*m_Logic, StartResolveIpByName(host)).Times(Exactly(1));  \tm_Logic-&gt;OnStart(); } TEST(Logic, ResolveIp) { \tstatic const unsigned long ip = 0x10101010;  \tEXPECT_CALL(*m_Logic, StartResolveNameByIp(ip)).Times(Exactly(1)); \tEXPECT_CALL(*m_Logic, StartICMPPing(1)).Times(Exactly(1)); \tEXPECT_CALL(*m_Logic, StartTCPPing(1)).Times(Exactly(1));  \tm_Logic-&gt;OnIpResolved(ip); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c, \u0431\u043b\u0430\u0433\u043e Boost.Asio \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a, \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0446\u0435\u043b\u0435\u0439. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u043e\u0434\u0438\u0442\u0441\u044f, \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0431\u044b\u043b\u043e \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u0431\u0430\u0433\u043e\u0432 \ud83d\ude42 \u0421\u0430\u043c\u043e \u0441\u043e\u0431\u043e\u0439, \u043d\u0430\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0438 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0447\u0430\u0441\u043e\u0432 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u043a\u043e\u0434\u0430. \u0421 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u043f\u0438\u043d\u0433\u0435\u0440\u0430 \u0432 \u043f\u0440\u043e\u0434\u0443\u043a\u0442, \u0432 \u043d\u0435\u043c \u0431\u044b\u043b \u0432\u044b\u044f\u0432\u043b\u0435\u043d \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u043c\u0435\u043b\u043a\u0438\u0439 \u0431\u0430\u0433, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441 \u043d\u0435\u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u043e\u0434\u0430, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442, \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u043e\u0432 \u043f\u043e\u0442\u0440\u0430\u0447\u0435\u043d\u043e \u043d\u0435 \u0437\u0440\u044f!<\/p>\n<p>  \u041e\u0442\u0441\u044e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434\u044b: <\/p>\n<ul>\n<li>\u041c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u0432\u0435\u0449\u044c, \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u043e\u043a\u0440\u044b\u0442 \u0432\u0435\u0441\u044c \u043a\u043e\u0434.<\/li>\n<li>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043b\u044e\u0431\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u043a\u043e\u0434\u0430 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0440\u0435\u0448\u0430\u0435\u043c\u0430! \u041d\u0443\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439.<\/li>\n<\/ul>\n<p>  \u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!    \t \t\t   \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\/company\/pt\/blog\/166139\/\"> http:\/\/habrahabr.ru\/company\/pt\/blog\/166139\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<a href=\"http:\/\/habrahabr.ru\/company\/pt\/blog\/166139\/\"><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/911\/38b\/b30\/91138bb305a4e889e17a99be4176eb16.jpg\" align=\"left\"\/><\/a>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0412 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043d\u0430\u0448\u0438\u0445 <a href=\"http:\/\/habrahabr.ru\/company\/pt\/blog\/156795\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b\u0438 \u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0438\u043d\u0433\u0430 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u00ab\u043f\u0438\u043d\u0433\u0435\u0440\u0430\u00bb \u0434\u043b\u044f \u0435\u0433\u043e \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438 \u043f\u0435\u043d\u0442\u0435\u0441\u0442\u0430\u0445 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0439 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u0441\u0442\u0430\u043d\u0446\u0438\u0439. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0438\u043d\u0433\u0435\u0440\u0430 (\u043b\u043e\u0433\u0438\u043a\u0430 \u0438 \u0441\u0435\u0442\u0435\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c) \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u043c\u0438 \u0442\u0435\u0441\u0442\u0430\u043c\u0438.<\/p>\n<p>  \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u2014 \u0434\u0438\u0441\u0446\u0438\u043f\u043b\u0438\u043d\u0438\u0440\u0443\u0435\u0442 \u0438 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u0435\u0435 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043f\u0435\u0440\u0432\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u043e \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0438 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0430 Boost.Asio \u0431\u044b\u043b\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u0430\u044f: \u00ab\u0427\u0442\u043e?! \u042d\u0442\u043e \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e! \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 \u0443\u0437\u043b\u0430?\u00bb<\/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-166139","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/166139","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=166139"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/166139\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=166139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=166139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=166139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}