{"id":213301,"date":"2014-02-20T12:55:02","date_gmt":"2014-02-20T08:55:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=213301"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=213301","title":{"rendered":"<span class=\"post_title\">\u041a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438. \u0427\u0430\u0441\u0442\u044c 4<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043c\u043e\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435:<br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/211474\/\">\u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u043a\u0440\u043e\u0441c\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 ssl<\/a><br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/211661\/\">\u041a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 https \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438 <\/a><br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/211853\/\">\u041a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 https \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438. \u0427\u0430\u0441\u0442\u044c 2<\/a><br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/212101\/\">\u041a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 https \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438. \u0427\u0430\u0441\u0442\u044c 3<\/a><\/p>\n<p>  \u0412 \u0441\u0432\u043e\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u044f \u043f\u043e\u044d\u0442\u0430\u043f\u043d\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u0441\u043e\u043a\u0435\u0442\u0430\u0445.<br \/>  \u0412\u043e \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445, \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e ssl \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043d\u0435\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e tcp \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 \u0438 \u043d\u0430\u0443\u0447\u0443 \u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0444\u0430\u0439\u043b.<br \/>  \u041d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0439\u0434\u0443\u0441\u044c \u043f\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c \u043a \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u0441\u0442\u0430\u0442\u044c\u044f\u043c.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  1. \u042f \u043f\u043e\u0441\u043b\u0443\u0448\u0430\u043b \u0441\u043e\u0432\u0435\u0442\u043e\u0432 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 printf \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 std::cout.<br \/>  2. \u0423\u043c\u043d\u044b\u0435 \u043b\u044e\u0434\u0438 \u0434\u043e\u043a\u0430\u0437\u0430\u043b\u0438 \u043c\u043d\u0435, \u0447\u0442\u043e std::memcpy \u0438 std::copy \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435. <br \/>  \u041c\u043d\u0435 memcpy \u0443\u0434\u043e\u0431\u043d\u0435\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0443 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0435\u0439.<br \/>  3. <a href=\"https:\/\/github.com\/3s3s\/simple_server\/\">\u042f \u043f\u0435\u0440\u0435\u043d\u0435\u0441 \u0432\u0441\u0435 \u0440\u0430\u043d\u043d\u0438\u0435 \u0440\u0435\u043b\u0438\u0437\u044b \u0438 \u0431\u0443\u0434\u0443 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u044c \u0431\u0443\u0434\u0443\u0449\u0438\u0435 \u043d\u0430 GitHub<\/a>, \u0445\u043e\u0442\u044f \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f Windows \u0443 \u043d\u0438\u0445, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0443\u0436\u0430\u0441\u0435\u043d.<br \/>  4. \u041a\u0442\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0442\u0440\u043e\u0447\u043a\u0438  <\/p>\n<pre><code class=\"cpp\">\t\t\tconst char on = 1; \t\t\tsetsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on) ); <\/code><\/pre>\n<p>  \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u00abAddress already in use\u00bb \u043f\u0440\u0438 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e\u043c \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u2014 \u0436\u0435\u0441\u0442\u043e\u043a\u043e \u043e\u0448\u0438\u0431\u0430\u044e\u0442\u0441\u044f. \u041d\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442.<br \/>  5. \u0422\u0435\u043c, \u043a\u0442\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u0442, \u0447\u0442\u043e \u0440\u0430\u0437\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u043d\u043e\u0441\u0438\u0442\u044c \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u0430\u043c, \u043f\u043e\u0434\u043e\u043b\u044c\u044e \u043c\u0430\u0441\u043b\u0430: \u044f \u0445\u043e\u0447\u0443 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441 CClient \u0432 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u0443\u044e \u0441\u0435\u043a\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430 CServer!<\/p>\n<p>  \u0411\u044b\u043b\u043e:  <\/p>\n<pre><code class=\"cpp\">CClient { *** }; CServer { *** };  <\/code><\/pre>\n<p>  \u0421\u0442\u0430\u043b\u043e:  <\/p>\n<pre><code class=\"cpp\">CServer { \tCClient \t{ \t*** \t}; *** }; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u0442\u0430\u043d\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439, \u043d\u0438 \u0443 \u043a\u043e\u0433\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043c\u044b\u0441\u043b\u0438 \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 CClient: \u044d\u0442\u043e \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c CServer.<\/p>\n<p>  6. \u0418 \u0435\u0449\u0435 \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0444\u0443\u043d\u043a\u0446\u0438\u044f main() \u2014 \u0430\u0442\u0430\u0432\u0438\u0437\u043c, \u0434\u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0439\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430\u043c \u043e\u0442 \u0421\u0418. \u0412 \u0421++ \u043e\u043d\u0430 \u043b\u0438\u0448\u043d\u044f\u044f. \u041d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u044b \u043f\u043e\u043a\u0430 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044e\u0442 \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e.<br \/>  \u041d\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u00ab\u043d\u0430\u043a\u0430\u0437\u0430\u0442\u044c\u00bb \u044d\u0442\u0443 \u043d\u0435\u043d\u0443\u0436\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043e\u0442\u043e\u0431\u0440\u0430\u0432 \u0443 \u043d\u0435\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0447\u0442\u043e-\u043b\u0438\u0431\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u2014 \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u0444\u0430\u0439\u043b serv.cpp \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">#include &quot;server.h&quot;  const server::CServer s(8085, 1111);  int main() {return 0;} <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e \u0433\u043b\u0430\u0432\u043d\u043e\u043c\u2026<\/p>\n<h4>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043d\u0435\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 tcp \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439<\/h4>\n<p>  \u041d\u0435\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u043e\u0440\u0442\u044b \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u2014 \u044d\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0434\u043b\u044f \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u0443\u0448\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u043a\u0435\u0442\u0430.<\/p>\n<p>  \u0412\u043c\u0435\u0441\u0442\u043e  <\/p>\n<pre><code class=\"cpp\">struct epoll_event m_ListenEvent; <\/code><\/pre>\n<p>  \u043f\u0438\u0448\u0435\u043c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430  <\/p>\n<pre><code class=\"cpp\">struct epoll_event m_ListenEventTCP, m_ListenEventSSL; <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u043c\u0435\u0440\u0430 \u043f\u043e\u0440\u0442\u043e\u0432 \u0438 \u043a\u043e\u0434 \u0434\u043b\u044f \u043b\u0438\u043d\u0443\u043a\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u0441\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 TCP \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445:  <\/p>\n<pre><code class=\"cpp\">\t\tCServer(const int nPortTCP, const int nPortSSL) \t\t{ #ifndef WIN32 \t\t\tstruct sigaction sa;\t\t\t \t\t\tmemset(&sa, 0, sizeof(sa));\t\t \t\t\tsa.sa_handler = SIG_IGN;\t\t \t\t\tsigaction(SIGPIPE, &sa, NULL); #else \t\t\tWSADATA wsaData; \t\t\tif ( WSAStartup( MAKEWORD( 2, 2 ), &wsaData ) != 0 ) \t\t\t{ \t\t\t\tcout &lt;&lt; &quot;Could not to find usable WinSock in WSAStartup\\n&quot;; \t\t\t\treturn; \t\t\t} #endif <\/code><\/pre>\n<p>  \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u0446\u0438\u0438 \u0441\u043b\u0443\u0448\u0430\u044e\u0449\u0438\u0445 \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u0438 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430:  <\/p>\n<pre><code class=\"cpp\">\tprivate: \t\tvoid InitListenSocket(const int nPort, struct epoll_event &eventListen) \t\t{ \t\t\tSOCKET listen_sd = socket (AF_INET, SOCK_STREAM, 0); \t\t\tSET_NONBLOCK(listen_sd);    \t\t\tconst char on = 1; \t\t\tsetsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on) );  \t\t\tstruct sockaddr_in sa_serv; \t\t\tmemset (&sa_serv, '\\0', sizeof(sa_serv)); \t\t\tsa_serv.sin_family      = AF_INET; \t\t\tsa_serv.sin_addr.s_addr = INADDR_ANY; \t\t\tsa_serv.sin_port        = htons (nPort);          \/* Server Port number *\/    \t\t\tint err = ::bind(listen_sd, (struct sockaddr*) &sa_serv, sizeof (sa_serv)); \t      \t\t\tif (err == -1) \t\t\t{ \t\t\t\tcout &lt;&lt; &quot;bind error = &quot; &lt;&lt; errno &lt;&lt; &quot;\\n&quot;; \t\t\t\treturn; \t\t\t} \t\t\t\/* Receive a TCP connection. *\/ \t\t\t \t\t\terr = listen (listen_sd, SOMAXCONN);  \t\t\teventListen.data.fd = listen_sd; \t\t\teventListen.events = EPOLLIN | EPOLLET; \t\t\tepoll_ctl (m_epoll, EPOLL_CTL_ADD, listen_sd, &eventListen); \t\t} \t\tvoid AcceptClient(const SOCKET hSocketIn, const bool bIsSSL) \t\t{ \t\t\tcout &lt;&lt; &quot;AcceptClient&quot;; \t\t\tstruct sockaddr_in sa_cli;   \t\t\tsize_t client_len = sizeof(sa_cli); #ifdef WIN32 \t\t\tconst SOCKET sd = accept (hSocketIn, (struct sockaddr*) &sa_cli, (int *)&client_len); #else \t\t\tconst SOCKET sd = accept (hSocketIn, (struct sockaddr*) &sa_cli, (socklen_t *)&client_len); #endif   \t\t\tif (sd != INVALID_SOCKET) \t\t\t{ \t\t\t\tcout &lt;&lt; &quot;Accepted\\n&quot;; \t\t\t\t\/\/\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \t\t\t\tm_mapClients[sd] = shared_ptr&lt;CClient&gt;(new CClient(sd, bIsSSL)); \t\t\t\t\t\t \t\t\t\tauto it = m_mapClients.find(sd); \t\t\t\tif (it == m_mapClients.end()) \t\t\t\t\treturn; \t\t\t\t\t\t \t\t\t\t\/\/\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0432 epoll \t\t\t\tstruct epoll_event ev = it-&gt;second-&gt;GetEvent(); \t\t\t\tepoll_ctl (m_epoll, EPOLL_CTL_ADD, it-&gt;first, &ev); \t\t\t}\t\t\t\t\t \t\t}  <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e m_bIsSSL, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u043c \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u0430 \u043f\u043e\u0442\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u043c callback \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u043c\u043e\u0433\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 TCP \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f\u043c\u0438:<br \/>  \u0412\u043c\u0435\u0441\u0442\u043e  <\/p>\n<pre><code class=\"cpp\">\t\tconst RETCODES AcceptSSL() \t\t{ \t\t\tif (!m_pSSLContext) \/\/\u041d\u0430\u0448 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f SSL \t\t\t\treturn RET_ERROR; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0440\u044c \u0431\u0443\u0434\u0435\u0442:  <\/p>\n<pre><code class=\"cpp\">\t\t\tconst RETCODES AcceptSSL() \t\t\t{ \t\t\t\tcout &lt;&lt; &quot;AcceptSSL\\n&quot;; \t\t\t\tif (!m_bIsSSL) return RET_READY;  \t\t\t\tif (!m_pSSLContext) \t\t\t\t\treturn RET_ERROR; <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043f\u0440\u043e\u0449\u0435 \u043d\u0435\u043a\u0443\u0434\u0430: TCP \u0444\u0443\u043d\u043a\u0446\u0438\u044f accept \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u043b\u043e\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0447\u0430\u0442\u044c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0438 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435.<br \/>  \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432 \u0434\u043b\u044f TCP \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0447\u0430\u043b\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cpp\">\t\t\tconst RETCODES GetSertificate() \t\t\t{ \t\t\t\tcout &lt;&lt; &quot;GetSertificate\\n&quot;; \t\t\t\tif (!m_bIsSSL) return RET_READY; <\/code><\/pre>\n<p>  \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0447\u0438\u0442\u0430\u044e\u0449\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 ContinueRead() \u043d\u0443\u0436\u043d\u043e \u0432\u043c\u0435\u0441\u0442\u043e  <\/p>\n<pre><code class=\"cpp\">\t\t\tunsigned char szBuffer[4096]; \t\t\t \t\t\tconst int err = SSL_read (m_pSSL, szBuffer, 4096); \/\/\u0447\u0438\u0442\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0432 \u0431\u0443\u0444\u0435\u0440 <\/code><\/pre>\n<p>  \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"cpp\">\t\t\t\tstatic char szBuffer[4096]; \t\t\t \t\t\t\t\/\/\u0447\u0438\u0442\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0432 \u0431\u0443\u0444\u0435\u0440 \t\t\t\tint err; \t\t\t\tif (m_bIsSSL) \t\t\t\t\terr = SSL_read (m_pSSL, szBuffer, 4096); \t\t\t\telse \t\t\t\t{ \t\t\t\t\terrno = 0; \t\t\t\t\terr = recv(m_hSocket, szBuffer, 4096, 0); \t\t\t\t} \t\t\t\tm_nLastSocketError = GetLastError(err); <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0434 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0434\u043b\u044f TCP \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f. \u041a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 SSL, \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0431\u0443\u0434\u0435\u0442<br \/>  \u0435\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u0435\u043c\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u043d\u0435\u0442 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0438\u043b\u0438 \u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u043a\u0435\u0442\u044b,<br \/>  \u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0430 WSAEWOULDBLOCK \u0432 Windows \u0438 EWOULDBLOCK \u0432 Linux \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0435 \u043f\u043e\u0434\u043e\u0436\u0434\u0430\u0442\u044c.<br \/>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0430\u043a\u0438\u0435 \u043c\u0430\u043a\u0440\u043e\u0441\u044b:  <\/p>\n<pre><code class=\"cpp\">#ifndef _WIN32 #define S_OK\t\t\t\t0 #define WSAEWOULDBLOCK\t\t\tEWOULDBLOCK #define WSAGetLastError()\t\terrno #endif <\/code><\/pre>\n<p>  \u0418 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e ContinueRead:  <\/p>\n<pre><code class=\"cpp\">\t\t\t\tif (!m_bIsSSL) \t\t\t\t{ \t\t\t\t\tif ((err == 0) || ((m_nLastSocketError != WSAEWOULDBLOCK) && (m_nLastSocketError != S_OK))) \t\t\t\t\t\treturn RET_ERROR; \t\t\t\t} \t\t\t\telse \t\t\t\t{ \t\t\t\t\tif ((err == 0) || ((m_nLastSocketError != SSL_ERROR_WANT_READ) && (m_nLastSocketError != SSL_ERROR_WANT_WRITE))) \t\t\t\t\t\treturn RET_ERROR; \t\t\t\t} <\/code><\/pre>\n<p>  \u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e CClient::GetLastError \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0442\u0430\u043a  <\/p>\n<pre><code class=\"cpp\">\t\tprivate: \t\t\tint GetLastError(int err) const \t\t\t{ \t\t\t\tif (m_bIsSSL) \t\t\t\t\treturn SSL_get_error(m_pSSL, err); \t\t\t\telse \t\t\t\t\treturn WSAGetLastError(); \t\t\t} <\/code><\/pre>\n<p>  \u0421\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 ContinueWrite \u0438 \u043d\u0430\u0448 \u043e\u0434\u043d\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0433\u043e\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u0440\u0438\u0435\u043c\u0430 tcp \u0438 ssl \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0434\u0430\u0442\u044c \u0438\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0435\u0449\u0435 \u043d\u0430\u0443\u0447\u0438\u043c \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043d\u0430\u0448 \u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u0444\u0430\u0439\u043b\u044b.<br \/>  \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u0432 \u044d\u0442\u043e\u043c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0435\u0442 \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 Linux \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0447\u0435\u043c \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445: \u0444\u0443\u043d\u043a\u0446\u0438\u044f sendfile.<br \/>  \u0427\u0442\u043e\u0431\u044b \u043a\u043e\u0434 \u0431\u044b\u043b \u0435\u0434\u0438\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u043c, \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u0441 sendfile \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u043b\u0438 \u0441 epoll: \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u043c\u0443\u043b\u044f\u0442\u043e\u0440 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0438\u0441\u0442\u0435\u043c \u043a\u0440\u043e\u043c\u0435 Linux.<\/p>\n<h5>\u042d\u043c\u0443\u043b\u044f\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 sendfile <\/h5>\n<p>  1. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0443\u0441\u0442\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u00absendfile.h\u00bb, \u00absendfile.cpp\u00bb \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u0445 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 Visual Studio.<br \/>  2. \u0412 sendfile.h \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"cpp\">#ifndef __linux__ #ifndef _SENDFILE_H #define _SENDFILE_H #include &lt;sys\/types.h&gt;  unsigned long long sendfile(int out_fd, int in_fd, off_t *offset, size_t count);  #endif #endif <\/code><\/pre>\n<p>  3. \u0412 sendfile.cpp \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043c \u0442\u0430\u043a\u043e\u0439:<\/p>\n<pre><code class=\"cpp\">#include &lt;io.h&gt; #include &lt;Winsock2.h&gt; #pragma comment(lib, &quot;ws2_32.lib&quot;) #endif  unsigned long long sendfile(int out_fd, int in_fd, off_t *offset, size_t count) { \tstatic unsigned char buffer[4096];  \tif (count &gt; 4096) \t\tcount = 4096;  \toff_t lPos = _lseek(in_fd, *offset, SEEK_SET); \tif (lPos == -1) \t\treturn -1;  \tconst int nReaded = _read(in_fd, buffer, count); \t \tif (nReaded == 0) \t\treturn nReaded; \tif (nReaded == -1) \t\treturn -1;  \t*offset += nReaded;  \terrno = 0; \tconst int nSended = send(out_fd, (const char *)buffer, nReaded, 0);  \tif (nSended != SOCKET_ERROR) \t\treturn nSended;  \tif (WSAGetLastError() != WSAEWOULDBLOCK) \t\treturn -1;  \treturn 0; } #endif <\/code><\/pre>\n<p>  4. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043a\u043b\u0430\u0441\u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0432 Linux \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0430 \u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u2014 \u043d\u0430\u0448\u0438.<br \/>  \u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443:  <\/p>\n<pre><code class=\"cpp\">#ifdef __linux__ #include &lt;sys\/epoll.h&gt; #include &lt;sys\/sendfile.h&gt; #define O_BINARY\t0 #else #include &quot;epoll.h&quot; #include &quot;sendfile.h&quot; #endif #include &lt;sys\/stat.h&gt; #define SEND_FILE &quot;.\/wwwroot\/festooningloops.jpg&quot; <\/code><\/pre>\n<p>  C \u044d\u043c\u0443\u043b\u044f\u0446\u0438\u0435\u0439 sendfile \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438.<\/p>\n<h5>\u041f\u043e\u0441\u044b\u043b\u0430\u0435\u043c \u0444\u0430\u0439\u043b<\/h5>\n<p>  5. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043a\u043b\u0430\u0441\u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0438 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e  <\/p>\n<pre><code class=\"cpp\">\tclass CClient \t{ \t\tint m_nSendFile; \t\toff_t m_nFilePos; \t\tunsigned long long m_nFileSize;  <\/code><\/pre>\n<p>  6. \u0418\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e InitRead()  <\/p>\n<pre><code class=\"cpp\">\t\t\tconst RETCODES InitRead() \t\t\t{ \t\t\t\tif (m_bIsSSL && (!m_pSSLContext || !m_pSSL)) \t\t\t\t\treturn RET_ERROR;  \t\t\t\tm_nSendFile = _open(SEND_FILE, O_RDONLY|O_BINARY); \t\t\t\tif (m_nSendFile == -1) \t\t\t\t\treturn RET_ERROR; \t\t\t \t\t\t\tstruct stat stat_buf; \t\t\t\tif (fstat(m_nSendFile, &stat_buf) == -1) \t\t\t\t\treturn RET_ERROR;  \t\t\t\tm_nFileSize = stat_buf.st_size;  \t\t\t\t\/\/\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u043e\u0442\u0432\u0435\u0442\u0430 http \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a  \t\t\t\tstd::ostringstream strStream; \t\t\t\tstrStream &lt;&lt;  \t\t\t\t\t\t&quot;HTTP\/1.1 200 OK\\r\\n&quot; \t\t\t\t\t\t&lt;&lt; &quot;Content-Type: image\/jpeg\\r\\n&quot; \t\t\t\t\t\t&lt;&lt; &quot;Content-Length: &quot; &lt;&lt; m_nFileSize &lt;&lt; &quot;\\r\\n&quot; &lt;&lt; \t\t\t\t\t\t&quot;\\r\\n&quot;;  \t\t\t\t\/\/\u0417\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \t\t\t\tm_vSendBuffer.resize(strStream.str().length()); \t\t\t\tmemcpy(&m_vSendBuffer[0], strStream.str().c_str(), strStream.str().length());  \t\t\t\treturn RET_READY; \t\t\t} <\/code><\/pre>\n<p>  7. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u043e\u0441\u044b\u043b\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 \u043f\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430\u043c tcp \u0438 ssl:  <\/p>\n<pre><code class=\"cpp\">\t\t\tconst RETCODES SendFileSSL(const int nFile, off_t *offset) \t\t\t{ \t\t\t\tif (nFile == -1 || m_vSendBuffer.size()) \t\t\t\t\treturn ContinueWrite();  \t\t\t\tif (!m_bIsSSL || !m_pSSLContext || !m_pSSL) \t\t\t\t\treturn RET_ERROR;  \t\t\t\tstatic unsigned char buffer[4096];  \t\t\t\toff_t lPos = _lseek(nFile, *offset, SEEK_SET); \t\t\t\tif (lPos == -1) \t\t\t\t\treturn RET_ERROR;  \t\t\t\tconst int nReaded = _read(nFile, buffer, 4096); \t \t\t\t\tif (nReaded == -1) \t\t\t\t\treturn RET_ERROR; \t\t\t \t\t\t\tif (nReaded &gt; 0) \t\t\t\t{ \t\t\t\t\t*offset += nReaded; \t\t\t\t \t\t\t\t\tm_vSendBuffer.resize(nReaded); \t\t\t\t\tmemcpy(&m_vSendBuffer[0], buffer, nReaded); \t\t\t\t}  \t\t\t\treturn RET_WAIT; \t\t\t} \t\t\tconst RETCODES SendFileTCP(const int nFile, off_t *offset) \t\t\t{ \t\t\t\tif (nFile == -1 || m_vSendBuffer.size()) \t\t\t\t\treturn ContinueWrite();  \t\t\t\tconst unsigned long long nSended = sendfile(m_hSocket, nFile, offset, 4096); \t\t\t\tif (nSended == (unsigned long long)-1) \t\t\t\t\treturn RET_ERROR;  \t\t\t\tm_nLastSocketError = WSAEWOULDBLOCK; \t\t\t\treturn RET_WAIT; \t\t\t} \t\t\tconst bool IsAllWrited() const \t\t\t{ \t\t\t\tif (m_nSendFile == -1 && m_vSendBuffer.size()) \t\t\t\t\treturn true;  \t\t\t\tif (m_nFileSize == (unsigned long long)m_nFilePos) \t\t\t\t\treturn true;  \t\t\t\treturn false; \t\t\t} <\/code><\/pre>\n<p>  8. \u0418\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443 callback \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430:  <\/p>\n<pre><code class=\"cpp\">\t\t\t\t\tcase S_WRITING: \t\t\t\t\t{ \t\t\t\t\t\tif (!m_bIsSSL && (SendFileTCP(m_nSendFile, &m_nFilePos) == RET_ERROR)) \t\t\t\t\t\t\treturn false; \t\t\t\t\t\telse if (m_bIsSSL && (SendFileSSL(m_nSendFile, &m_nFilePos) == RET_ERROR)) \t\t\t\t\t\t\treturn false;  \t\t\t\t\t\tif (IsAllWrited()) \t\t\t\t\t\t\tSetState(S_ALL_WRITED, pCurrentEvent); \t\t\t\t\t\treturn true; \t\t\t\t\t} <\/code><\/pre>\n<p>  \u041d\u0430\u0448 \u0441\u0435\u0440\u0432\u0435\u0440 \u0433\u043e\u0442\u043e\u0432!<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043d \u0443\u043c\u0435\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0444\u0435\u0440, \u043d\u043e \u0438 \u0444\u0430\u0439\u043b\u044b. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043a\u0442\u043e-\u0442\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u043b, \u0447\u0442\u043e \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u00abm_nLastSocketError\u00bb\u2026 <br \/>  \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043c\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0436\u0434\u0430\u043b\u0438 \u043e\u0442 \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u043b\u044e\u0431\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f m_nLastSocketError \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e CClient::SetState \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u044f epoll<br \/>  \u043e\u0442 \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u0436\u0434\u0430\u043b\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u044b \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442.  <\/p>\n<pre><code class=\"cpp\">\t\t\tvoid SetState(const STATES state, struct epoll_event *pCurrentEvent)  \t\t\t{ \t\t\t\tm_stateCurrent = state;  \t\t\t\tpCurrentEvent-&gt;events = EPOLLERR | EPOLLHUP; \t\t\t\tif (m_bIsSSL) \t\t\t\t{ \t\t\t\t\tif (m_nLastSocketError == SSL_ERROR_WANT_READ) \t\t\t\t\t\tpCurrentEvent-&gt;events |= EPOLLIN; \t\t\t\t\tif (m_nLastSocketError == SSL_ERROR_WANT_WRITE) \t\t\t\t\t\tpCurrentEvent-&gt;events |= EPOLLOUT; \t\t\t\t\treturn; \t\t\t\t}  \t\t\t\tif (m_nLastSocketError == WSAEWOULDBLOCK) \t\t\t\t{ \t\t\t\t\tif (m_stateCurrent == S_READING) \t\t\t\t\t\tpCurrentEvent-&gt;events |= EPOLLIN; \t\t\t\t\tif (m_stateCurrent == S_WRITING) \t\t\t\t\t\tpCurrentEvent-&gt;events |= EPOLLOUT; \t\t\t\t\treturn; \t\t\t\t}  \t\t\t\tpCurrentEvent-&gt;events |= EPOLLIN | EPOLLOUT; \t\t\t} <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e!<br \/>  <u><i>\u0414\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438\u0432 Visual Studio 2012<\/i><\/u>, \u043e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u0444\u0430\u0439\u043b ssl_test.sln \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0439\u0442\u0435.<br \/>  <u><i>\u0414\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0432 Linux<\/i><\/u> \u0444\u0430\u0439\u043b\u044b epoll.h, epoll.cpp, sendfile.h \u0438 sendfile.cpp <b>\u043d\u0435 \u043d\u0443\u0436\u043d\u044b<\/b>, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0444\u0430\u0439\u043b\u044b: serv.cpp, server.h, ca-cert.pem, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e wwwroot \u0438 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0443\u0434\u0430 \u0444\u0430\u0439\u043b .\/wwwroot\/festooningloops.jpg, \u043f\u043e\u0442\u043e\u043c \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043d\u0430\u0431\u0440\u0430\u0442\u044c: \u00abg++ -std=c++0x -L\/usr\/lib -lssl -lcrypto serv.cpp\u00bb \u041a\u0442\u043e \u0437\u0430\u0447\u0435\u043c-\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0435\u043c\u0443 \u043e\u043f\u0446\u0438\u044e -Wall.<\/p>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435 \u043c\u043e\u0436\u043d\u043e, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u043d\u0430\u0431\u0440\u0430\u0432 \u0432 \u0430\u0434\u0440\u0435\u0441\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430<br \/>  <code>https:\/\/localhost:1111<\/code><br \/>  \u0438\u043b\u0438<br \/>  <code>http:\/\/localhost:8085<\/code>    \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\/213301\/\"> http:\/\/habrahabr.ru\/post\/213301\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043c\u043e\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435:<br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/211474\/\">\u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u043a\u0440\u043e\u0441c\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 ssl<\/a><br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/211661\/\">\u041a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 https \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438 <\/a><br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/211853\/\">\u041a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 https \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438. \u0427\u0430\u0441\u0442\u044c 2<\/a><br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/212101\/\">\u041a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 https \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438. \u0427\u0430\u0441\u0442\u044c 3<\/a><\/p>\n<p>  \u0412 \u0441\u0432\u043e\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u044f \u043f\u043e\u044d\u0442\u0430\u043f\u043d\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u0441\u043e\u043a\u0435\u0442\u0430\u0445.<br \/>  \u0412\u043e \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445, \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e ssl \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0443. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u043d\u0435\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e tcp \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 \u0438 \u043d\u0430\u0443\u0447\u0443 \u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0444\u0430\u0439\u043b.<br \/>  \u041d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0439\u0434\u0443\u0441\u044c \u043f\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c \u043a \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u0441\u0442\u0430\u0442\u044c\u044f\u043c.  <\/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-213301","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/213301","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=213301"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/213301\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=213301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=213301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=213301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}