{"id":217087,"date":"2014-03-25T21:55:03","date_gmt":"2014-03-25T17:55:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=217087"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=217087","title":{"rendered":"<span class=\"post_title\">\u0421\u0430\u043c\u044b\u0439 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 \u0441++<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412 <a href=\"http:\/\/habrahabr.ru\/post\/213301\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u043f\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430\u043c http \u0438 https. \u041f\u0440\u043e\u0448\u043b\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432.<\/p>\n<p>  \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/3s3s\/simple_server\">\u0433\u0438\u0442\u0445\u0430\u0431\u0435<\/a>, \u0430 \u0435\u0441\u043b\u0438 \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445, \u0442\u043e \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u00ab\u0435\u0433\u0438\u043f\u0435\u0442\u0441\u043a\u0438\u0445 \u0441\u043a\u043e\u0431\u043e\u043a\u00bb, \u043d\u043e\u0432\u043e\u043c\u043e\u0434\u043d\u044b\u0445 \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432. \u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0441\u0442\u0430\u043b\u0430 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437 5 \u0444\u0430\u0439\u043b\u043e\u0432 \u0441 \u043e\u0431\u0449\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c 22.5 \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442. \u0412\u0435\u0440\u0441\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u041b\u0438\u043d\u0443\u043a\u0441 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c 18 \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442 (517 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430).<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0438 \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0441 \u0435\u0435 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0439 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0430\u0439\u0442\u043e\u0432.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0445\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0444\u0430\u0439\u043b\u0430\u0445.<br \/>  \u041f\u0435\u0440\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f serv.cpp \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430:  <\/p>\n<pre><code class=\"cpp\">#include &quot;http_server.h&quot; using namespace server;  CServer&lt;CHttpClient&gt; s(8085, 1111);  int main() {return 0;} <\/code><\/pre>\n<p>  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b \u0433\u0434\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0432\u0435\u0441\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0412 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u0441\u043a\u0430\u0437\u0430\u043b \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u043e\u0441\u0442\u0430.<\/p>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0438\u043f\u0430 CServer, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043d\u043e\u043c\u0435\u0440\u0430 \u043f\u043e\u0440\u0442\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0443\u0448\u0430\u0442\u044c.<br \/>  \u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c CHttpClient (\u043e \u043d\u0435\u043c \u0440\u0435\u0447\u044c \u0447\u0443\u0442\u044c \u043d\u0438\u0436\u0435), \u0441 \u043f\u043e\u0440\u0442\u043e\u043c 8085 \u0434\u043b\u044f \u043f\u0440\u0438\u0435\u043c\u0430 tcp \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0438 \u043f\u043e\u0440\u0442\u043e\u043c 1111 \u0434\u043b\u044f ssl.<\/p>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043d\u0430 \u043e\u0431\u043c\u0435\u043d\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c. \u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f:  <\/p>\n<pre><code class=\"cpp\">\tenum MESSAGE { \t\tI_READY_EPOLL, \t\tI_ACCEPTED, \t\tI_READED, \t\tI_ALL_WRITED, \t\tPLEASE_READ, \t\tPLEASE_WRITE_BUFFER, \t\tPLEASE_WRITE_FILE, \t\tPLEASE_STOP \t}; <\/code><\/pre>\n<p>  \u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u00abI_\u00bb \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u00abPLEASE_\u00bb \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435.<br \/>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441:  <\/p>\n<pre><code class=\"cpp\">\tclass CHttpClient \t{ \tpublic: \t\tconst MESSAGE OnAccepted(shared_ptr&lt;vector&lt;unsigned char&gt;&gt; pvBuffer)  \t\t{***} \t\tconst MESSAGE OnWrited(shared_ptr&lt;vector&lt;unsigned char&gt;&gt; pvBuffer) \t\t{***} \t\tconst MESSAGE OnReaded(shared_ptr&lt;vector&lt;unsigned char&gt;&gt; pvBuffer) \t\t{***} \t};   <\/code><\/pre>\n<p>  \u042d\u0442\u0438 \u0442\u0440\u0438 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u0445 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u043e\u0431\u043c\u0435\u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<br \/>  \u041e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u00ab\u0431\u0443\u0444\u0435\u0440 \u043e\u0431\u043c\u0435\u043d\u0430\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u043c \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u044d\u0442\u0430\u043f\u043d\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0443\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 CHttpClient \u043d\u043e \u043f\u043e\u0442\u043e\u043c \u0440\u0435\u0448\u0438\u043b, \u0447\u0442\u043e \u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u0445\u0430\u0431\u0440\u043e\u0432\u0447\u0430\u043d\u0435 \u0441\u043c\u043e\u0433\u0443\u0442 \u0438 \u0431\u0435\u0437 \u043c\u0435\u043d\u044f \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 115 \u0441\u0442\u0440\u043e\u0447\u043a\u0430\u0445 \u043a\u043e\u0434\u0430 \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0435\u0433\u043e \u0437\u0434\u0435\u0441\u044c \u0446\u0435\u043b\u0438\u043a\u043e\u043c:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a http_server.h<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &quot;server.h&quot;  #define ROOT_PATH\t\t&quot;.\/wwwroot&quot; #define ERROR_PAGE\t\t&quot;error.html&quot; #define DEFAULT_PAGE\t&quot;index.html&quot;  namespace server { \tclass CHttpClient \t{ \t\tint m_nSendFile; \t\toff_t m_nFilePos; \t\tunsigned long long m_nFileSize;  \t\tenum STATES\t{ \t\t\tS_READING_HEADER, \t\t\tS_READING_BODY, \t\t\tS_WRITING_HEADER, \t\t\tS_WRITING_BODY, \t\t\tS_ERROR \t\t}; \t\tSTATES m_stateCurrent; \t\tmap&lt;string, string&gt; m_mapHeader;  \t\tvoid SetState(const STATES state) {m_stateCurrent = state;} \t\tconst bool ParseHeader(const string strHeader) \t\t{ \t\t\tm_mapHeader[&quot;Method&quot;] = strHeader.substr(0, strHeader.find(&quot; &quot;) &gt; 0 ? strHeader.find(&quot; &quot;) : 0); \t\t\tif (m_mapHeader[&quot;Method&quot;] != &quot;GET&quot;) return false; \t\t\t \t\t\tconst int nPathSize = strHeader.find(&quot; &quot;, m_mapHeader[&quot;Method&quot;].length()+1)-m_mapHeader[&quot;Method&quot;].length()-1; \t\t\tif (nPathSize &lt; 0)\treturn false; \t\t\tm_mapHeader[&quot;Path&quot;] = strHeader.substr(m_mapHeader[&quot;Method&quot;].length()+1, nPathSize); \t\t\t \t\t\treturn true; \t\t} \t\tconst MESSAGE OnReadedHeader(const string strHeader, shared_ptr&lt;vector&lt;unsigned char&gt;&gt; pvBuffer) \t\t{ \t\t\tcout &lt;&lt; &quot;Header readed\\n&quot;; \t\t\tif (!ParseHeader(strHeader))\tm_mapHeader[&quot;Path&quot;] = ERROR_PAGE; \t\t\tif (m_mapHeader[&quot;Path&quot;] == &quot;\/&quot;) m_mapHeader[&quot;Path&quot;] += DEFAULT_PAGE;  \t\t\tcout &lt;&lt; &quot;open file&quot; &lt;&lt; ROOT_PATH &lt;&lt; m_mapHeader[&quot;Path&quot;].c_str() &lt;&lt; &quot;\\n&quot;; \t\t\tif ((m_nSendFile = _open((ROOT_PATH+m_mapHeader[&quot;Path&quot;]).c_str(), O_RDONLY|O_BINARY)) == -1) \t\t\t\treturn PLEASE_STOP; \t\t\t \t\t\tstruct stat stat_buf; \t\t\tif (fstat(m_nSendFile, &stat_buf) == -1) \t\t\t\treturn PLEASE_STOP;  \t\t\tm_nFileSize = stat_buf.st_size;  \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\tstd::ostringstream strStream; \t\t\tstrStream &lt;&lt;  \t\t\t\t&quot;HTTP\/1.1 200 OK\\r\\n&quot; \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&quot;\\r\\n&quot;;  \t\t\t\/\/\u0417\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \t\t\tpvBuffer-&gt;resize(strStream.str().length()); \t\t\tmemcpy(&pvBuffer-&gt;at(0), strStream.str().c_str(), strStream.str().length()); \t\t\treturn PLEASE_WRITE_BUFFER; \t\t} \t\texplicit CHttpClient(CHttpClient &client) {} \tpublic: \t\tCHttpClient() : m_nSendFile(-1), m_nFilePos(0), m_nFileSize(0), m_stateCurrent(S_READING_HEADER) {} \t\t~CHttpClient() \t\t{ \t\t\tif (m_nSendFile != -1) _close(m_nSendFile); \t\t} \t\t\t \t\tconst MESSAGE OnAccepted(shared_ptr&lt;vector&lt;unsigned char&gt;&gt; pvBuffer) {return PLEASE_READ;} \t\tconst MESSAGE OnWrited(shared_ptr&lt;vector&lt;unsigned char&gt;&gt; pvBuffer) \t\t{ \t\t\tswitch(m_stateCurrent) { \t\t\t\tcase S_WRITING_HEADER: \t\t\t\t\tif (m_nSendFile == -1) \t\t\t\t\t\treturn PLEASE_STOP;  \t\t\t\t\tSetState(S_WRITING_BODY); \t\t\t\t\tpvBuffer-&gt;resize(sizeof(int)); \t\t\t\t\tmemcpy(&pvBuffer-&gt;at(0), &m_nSendFile, pvBuffer-&gt;size()); \t\t\t\t\treturn PLEASE_WRITE_FILE; \t\t\t\tdefault: \t\t\t\t\treturn PLEASE_STOP; \t\t\t} \t\t} \t\tconst MESSAGE OnReaded(shared_ptr&lt;vector&lt;unsigned char&gt;&gt; pvBuffer) \t\t{ \t\t\tswitch(m_stateCurrent) { \t\t\t\tcase S_READING_HEADER: \t\t\t\t{ \t\t\t\t\t\/\/\u0418\u0449\u0435\u043c \u043a\u043e\u043d\u0435\u0446 http \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0432 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \t\t\t\t\tconst std::string strInputString((const char *)&pvBuffer-&gt;at(0)); \t\t\t\t\tif (strInputString.find(&quot;\\r\\n\\r\\n&quot;) == strInputString.npos) \t\t\t\t\t\treturn PLEASE_READ;  \t\t\t\t\tswitch(OnReadedHeader(strInputString.substr(0, strInputString.find(&quot;\\r\\n\\r\\n&quot;)+4), pvBuffer)) { \t\t\t\t\t\tcase PLEASE_READ: \t\t\t\t\t\t\tSetState(S_READING_BODY); \t\t\t\t\t\t\treturn PLEASE_READ; \t\t\t\t\t\tcase PLEASE_WRITE_BUFFER: \t\t\t\t\t\t\tSetState(S_WRITING_HEADER); \t\t\t\t\t\t\treturn PLEASE_WRITE_BUFFER; \t\t\t\t\t\tdefault: \t\t\t\t\t\t\tSetState(S_ERROR); \t\t\t\t\t\t\treturn PLEASE_STOP; \t\t\t\t\t} \t\t\t\t} \t\t\t\tdefault: return PLEASE_STOP; \t\t\t} \t\t} \t}; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0439: <br \/>  \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043c\u043e\u044f \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u0430\u044f \u043c\u0438\u043a\u0440\u043e\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430,<br \/>  \u043f\u043e\u0442\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u0430,<br \/>  \u043f\u043e\u0442\u043e\u043c \u0438\u0434\u0443\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430,<br \/>  callback-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043b\u044f Visual Studio 2012.<br \/>  \u0414\u043b\u044f \u041b\u0438\u043d\u0443\u043a\u0441\u0430 \u043d\u0443\u0436\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u044b serv.cpp, server.h, http_server.h \u0438 ca-cert.pem. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 gcc 4.5 \u0438 \u0432\u044b\u0448\u0435: \u00abg++ -std=c++0x -L\/usr\/lib -lssl -lcrypto serv.cpp\u00bb<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0432 \u043a\u043e\u0434\u0435 \u043d\u0435 \u043c\u0435\u043d\u044f\u0442\u044c, \u0442\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0443\u0436\u043d\u043e \u0435\u0449\u0435 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 .\/wwwroot \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u0444\u0430\u0439\u043b index.html<\/p>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443:<br \/>  <a href=\"http:\/\/unblok.us:8085\/\">http:\/\/unblok.us:8085\/<\/a><\/p>\n<p>  \u0438\u043b\u0438<br \/>  <a href=\"https:\/\/unblok.us:1111\">https:\/\/unblok.us:1111<\/a>    \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\/217087\/\"> http:\/\/habrahabr.ru\/post\/217087\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412 <a href=\"http:\/\/habrahabr.ru\/post\/213301\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u043f\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430\u043c http \u0438 https. \u041f\u0440\u043e\u0448\u043b\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432.<\/p>\n<p>  \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/3s3s\/simple_server\">\u0433\u0438\u0442\u0445\u0430\u0431\u0435<\/a>, \u0430 \u0435\u0441\u043b\u0438 \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445, \u0442\u043e \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u00ab\u0435\u0433\u0438\u043f\u0435\u0442\u0441\u043a\u0438\u0445 \u0441\u043a\u043e\u0431\u043e\u043a\u00bb, \u043d\u043e\u0432\u043e\u043c\u043e\u0434\u043d\u044b\u0445 \u043b\u044f\u043c\u0431\u0434\u0430-\u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432. \u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0441\u0442\u0430\u043b\u0430 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437 5 \u0444\u0430\u0439\u043b\u043e\u0432 \u0441 \u043e\u0431\u0449\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c 22.5 \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442. \u0412\u0435\u0440\u0441\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u041b\u0438\u043d\u0443\u043a\u0441 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c 18 \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442 (517 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430).<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0438 \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0441 \u0435\u0435 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0439 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0430\u0439\u0442\u043e\u0432.  <\/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-217087","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/217087","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=217087"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/217087\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=217087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=217087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}