{"id":201826,"date":"2013-11-12T11:10:08","date_gmt":"2013-11-12T07:10:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=201826"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=201826","title":{"rendered":"<span class=\"post_title\">\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c: \u043d\u0430\u0437\u0430\u0434 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u0435<\/span>"},"content":{"rendered":"<div class=\"content html_format\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/397\/9e6\/382\/3979e63829a5f92aff5605016ff37596.jpg\" \/><\/div>\n<p><br clear=\"all\"\/>  \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c\u2026 \u0423\u0441\u043b\u044b\u0448\u0430\u0432 \u044d\u0442\u043e \u0441\u043b\u043e\u0432\u043e, \u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0431\u043b\u0435\u0441\u0442\u0435\u0442\u044c \u0433\u043b\u0430\u0437\u0430, \u0434\u044b\u0445\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u044b\u043c, \u0440\u0443\u043a\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0442\u0440\u044f\u0441\u0442\u0438\u0441\u044c, \u0433\u043e\u043b\u043e\u0441 \u2014 \u0437\u0430\u0438\u043a\u0430\u0442\u044c\u0441\u044f, \u043c\u043e\u0437\u0433 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0443\u0440\u043e\u0432\u043d\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438\u2026 \u0423 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u0432 \u043e\u043a\u0440\u0443\u0433\u043b\u044f\u044e\u0442\u0441\u044f \u0433\u043b\u0430\u0437\u0430, \u0437\u0432\u0443\u043a\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043d\u0435\u0447\u043b\u0435\u043d\u043e\u0440\u0430\u0437\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438, \u0440\u0443\u043a\u0438 \u0441\u0436\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u0443\u043b\u0430\u043a\u0438, \u0430 \u0433\u043e\u043b\u043e\u0441 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u043e\u0431\u0435\u0440\u0442\u043e\u043d\u0430\u2026 \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435, \u0447\u0442\u043e \u0438\u0445 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u2014 \u044d\u0442\u043e \u0443\u0447\u0430\u0449\u0435\u043d\u043d\u044b\u0439 \u043f\u0443\u043b\u044c\u0441. \u0422\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b: \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u0440\u0432\u0443\u0442\u0441\u044f \u0432 \u0431\u043e\u0439, \u0430 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u044b \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u0445\u0440\u0443\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0440 \u0438 \u043e\u0441\u043e\u0437\u043d\u0430\u0442\u044c \u0440\u0438\u0441\u043a\u0438, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0441\u0443\u0434\u043e\u0440\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0441\u0440\u043e\u043a\u043e\u0432 \u0432 \u0440\u0430\u0437\u044b\u2026 \u0418 \u0443\u0436\u0435 \u043f\u043e\u0442\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043e\u0441\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u0438 \u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u0432\u0441\u044e \u0433\u043e\u0440\u0435\u0447\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u043e\u0432\u043e\u0434\u044f \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u043d\u043e\u0447\u0438 \u0432 \u0434\u0435\u0431\u0430\u0433\u0433\u0435\u0440\u0435, \u043e\u0442\u0447\u0430\u044f\u043d\u043d\u043e \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0436\u0435 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u2026<\/p>\n<p>  \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443 \u0440\u0438\u0441\u0443\u0435\u0442 \u043c\u043e\u0435 \u0432\u043e\u0441\u043f\u0430\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0441\u043b\u043e\u0432\u0435 \u201c\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c\u201d. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432\u0441\u0435 \u044d\u0442\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u044d\u043c\u043e\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u0438 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0430\u0432\u0434\u0430. \u0412\u0435\u0434\u044c \u0442\u0430\u043a?.. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043a\u0430\u0436\u0443\u0442, \u0447\u0442\u043e \u201c\u043f\u0440\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u043e\u201d. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u0438 \u0432\u0435\u0437\u0434\u0435 \u043f\u0440\u0438 \u0432\u0441\u044f\u043a\u043e\u043c \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0438 \u043d\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435. \u041d\u043e \u043b\u0443\u0447\u0448\u0435 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f, \u0431\u0430\u0433\u0438 \u043d\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f, \u0430 \u0431\u0435\u0441\u0441\u043e\u043d\u043d\u0438\u0446\u0430 \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442.<\/p>\n<p>  \u0422\u0430\u043a \u0447\u0442\u043e \u0436\u0435 \u0442\u0430\u043a\u043e\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c? \u041f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d\u0430 \u0442\u0430\u043a \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u0430? \u0410 \u0433\u043b\u0430\u0432\u043d\u043e\u0435: \u0447\u0442\u043e \u0441 \u043d\u0435\u0439 \u043d\u0435 \u0442\u0430\u043a?<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u0442\u0435\u043c\u043e\u0439. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u0445\u0430\u0431\u0440\u0435, \u0447\u0442\u043e\u0431\u044b \u0432 \u044d\u0442\u043e\u043c \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f. \u0422\u0443\u0442 \u0442\u0435\u0431\u0435 \u0438 \u043e\u0431\u0437\u043e\u0440 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044f\u0437\u044b\u043a\u0430 Go, \u0438 \u0432\u0441\u044f\u043a\u0438\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u043d\u0430 JS, \u0438 \u043c\u043d\u043e\u0433\u043e \u0447\u0435\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e.<\/p>\n<p>  \u041e\u0431\u044b\u0447\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0435\u0442\u0435\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f: \u0432\u0441\u044f\u043a\u0438\u0435 \u0441\u043e\u043a\u0435\u0442\u044b-\u0448\u043c\u043e\u043a\u0435\u0442\u044b, \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438-\u043f\u0438\u0441\u0430\u0442\u0435\u043b\u0438 \u0438 \u043f\u0440\u043e\u0447\u0438\u0435 \u0430\u043a\u0446\u0435\u043f\u0442\u043e\u0440\u044b. \u041d\u043e \u0431\u044b\u0432\u0430\u044e\u0442 \u0435\u0449\u0435 \u0437\u0430\u0431\u0430\u0432\u043d\u044b\u0435 \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 UI. \u0417\u0434\u0435\u0441\u044c \u044f \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0435\u0442\u0435\u0432\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435. \u041e\u0434\u043d\u0430\u043a\u043e, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0438 \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0442\u044c \u0432 \u043d\u0435\u0432\u0435\u0434\u043e\u043c\u044b\u0435 \u0434\u0430\u043b\u0438.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u0443\u0436 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c, \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 HTTP \u0441\u0435\u0440\u0432\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430 \u043d\u0435\u043a\u0438\u0439 \u043b\u044e\u0431\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442 \u043d\u0435\u043a\u0438\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442. \u042d\u0442\u043e \u0447\u0442\u043e\u0431 \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0430\u0440\u0441\u0435\u0440, \u0442.\u043a. \u043a \u0442\u0435\u043c\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438 \u043e\u043d \u0438\u043c\u0435\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u0442\u0430\u043a\u043e\u0435 \u0436\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435, \u043a\u0430\u043a \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0432\u0435\u0437\u0434 \u043a \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0443 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 (\u0441\u043c. \u0430\u0441\u0442\u0440\u043e\u043b\u043e\u0433\u0438\u044e).<\/p>\n<h3>\u0421\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043e\u0434\u043d\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440<\/h3>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/688\/f49\/134\/688f4913476148d4276eda6579208143.jpg\" \/><\/div>\n<p><br clear=\"all\"\/>  \u0425\u043c. \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439? \u0410 \u043f\u0440\u0438 \u0447\u0435\u043c \u0442\u0443\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439, \u0441\u043f\u0440\u043e\u0441\u0438\u0442 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c, \u043e\u0442\u043a\u0440\u044b\u0432 \u0441\u0442\u0430\u0442\u044c\u044e \u043f\u0440\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c. \u041d\u0443, \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043d\u0430\u0434\u043e \u0436\u0435 \u0441 \u0447\u0435\u0433\u043e-\u0442\u043e \u043d\u0430\u0447\u0430\u0442\u044c. \u0421 \u0447\u0435\u0433\u043e-\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e. \u0410 \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445\u2026 \u041a\u043e\u0440\u043e\u0447\u0435, \u044f \u0430\u0432\u0442\u043e\u0440, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a. \u0410 \u043f\u043e\u0442\u043e\u043c \u0438 \u0441\u0430\u043c\u0438 \u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u0437\u0430\u0447\u0435\u043c.<\/p>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u043e\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439 \u043a\u043e\u0434, \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043d\u0430\u0448\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0449\u043d\u0443\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <abbr title=\"Portable networking, including sockets, timers, hostname resolution and socket iostreams.\">boost.asio<\/abbr>. \u0411\u043b\u0430\u0433\u043e, \u0441\u0442\u0430\u0442\u0435\u0439 \u0443\u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043f\u0440\u043e \u043d\u0435\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043d\u0435\u043c\u043d\u043e\u0436\u043a\u043e \u0432 \u0442\u0435\u043c\u0435.<\/p>\n<p>  \u041e\u043f\u044f\u0442\u044c \u0436\u0435, \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0438 \u201c\u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u043d\u043e\u0441\u0442\u0438\u201d \u043a\u043e\u0434\u0430 \u044f \u0441\u0434\u0435\u043b\u0430\u044e \u043e\u0431\u0435\u0440\u0442\u043a\u0438 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <abbr title=\"Portable networking, including sockets, timers, hostname resolution and socket iostreams.\">boost.asio<\/abbr>. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043a\u043e\u043c\u0443-\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u043d\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u0440\u0442\u044f\u043d\u043a\u0438 \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 <code>boost::asio::ip::tcp::socket<\/code> \u0438\u043b\u0438 <code>boost::asio::ip::udp::resolver::iterator<\/code>, \u043d\u043e \u044f\u0441\u043d\u043e\u0441\u0442\u044c \u0438 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u043e\u043a\u0435\u0442\u0430 \u0438 \u0430\u043a\u0446\u0435\u043f\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"cpp\">typedef std::string Buffer;  \/\/ forward declaration struct Acceptor; struct Socket {     friend struct Acceptor;          Socket();     Socket(Socket&& s);          \/\/ \u0447\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430     void read(Buffer&);          \/\/ \u0447\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430     void readSome(Buffer&);          \/\/ \u0447\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043f\u043b\u043e\u0442\u044c \u0434\u043e \u0441\u0442\u0440\u043e\u043a\u0438 until     int readUntil(Buffer&, const Buffer& until);          \/\/ \u0437\u0430\u043f\u0438\u0441\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430     void write(const Buffer&);          \/\/ \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u043e\u043a\u0435\u0442\u0430     void close();  private:     boost::asio::ip::tcp::socket socket; };  struct Acceptor {     \/\/ \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u043f\u043e\u0440\u0442 \u0434\u043b\u044f \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439     explicit Acceptor(int port);          \/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043e\u043a\u0435\u0442\u0430 \u043d\u0430 \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435     void accept(Socket& socket);  private:     boost::asio::ip::tcp::acceptor acceptor; }; <\/code><\/pre>\n<p>  \u041d\u0438\u0447\u0435\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0433\u043e, \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440. <code>Socket<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u0447\u0438\u0442\u0430\u0442\u044c, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0434\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 (<code>readUntil<\/code>). <code>Acceptor<\/code> \u0441\u043b\u0443\u0448\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 \u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u0445\u043e\u0437\u044f\u0439\u0441\u0442\u0432\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0430 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"cpp\">boost::asio::io_service& service() {     return single&lt;boost::asio::io_service&gt;(); }  Socket::Socket() :     socket(service()) { }  Socket::Socket(Socket&& s) :     socket(std::move(s.socket)) { }  void Socket::read(Buffer& buffer) {     boost::asio::read(socket, boost::asio::buffer(&buffer[0], buffer.size())); }  void Socket::readSome(Buffer& buffer) {     buffer.resize(socket.read_some(boost::asio::buffer(&buffer[0], buffer.size()))); }  bool hasEnd(size_t posEnd, const Buffer& b, const Buffer& end) {     return posEnd &gt;= end.size() &&         b.rfind(end, posEnd - end.size()) != std::string::npos; }  int Socket::readUntil(Buffer& buffer, const Buffer& until) {     size_t offset = 0;     while (true)     {         size_t bytes = socket.read_some(boost::asio::buffer(&buffer[offset], buffer.size() - offset));         offset += bytes;         if (hasEnd(offset, buffer, until))         {             buffer.resize(offset);             return offset;         }         if (offset == buffer.size())         {             LOG(&quot;not enough size: &quot; &lt;&lt; buffer.size());             buffer.resize(buffer.size() * 2);         }     } }  void Socket::write(const Buffer& buffer) {     boost::asio::write(socket, boost::asio::buffer(&buffer[0], buffer.size())); }  void Socket::close() {     socket.close(); }  Acceptor::Acceptor(int port) :     acceptor(service(), boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)) { }  void Acceptor::accept(Socket& socket) {     acceptor.accept(socket.socket); } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d \u0434\u043b\u044f <code>io_service<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0432 \u0441\u043e\u043a\u0435\u0442 \u044f\u0432\u043d\u043e \u0432\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445. \u0418 \u043e\u0442\u043a\u0443\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e <code>io_service<\/code>? \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0435\u0433\u043e \u0441\u043f\u0440\u044f\u0442\u0430\u043b \u043f\u043e\u0434\u0430\u043b\u044c\u0448\u0435, \u0447\u0442\u043e\u0431\u044b \u0433\u043b\u0430\u0437\u0430 \u043d\u0435 \u043c\u043e\u0437\u043e\u043b\u0438\u043b. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435, \u044f \u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c, \u0431\u044b\u0442\u044c \u043c\u043e\u0436\u0435\u0442, \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>readUntil<\/code>. \u041d\u043e \u0441\u0443\u0442\u044c \u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u0430: \u0447\u0438\u0442\u0430\u0442\u044c \u0431\u0430\u0439\u0442\u0438\u043a\u0438 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u0441\u044f \u0437\u0430\u0432\u0435\u0442\u043d\u043e\u0435 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0435. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0434\u043b\u044f HTTP, \u0442.\u043a. \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0440\u0430\u0437\u043c\u0435\u0440 \u043c\u044b, \u0443\u0432\u044b, \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0434\u0430\u0442\u044c. \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0435\u0441\u0430\u0439\u0437\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0434\u043e\u043b\u0433\u043e\u0436\u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440. \u0412\u043e\u0442 \u043e\u043d:<\/p>\n<pre><code class=\"cpp\">#define HTTP_DELIM          &quot;\\r\\n&quot; #define HTTP_DELIM_BODY     HTTP_DELIM HTTP_DELIM  \/\/ \u043d\u0430\u0448 \u043e\u0442\u0432\u0435\u0442 Buffer httpContent(const Buffer& body) {     std::ostringstream o;     o &lt;&lt; &quot;HTTP\/1.1 200 Ok&quot; HTTP_DELIM         &quot;Content-Type: text\/html&quot; HTTP_DELIM         &quot;Content-Length: &quot; &lt;&lt; body.size() &lt;&lt; HTTP_DELIM_BODY         &lt;&lt; body;     return o.str(); }  \/\/ \u0441\u043b\u0443\u0448\u0430\u0435\u043c 8800 \u043f\u043e\u0440\u0442 (\u0432\u0434\u0440\u0443\u0433 80 \u0437\u0430\u043d\u044f\u0442?) Acceptor acceptor(8800); LOG(&quot;accepting&quot;); while (true) {     Socket socket;     acceptor.accept(socket);     try     {         LOG(&quot;accepted&quot;);         Buffer buffer(4000, 0);         socket.readUntil(buffer, HTTP_DELIM_BODY);         socket.write(httpContent(&quot;&lt;h1&gt;Hello sync singlethread!&lt;\/h1&gt;&quot;));         socket.close();     }     catch (std::exception& e)     {         LOG(&quot;error: &quot; &lt;&lt; e.what());     } } <\/code><\/pre>\n<p>  \u0421\u0435\u0440\u0432\u0435\u0440 \u0433\u043e\u0442\u043e\u0432!<\/p>\n<h3>\u0421\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440<\/h3>\n<p>\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b:  <\/p>\n<ol>\n<li>\u041d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.<\/li>\n<li>\u041a\u043b\u0438\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0430 \u043c\u044b \u0435\u0433\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c.<\/li>\n<\/ol>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0434\u0435\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u0432\u043d\u0435\u0437\u0430\u043f\u043d\u043e \u043d\u0430\u0437\u043e\u0432\u0443 <code>go<\/code>:<\/p>\n<pre><code class=\"cpp\">typedef std::function&lt;void ()&gt; Handler;  void go(Handler handler) {     LOG(&quot;sync::go&quot;);     std::thread([handler] {         try         {             LOG(&quot;new thread had been created&quot;);             handler();             LOG(&quot;thread was ended successfully&quot;);         }         catch (std::exception& e)         {             LOG(&quot;thread was ended with error: &quot; &lt;&lt; e.what());         }     }).detach(); } <\/code><\/pre>\n<p>  \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043e\u0434\u043d\u0443 \u0437\u0430\u0431\u0430\u0432\u043d\u0443\u044e \u0432\u0435\u0449\u044c: \u0435\u0441\u043b\u0438 \u0443\u0431\u0440\u0430\u0442\u044c <code>detach()<\/code>, \u0442\u043e \u0443\u0433\u0430\u0434\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430?<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041e\u0442\u0432\u0435\u0442:<\/b><\/p>\n<div class=\"spoiler_text\">\u0422\u0443\u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430, \u0442\u0430\u043a \u0434\u0435\u0440\u0436\u0430\u0442\u044c!<\/div>\n<\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"cpp\">Acceptor acceptor(8800); LOG(&quot;accepting&quot;); while (true) {     Socket* toAccept = new Socket;     acceptor.accept(*toAccept);     LOG(&quot;accepted&quot;);     go([toAccept] {         try         {             Socket socket = std::move(*toAccept);             delete toAccept;             Buffer buffer;             while (true)             {                 buffer.resize(4000);                 socket.readUntil(buffer, HTTP_DELIM_BODY);                 socket.write(httpContent(&quot;&lt;h1&gt;Hello sync multithread!&lt;\/h1&gt;&quot;));             }         }         catch (std::exception& e)         {             LOG(&quot;error: &quot; &lt;&lt; e.what());         }     }); } <\/code><\/pre>\n<p>  \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u043d\u0435 \u0442\u0443\u0442 \u0442\u043e \u0431\u044b\u043b\u043e: \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u044d\u0442\u043e \u0434\u0435\u043b\u043e \u043b\u043e\u0436\u0438\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u043f\u043e\u0442\u043e\u043c \u043d\u0435 \u043e\u0442\u0436\u0438\u043c\u0430\u0435\u0442\u0441\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443\u043c\u043d\u044b\u0435 \u0434\u044f\u0434\u044c\u043a\u0438 \u043f\u043e\u0434\u0443\u043c\u0430\u043b\u0438, \u043f\u043e\u0434\u0443\u043c\u0430\u043b\u0438, \u0438 \u0440\u0435\u0448\u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<h3>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440<\/h3>\n<p>\u0412 \u0447\u0435\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430? \u0410 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u0442\u043e\u043a\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0436\u0438\u0434\u0430\u044e\u0442 \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u0445 \u0438\u0437 \u0441\u0435\u0442\u0438, \u043e\u0442\u0436\u0438\u0440\u0430\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u0425\u043e\u0447\u0435\u0442\u0441\u044f \u043a\u0430\u043a-\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u0438 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0443\u0436\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0430\u043a\u0442\u043e\u0440\u0430. \u0427\u0442\u043e \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442? \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c callback, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0437\u043e\u0432\u0435\u0442\u0441\u044f \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u0422.\u0435. \u043d\u0430\u0441 \u043f\u043e\u0437\u043e\u0432\u0443\u0442 \u0441\u0430\u043c\u0438, \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f. \u042d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u0440\u0435\u0430\u043a\u0442\u043e\u0440\u0430, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0430\u043c\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u044f \u0437\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u0422\u0438\u043f\u0438\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043a\u0442\u043e\u0440\u0430: epoll, kqueue \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 select\u2019\u044b. \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0430\u043a\u0442\u043e\u0440\u0430: <abbr title=\"I\/O Completion Ports\">IOCP<\/abbr> \u043d\u0430 Windows. \u042f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0430\u043a\u0442\u043e\u0440 <abbr title=\"Portable networking, including sockets, timers, hostname resolution and socket iostreams.\">boost.asio<\/abbr>.<\/p>\n<p>  \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b:<\/p>\n<pre><code class=\"cpp\">typedef boost::system::error_code Error; typedef std::function&lt;void(const Error&)&gt; IoHandler;  struct Acceptor; struct Socket {     friend struct Acceptor;          Socket();     Socket(Socket&&);          void read(Buffer&, IoHandler);     void readSome(Buffer&, IoHandler);     void readUntil(Buffer&, Buffer until, IoHandler);     void write(const Buffer&, IoHandler);     void close();      private:     boost::asio::ip::tcp::socket socket; };  struct Acceptor {     explicit Acceptor(int port);          void accept(Socket&, IoHandler);  private:     boost::asio::ip::tcp::acceptor acceptor; }; <\/code><\/pre>\n<p>  \u0421\u0442\u043e\u0438\u0442 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u0435\u0449\u0430\u0445:  <\/p>\n<ol>\n<li>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0443 \u043d\u0430\u0441 2 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430: \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u043a\u043e\u0434\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u043b\u0438\u0431\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f (\u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438). \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d: \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u0422.\u0435. \u0434\u0430\u0436\u0435 \u043d\u0435 \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0430 \u043a\u0430\u043a \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. \u0418 \u0445\u043e\u0447\u0435\u0448\u044c, \u043d\u0435 \u0445\u043e\u0447\u0435\u0448\u044c \u2014 \u0431\u0443\u0434\u044c \u043b\u044e\u0431\u0435\u0437\u0435\u043d \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u043a\u0430\u043a \u0432 \u0441\u0442\u0430\u0440\u044b\u0435 \u0434\u043e\u0431\u0440\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0430, \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0435\u0449\u0435 \u043d\u0435 \u0431\u044b\u043b\u043e: \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u0438\u0445 \u043f\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435. \u041d\u043e \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435 \u044d\u0442\u043e; \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u2014 \u044d\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0438 \u0435\u0435 \u043d\u0430\u0434\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u0412\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u2014 \u0438\u0437\u043b\u044e\u0431\u043b\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f!<\/li>\n<li>\u0414\u043b\u044f \u0435\u0434\u0438\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <code>IoHandler<\/code>, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u043c.<\/li>\n<\/ol>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c\u0441\u044f, \u0442\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430.<\/p>\n<p>  \u041d\u0443 \u0447\u0442\u043e \u0436, \u0432\u0440\u043e\u0434\u0435 \u043f\u043e\u043a\u0430 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0433\u043e \u043d\u0435\u0442.<\/p>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">Socket::Socket() :     socket(service()) { }  Socket::Socket(Socket&& s) :     socket(std::move(s.socket)) { }  void Socket::read(Buffer& buffer, IoHandler handler) {     boost::asio::async_read(socket, boost::asio::buffer(&buffer[0], buffer.size()),         [&buffer, handler](const Error& error, std::size_t) {             handler(error);     });  }  void Socket::readSome(Buffer& buffer, IoHandler handler) {     socket.async_read_some(boost::asio::buffer(&buffer[0], buffer.size()),         [&buffer, handler](const Error& error, std::size_t bytes) {             buffer.resize(bytes);             handler(error);     }); }  bool hasEnd(size_t posEnd, const Buffer& b, const Buffer& end) {     return posEnd &gt;= end.size() &&         b.rfind(end, posEnd - end.size()) != std::string::npos; }  void Socket::readUntil(Buffer& buffer, Buffer until, IoHandler handler) {     VERIFY(buffer.size() &gt;= until.size(), &quot;Buffer size is smaller than expected&quot;);     struct UntilHandler     {         UntilHandler(Socket& socket_, Buffer& buffer_, Buffer until_, IoHandler handler_) :             offset(0),             socket(socket_),             buffer(buffer_),             until(std::move(until_)),             handler(std::move(handler_))         {         }                  void read()         {             LOG(&quot;read at offset: &quot; &lt;&lt; offset);             socket.socket.async_read_some(boost::asio::buffer(&buffer[offset], buffer.size() - offset), *this);         }                  void complete(const Error& error)         {             handler(error);         }                  void operator()(const Error& error, std::size_t bytes)         {             if (!!error)             {                 return complete(error);             }             offset += bytes;             VERIFY(offset &lt;= buffer.size(), &quot;Offset outside buffer size&quot;);             LOG(&quot;buffer: '&quot; &lt;&lt; buffer.substr(0, offset) &lt;&lt; &quot;'&quot;);             if (hasEnd(offset, buffer, until))             {                 \/\/ found end                 buffer.resize(offset);                 return complete(error);             }             if (offset == buffer.size())             {                 LOG(&quot;not enough size: &quot; &lt;&lt; buffer.size());                 buffer.resize(buffer.size() * 2);             }             read();         }              private:         size_t offset;         Socket& socket;         Buffer& buffer;         Buffer until;         IoHandler handler;     };     UntilHandler(*this, buffer, std::move(until), std::move(handler)).read(); }  void Socket::write(const Buffer& buffer, IoHandler handler) {     boost::asio::async_write(socket, boost::asio::buffer(&buffer[0], buffer.size()),         [&buffer, handler](const Error& error, std::size_t) {             handler(error);     });  }  void Socket::close() {     socket.close(); }  Acceptor::Acceptor(int port) :     acceptor(service(), boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)) { }  void Acceptor::accept(Socket& socket, IoHandler handler) {     acceptor.async_accept(socket.socket, handler); } <\/code><\/pre>\n<p>  \u0422\u0443\u0442 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0430 <code>readUntil<\/code>. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u043e\u043a\u0435\u0442\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>UntilHandler<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u041f\u043e\u0445\u043e\u0436\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u0432 <abbr title=\"Portable networking, including sockets, timers, hostname resolution and socket iostreams.\">boost.asio<\/abbr> \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>boost::asio::read<\/code>), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 (\u043d\u043e \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445) \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<p>  \u041f\u043e\u043c\u0438\u043c\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433 <code>go<\/code> \u0438 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"cpp\">void go(Handler); void dispatch(int threadCount = 0); <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u0432 \u043f\u0443\u043b\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0438, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0443\u043b\u0430 \u043f\u043e\u0442\u043e\u043a \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439.<\/p>\n<p>  \u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">void go(Handler handler) {     LOG(&quot;async::go&quot;);     service().post(std::move(handler)); }  void run() {     service().run(); }  void dispatch(int threadCount) {     int threads = threadCount &gt; 0 ? threadCount : int(std::thread::hardware_concurrency());     RLOG(&quot;Threads: &quot; &lt;&lt; threads);     for (int i = 1; i &lt; threads; ++ i)         sync::go(run);     run(); } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>sync::go<\/code> \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0438\u0437 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430.<\/p>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430:<\/p>\n<pre><code class=\"cpp\">Acceptor acceptor(8800); LOG(&quot;accepting&quot;); Handler accepting = [&acceptor, &accepting] {     struct Connection     {         Buffer buffer;         Socket socket;                  void handling()         {             buffer.resize(4000);             socket.readUntil(buffer, HTTP_DELIM_BODY, [this](const Error& error) {                 if (!!error)                 {                     LOG(&quot;error on reading: &quot; &lt;&lt; error.message());                     delete this;                     return;                 }                 LOG(&quot;read&quot;);                 buffer = httpContent(&quot;&lt;h1&gt;Hello async!&lt;\/h1&gt;&quot;);                 socket.write(buffer, [this](const Error& error) {                     if (!!error)                     {                         LOG(&quot;error on writing: &quot; &lt;&lt; error.message());                         delete this;                         return;                     }                     LOG(&quot;written&quot;);                     handling();                 });             });         }     };          Connection* conn = new Connection;     acceptor.accept(conn-&gt;socket, [conn, &accepting](const Error& error) {         if (!!error)         {             LOG(&quot;error on accepting: &quot; &lt;&lt; error.message());             delete conn;             return;         }         LOG(&quot;accepted&quot;);         conn-&gt;handling();         accepting();     }); };  accepting(); dispatch(); <\/code><\/pre>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/b8f\/44f\/577\/b8f44f577ce67324882dc94800a19ad8.jpg\" \/><\/div>\n<p><br clear=\"all\"\/>  \u0412\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043d\u044f. \u0421 \u043a\u0430\u0436\u0434\u044b\u043c \u043d\u043e\u0432\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0440\u0430\u0441\u0442\u0435\u0442 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043b\u044f\u043c\u0431\u0434. \u041e\u0431\u044b\u0447\u043d\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0442\u0430\u043a\u043e\u0435 \u0447\u0435\u0440\u0435\u0437 \u043b\u044f\u043c\u0431\u0434\u044b \u043d\u0435 \u043f\u0438\u0448\u0443\u0442, \u0442.\u043a. \u0435\u0441\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441 \u0437\u0430\u0446\u0438\u043a\u043b\u0438\u0432\u0430\u043d\u0438\u0435\u043c: \u0432 \u043b\u044f\u043c\u0431\u0434\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u0443 \u0441\u0435\u0431\u044f, \u0447\u0442\u043e\u0431\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0430\u043c\u043e\u0439 \u0441\u0435\u0431\u044f \u043f\u043e\u0437\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u0443 \u0441\u0435\u0431\u044f. \u041d\u043e \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0430\u044f, \u0442.\u0435. \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e \u043f\u043b\u043e\u0445\u0430\u044f \u043f\u0440\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430:  <\/p>\n<ol>\n<li>\u0411\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u043f\u043b\u044e\u0441 (\u0438 \u044d\u0442\u043e, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0442\u043e, \u0440\u0430\u0434\u0438 \u0447\u0435\u0433\u043e \u0432\u0441\u0435 \u044d\u0442\u0438 \u043c\u0443\u0447\u0435\u043d\u0438\u044f) \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u041f\u0440\u0438\u0447\u0435\u043c \u043e\u043d\u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u0440\u0430\u0437\u044b \u0432\u044b\u0448\u0435, \u043e\u043d\u0430 \u0432\u044b\u0448\u0435 \u043d\u0430 \u043f\u043e\u0440\u044f\u0434\u043a\u0438!<\/li>\n<li>\u041d\u0443 \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u0438\u043d\u0443\u0441\u044b. \u041c\u0438\u043d\u0443\u0441 \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u2014 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0438 \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0435\u0449\u0435 \u0438 \u0441\u043b\u043e\u0436\u043d\u043e \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u0442\u044c.<\/li>\n<\/ol>\n<p>  \u0425\u043e\u0440\u043e\u0448\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438 \u043e\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0438 \u0431\u0435\u0437 \u0431\u0430\u0433\u043e\u0432. \u0410 \u0432\u043e\u0442 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a\u2026 \u0412 \u043e\u0431\u0449\u0435\u043c, \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u043e\u0433\u043e \u0434\u0435\u0431\u0430\u0433\u0433\u0438\u043d\u0433\u0430, \u043a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f \u0432 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445. \u0418 \u044d\u0442\u043e \u044f \u0435\u0449\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u041f\u0440\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u043c \u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0438 \u0441\u0445\u0435\u043c\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0441\u043e\u043a\u0435\u0442\u044b) \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u0440\u0430\u0441\u0442\u0435\u0442 \u043a\u0430\u043a \u043d\u0430 \u0434\u0440\u043e\u0436\u0436\u0430\u0445, \u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0433\u043e\u0432 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0441\u0442\u0438 \u0447\u0443\u0442\u044c \u043b\u0438 \u043d\u0435 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e.<\/p>\n<p>  \u0422\u0430\u043a \u0441\u0442\u043e\u0438\u0442 \u043b\u0438 \u0438\u0433\u0440\u0430 \u0441\u0432\u0435\u0447? \u0421\u0442\u043e\u0438\u0442 \u043b\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c\u044e? \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432\u044b\u0445\u043e\u0434 \u0435\u0441\u0442\u044c \u2014 coroutines \u0438\u043b\u0438 <abbr title=\"Wikipedia: \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043e\u0431\u043e\u0431\u0449\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a (\u0430 \u043d\u0435 \u043e\u0434\u043d\u0443 \u043a\u0430\u043a \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430) \u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f.\">\u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/abbr>.<\/p>\n<h3>\u0421\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/h3>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/18a\/ad4\/dda\/18aad4dda99815fc1ba476de911ccc73.jpg\" \/><\/div>\n<p><br clear=\"all\"\/>  \u0418\u0442\u0430\u043a, \u0447\u0435\u0433\u043e \u0436\u0435 \u043d\u0430\u043c \u0432\u0441\u0435\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f? <s>\u0421\u0447\u0430\u0441\u0442\u044c\u044f, \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u044f, \u0434\u0435\u043d\u0435\u0433 \u043c\u0435\u0448\u043e\u043a.<\/s> \u0410 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043b\u044e\u0441\u044b \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e, \u0442.\u0435. \u0447\u0442\u043e\u0431\u044b \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u044b\u043b\u0430 \u043a\u0430\u043a \u0443 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e, \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0430 \u043a\u0430\u043a \u0443 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e.<\/p>\n<p>  \u041d\u0430 \u0431\u0443\u043c\u0430\u0433\u0435 \u0437\u0432\u0443\u0447\u0438\u0442 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u044d\u0442\u043e? \u0414\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>  \u0412\u043e\u0442 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b? \u041d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u043c\u044b, \u0437\u043d\u0430\u0447\u0438\u0442, \u0432 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u043c\u0435\u0441\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u0442\u0443\u0442 \u0440\u0430\u0437, \u0438 \u043f\u043e\u0437\u0432\u0430\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443. \u0414\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430, \u0437\u0430\u0442\u0435\u043c \u0437\u043e\u0432\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430, \u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0442\u043e \u043c\u0435\u0441\u0442\u043e, \u043e\u0442\u043a\u0443\u0434\u0430 \u0431\u044b\u043b\u0430 \u043f\u043e\u0437\u0432\u0430\u043d\u0430. \u0410 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u2014 \u044d\u0442\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0440\u0443\u0433\u043e\u0435: \u043e\u043d\u0430 \u0442\u043e\u0436\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0442\u043e \u043c\u0435\u0441\u0442\u043e, \u043e\u0442\u043a\u0443\u0434\u0430 \u0431\u044b\u043b\u0430 \u043f\u043e\u0437\u0432\u0430\u043d\u0430, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u043d\u0430 <b>\u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f<\/b>, \u0430 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435. \u0422.\u0435. \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u044d\u0434\u0430\u043a\u0438\u0439 \u043f\u0438\u043d\u0433-\u043f\u043e\u043d\u0433: \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0431\u0440\u043e\u0441\u0430\u0435\u0442 \u043c\u044f\u0447\u0438\u043a, \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043b\u043e\u0432\u0438\u0442 \u0435\u0433\u043e, \u043f\u0435\u0440\u0435\u0431\u0435\u0433\u0430\u0435\u0442 \u0432 \u0434\u0440\u0443\u0433\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u0431\u0440\u043e\u0441\u0430\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0442\u043e\u0436\u0435 \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 (\u043f\u0435\u0440\u0435\u0431\u0435\u0433\u0430\u0435\u0442) \u0438 \u0441\u043d\u043e\u0432\u0430 \u0431\u0440\u043e\u0441\u0430\u0435\u0442 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u043c\u0435\u0441\u0442\u043e \u0443\u0436\u0435 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0418 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f. \u0412 \u0446\u0435\u043b\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u2014 \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>  \u041a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447? \u041d\u0443 \u0442\u0443\u0442 \u043d\u0430\u0432\u043e\u0434\u0438\u0442 \u043d\u0430 \u043c\u044b\u0441\u043b\u044c \u0442\u043e, \u0447\u0442\u043e \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u043d\u0435\u043a\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438 \u043a\u0440\u0430\u0439\u043d\u0435 \u0432\u0430\u0436\u043d\u043e. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0438 \u0431\u0443\u0434\u0443 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c: \u0435\u0441\u043b\u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e, \u0442\u043e \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u043e\u0432\u0443 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0438 \u0432\u044b\u0439\u0434\u0443 \u0438\u0437 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0410 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0439 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 \u043c\u0435\u0441\u0442\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0442\u043e\u0439 \u0441\u0430\u043c\u043e\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u0422.\u0435. \u0432\u0441\u044f \u0433\u0440\u044f\u0437\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u043f\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043b\u043e\u0436\u0438\u0442\u0441\u044f \u043d\u0430 \u043f\u043b\u0435\u0447\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c.<\/p>\n<p>  \u0418 \u0432\u043e\u0442 \u0442\u0443\u0442 \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u044f\u0437\u044b\u043a\u043e\u0432 \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043e\u0432 \u2014 \u0434\u0435\u043b\u0430 \u0434\u0430\u0432\u043d\u043e \u043c\u0438\u043d\u0443\u0432\u0448\u0438\u0445 \u0434\u043d\u0435\u0439. \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439: \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432, \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0442\u0435\u043a \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0440\u0435\u0434\u044b \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, <abbr title=\"Thread local storage\">TLS<\/abbr> \u0438 \u0434\u0440.). \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430, \u043d\u043e \u0435\u0449\u0435 \u0438 \u043e\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0417\u0432\u0443\u0447\u0438\u0442 \u043a\u0430\u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0433\u0432\u043e\u0437\u0434\u044c \u0432 \u043a\u0440\u044b\u0448\u043a\u0443 \u0433\u0440\u043e\u0431\u0430\u2026<\/p>\n<p>  \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0435\u0441\u0442\u044c <abbr title=\"Context switching library.\">boost.context<\/abbr>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0432\u0441\u0435, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b. \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432\u0441\u0435 \u043d\u0430 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0435, \u0432 \u043b\u0443\u0447\u0448\u0438\u0445 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u044f\u0445. \u041c\u043e\u0436\u043d\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <abbr title=\"Coroutine library.\">boost.coroutine<\/abbr>, \u043d\u043e \u0437\u0430\u0447\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u0435\u0441\u0442\u044c <abbr title=\"Context switching library.\">boost.context<\/abbr>? \u0411\u043e\u043b\u044c\u0448\u0435 \u0430\u0434\u0430 \u0438 \u0443\u0433\u0430\u0440\u0430!<\/p>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c<\/h4>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0439:<\/p>\n<pre><code class=\"cpp\">\/\/ \u0432\u044b\u0445\u043e\u0434 \u0438\u0437 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b void yield();  \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b bool isInsideCoro();  \/\/ \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 struct Coro {     \/\/ \u043d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043c\u0430\u043b\u043e \u043b\u0438     friend void yield();          Coro();          \/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430     Coro(Handler);          \/\/ \u0431\u0435\u0437 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432     ~Coro();          \/\/ \u0437\u0430\u043f\u0443\u0441\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430     void start(Handler);      \/\/ \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b (\u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0430\u0441\u044c yield)     void resume();          \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c     bool isStarted() const;  private:     ... }; <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043d\u0435\u0445\u0438\u0442\u0440\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441. \u041d\u0443 \u0438 \u0441\u0440\u0430\u0437\u0443 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">void coro() {     std::cout &lt;&lt; '2';     yield();     std::cout &lt;&lt; '4'; } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"cpp\">std::cout &lt;&lt; '1'; Coro c(coro); std::cout &lt;&lt; '3'; c.resume(); std::cout &lt;&lt; '5'; <\/code><\/pre>\n<p>  \u0414\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0434\u0430\u0442\u044c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d:<\/p>\n<blockquote>\n<pre> 12345 <\/pre>\n<\/blockquote>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043c\u0435\u0442\u043e\u0434\u0430 <code>start<\/code>:<\/p>\n<pre><code class=\"cpp\">void Coro::start(Handler handler) {     VERIFY(!isStarted(), &quot;Trying to start already started coro&quot;);     context = boost::context::make_fcontext(&stack.back(), stack.size(), &starterWrapper0);     jump0(reinterpret_cast&lt;intptr_t&gt;(&handler)); } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c <code>boost::context::make_fcontext<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 <code>starterWrapper0<\/code>:<\/p>\n<pre><code class=\"cpp\">TLS Coro* t_coro; void Coro::starterWrapper0(intptr_t p) {     t_coro-&gt;starter0(p); } <\/code><\/pre>\n<p>  \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 <code>starter0<\/code>, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044f \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>Coro<\/code> \u0438\u0437 <abbr title=\"Thread local storage\">TLS<\/abbr>. \u0412\u0441\u044f \u043c\u0430\u0433\u0438\u044f \u043f\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 <code>jump0<\/code>:<\/p>\n<pre><code class=\"cpp\">void Coro::jump0(intptr_t p) {     Coro* old = this;     std::swap(old, t_coro);     running = true;     boost::context::jump_fcontext(&savedContext, context, p);     running = false;     std::swap(old, t_coro);     if (exc != std::exception_ptr())         std::rethrow_exception(exc); } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u043e\u0435 <abbr title=\"Thread local storage\">TLS<\/abbr> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>t_coro<\/code> \u043d\u0430 \u043d\u043e\u0432\u043e\u0435 (\u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c\u0438), \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0432\u0441\u044f\u043a\u0438\u0435 \u0444\u043b\u0430\u0433\u0438 \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>boost::context::jump_fcontext<\/code>. \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0441\u0442\u0430\u0440\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<p>  \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>starter0<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a:<\/p>\n<pre><code class=\"cpp\">void Coro::starter0(intptr_t p) {     started = true;     try     {         Handler handler = std::move(*reinterpret_cast&lt;Handler*&gt;(p));         handler();     }     catch (...)     {         exc = std::current_exception();     }     started = false;     yield0(); } <\/code><\/pre>\n<p>  \u041e\u0442\u043c\u0435\u0447\u0443 \u043e\u0434\u0438\u043d \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442: \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b (\u0434\u043e \u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430), \u0442\u043e \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u043b\u0430\u0433\u043e\u043f\u043e\u043b\u0443\u0447\u043d\u043e \u0443\u043f\u0430\u0441\u0442\u044c. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e, \u0432\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u0440\u0443\u0448\u0435\u043d\u043e \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cpp\">\/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b void yield() {     VERIFY(isInsideCoro(), &quot;yield() outside coro&quot;);     t_coro-&gt;yield0(); }  \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u043e\u0433\u043e, \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u043b\u0438 \u043c\u044b \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b bool isInsideCoro() {     return t_coro != nullptr; }  \/\/ \u0432\u043e\u0437\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u043e\u0441\u043b\u0435 yield void Coro::resume() {     VERIFY(started, &quot;Cannot resume: not started&quot;);     VERIFY(!running, &quot;Cannot resume: in running state&quot;);     jump0(); }  \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 bool Coro::isStarted() const {     return started || running; }  \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0432 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 void Coro::yield0() {     boost::context::jump_fcontext(context, &savedContext, 0); } <\/code><\/pre>\n<p>  <\/p>\n<h3>Synca: async \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442<\/h3>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/c08\/c6a\/39a\/c08c6a39a51298efba0ab76b5fe4339a.jpg\" \/><\/div>\n<p><br clear=\"all\"\/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0448\u043b\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445. \u0422\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0435:  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/d36\/5b1\/c48\/d365b1c48d016e5ca4445e0e9f9a7cb1.png\" \/><\/div>\n<p><br clear=\"all\"\/>  \u0417\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>yield()<\/code>. \u041f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <code>resume()<\/code>.<\/p>\n<p>  \u0418 \u0432\u0441\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u0445\u043e\u0440\u043e\u0448\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u043d\u0435 \u043f\u0440\u0435\u0441\u043b\u043e\u0432\u0443\u0442\u0430\u044f \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c. \u041a\u0430\u043a \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442, \u043e\u043d\u0430 \u0432\u043d\u043e\u0441\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0442\u0443\u0440\u0431\u0443\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043e\u043b\u0436\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430:  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/c29\/d89\/176\/c29d891763e7a61c151597acaf8f11d1.png\" \/><\/div>\n<p><br clear=\"all\"\/>  \u0422.\u0435. \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0448\u0435\u0434\u0443\u043b\u0438\u043d\u0433\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u043e \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u042d\u0442\u043e, \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u043b\u043e \u0432 \u043d\u0430\u0448\u0438 \u043f\u043b\u0430\u043d\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c:  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/72b\/e36\/f04\/72be36f049acef168f4ba9eccd3df250.png\" \/><\/div>\n<p><br clear=\"all\"\/>  \u041e\u0442\u043b\u0438\u0447\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0448\u0435\u0434\u0443\u043b\u0438\u043d\u0433 \u043d\u0435 \u0432 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435, \u0430 \u0432\u043d\u0435 \u0435\u0435, \u0447\u0442\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u0447\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043f\u043e\u043b\u043d\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0442\u0443\u0441\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0442\u0443\u0434\u0430-\u0441\u044e\u0434\u0430, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0440\u0435\u043c\u0430\u0440\u043a\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\u0423\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u0432 <abbr title=\"Portable networking, including sockets, timers, hostname resolution and socket iostreams.\">boost.asio<\/abbr> \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>io_service::strand<\/code>, \u043d\u043e \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f. \u0412\u0435\u0434\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0441\u0432\u043e\u0435, \u0440\u043e\u0434\u043d\u043e\u0435\u2026 \u0414\u0430 \u0438 \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435.<\/div>\n<\/div>\n<p>  <\/p>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h4>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>go<\/code>:<\/p>\n<pre><code class=\"cpp\">void go(Handler handler) {     LOG(&quot;synca::go&quot;);     async::go([handler] {         coro::Coro* coro = new coro::Coro(std::move(handler));         onCoroComplete(coro);     }); } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0443\u0436\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0435. \u0418\u043d\u0442\u0435\u0440\u0435\u0441 \u0442\u0443\u0442 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>onCoroComplete<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043c\u043e\u0442\u0440\u0438\u0442, \u043d\u0435 \u043d\u0430\u0434\u043e \u043b\u0438 \u0447\u0435\u0433\u043e \u0437\u0430\u0448\u0435\u0434\u0443\u043b\u0438\u0442\u044c:<\/p>\n<pre><code class=\"cpp\">typedef std::function&lt;void(coro::Coro*)&gt; CoroHandler; TLS CoroHandler* t_deferHandler; void onCoroComplete(coro::Coro* coro) {     VERIFY(!coro::isInsideCoro(), &quot;Complete inside coro&quot;);     VERIFY(coro-&gt;isStarted() == (t_deferHandler != nullptr), &quot;Unexpected condition in defer\/started state&quot;);     if (t_deferHandler != nullptr)     {         LOG(&quot;invoking defer handler&quot;);         (*t_deferHandler)(coro);         t_deferHandler = nullptr;         LOG(&quot;completed defer handler&quot;);     }     else     {         LOG(&quot;nothing to do, deleting coro&quot;);         delete coro;     } } <\/code><\/pre>\n<p>  \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0435: \u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u2014 \u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c, \u043d\u0435\u0442 \u2014 \u0442\u043e\u0433\u0434\u0430 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430 \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0438 \u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c.<\/p>\n<p>  \u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441: \u0430 \u043a\u0430\u043a \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <code>t_deferHandler<\/code>? \u0410 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">TLS const Error* t_error;  void handleError() {     if (t_error)         throw boost::system::system_error(*t_error, &quot;synca&quot;); }  void defer(CoroHandler handler) {     VERIFY(coro::isInsideCoro(), &quot;defer() outside coro&quot;);     VERIFY(t_deferHandler == nullptr, &quot;There is unexecuted defer handler&quot;);     t_deferHandler = &handler;     coro::yield();     handleError(); } <\/code><\/pre>\n<p>  \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0417\u0434\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043a\u0438\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0448\u0435\u0434\u0443\u043b\u0438\u043d\u0433\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u0442.\u0435. \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0435\u0439. \u042d\u0442\u043e\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u043e \u0432\u044b\u0445\u043e\u0434\u0443 \u0438\u0437 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b (<code>coro::yield<\/code>), \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f <code>onCoroComplete<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043d\u0430\u0448 <i>\u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439<\/i> \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>defer<\/code> \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <code>Socket::accept<\/code>:<\/p>\n<pre><code class=\"cpp\">void onComplete(coro::Coro* coro, const Error& error) {     LOG(&quot;async completed, coro: &quot; &lt;&lt; coro &lt;&lt; &quot;, error: &quot; &lt;&lt; error.message());     VERIFY(coro != nullptr, &quot;Coro is null&quot;);     VERIFY(!coro::isInsideCoro(), &quot;Completion inside coro&quot;);     t_error = error ? &error : nullptr;     coro-&gt;resume();     LOG(&quot;after resume&quot;);     onCoroComplete(coro); }  async::IoHandler onCompleteHandler(coro::Coro* coro) {     return [coro](const Error& error) {         onComplete(coro, error);     }; }  void Acceptor::accept(Socket& socket) {     VERIFY(coro::isInsideCoro(), &quot;accept must be called inside coro&quot;);     defer([this, &socket](coro::Coro* coro) {         VERIFY(!coro::isInsideCoro(), &quot;accept completion must be called outside coro&quot;);         acceptor.accept(socket.socket, onCompleteHandler(coro));         LOG(&quot;accept scheduled&quot;);     }); } <\/code><\/pre>\n<p>  <code>onCompleteHandler<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u0412\u043d\u0443\u0442\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 <code>t_error<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0437\u0436\u0435 \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0430\u0448\u0435\u0439 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b (\u0441\u043c. \u0432\u044b\u0437\u043e\u0432 <code>handleError<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 <code>defer<\/code>), \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b <code>coro-&gt;resume()<\/code>, \u0442.\u0435. \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434 <code>defer<\/code> \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 <code>yield()<\/code>. \u0414\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0438\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439:  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/65e\/762\/4c4\/65e7624c4f0785557becf70836190df2.png\" \/><\/div>\n<p><br clear=\"all\"\/>  \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e:<\/p>\n<pre><code class=\"cpp\">void Socket::readSome(Buffer& buffer) {     VERIFY(coro::isInsideCoro(), &quot;readSome must be called inside coro&quot;);     defer([this, &buffer](coro::Coro* coro) {         VERIFY(!coro::isInsideCoro(), &quot;readSome completion must be called outside coro&quot;);         socket.readSome(buffer, onCompleteHandler(coro));         LOG(&quot;readSome scheduled&quot;);     }); }  void Socket::readUntil(Buffer& buffer, Buffer until) {     VERIFY(coro::isInsideCoro(), &quot;readUntil must be called inside coro&quot;);     defer([this, &buffer, until](coro::Coro* coro) {         VERIFY(!coro::isInsideCoro(), &quot;readUntil completion must be called outside coro&quot;);         socket.readUntil(buffer, std::move(until), onCompleteHandler(coro));         LOG(&quot;readUntil scheduled&quot;);     }); }  void Socket::write(const Buffer& buffer) {     VERIFY(coro::isInsideCoro(), &quot;write must be called inside coro&quot;);     defer([this, &buffer](coro::Coro* coro) {         VERIFY(!coro::isInsideCoro(), &quot;write completion must be called outside coro&quot;);         socket.write(buffer, onCompleteHandler(coro));         LOG(&quot;write scheduled&quot;);     }); } <\/code><\/pre>\n<p>  \u0412\u0435\u0437\u0434\u0435 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b <code>async::Socket<\/code> \u0438 <code>async::Acceptor<\/code>, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u0443\u043d\u043a\u0442\u0435 \u043f\u0440\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<h4>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/h4>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430. \u0422\u0443\u0442 \u0432\u0441\u0435 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u0438 \u0438\u0437\u044f\u0449\u043d\u0435\u0435:<\/p>\n<pre><code class=\"cpp\">Acceptor acceptor(8800); LOG(&quot;accepting&quot;); go([&acceptor] {     while (true)     {         Socket* toAccept = new Socket;         acceptor.accept(*toAccept);         LOG(&quot;accepted&quot;);         go([toAccept] {             try             {                 Socket socket = std::move(*toAccept);                 delete toAccept;                 Buffer buffer;                 while (true)                 {                     buffer.resize(4000);                     socket.readUntil(buffer, HTTP_DELIM_BODY);                     socket.write(httpContent(&quot;&lt;h1&gt;Hello synca!&lt;\/h1&gt;&quot;));                 }             }             catch (std::exception& e)             {                 LOG(&quot;error: &quot; &lt;&lt; e.what());             }         });     } }); dispatch(); <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0447\u0442\u043e-\u0442\u043e \u043d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442\u2026 \u0422\u043e\u0447\u043d\u043e! \u042d\u0442\u043e \u0436\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430\u0448 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434:  <\/p>\n<table>\n<tr>\n<th><code>sync<\/code><\/th>\n<th><code>synca<\/code><\/th>\n<\/tr>\n<tr>\n<td>\n<pre><code class=\"cpp\">Acceptor acceptor(8800); LOG(&quot;accepting&quot;);  while (true) {   Socket* toAccept = new Socket;   acceptor.accept(*toAccept);   LOG(&quot;accepted&quot;);   go([toAccept] {     try     {       Socket socket = std::move(*toAccept);       delete toAccept;       Buffer buffer;       while (true)       {         buffer.resize(4000);         socket.readUntil(buffer, HTTP_DELIM_BODY);         socket.write(httpContent(           &quot;&lt;h1&gt;Hello sync multithread!&lt;\/h1&gt;&quot;));       }     }     catch (std::exception& e)     {       LOG(&quot;error: &quot; &lt;&lt; e.what());     }   }); }   <\/code><\/pre>\n<\/td>\n<td>\n<pre><code class=\"cpp\">Acceptor acceptor(8800); LOG(&quot;accepting&quot;); go([&acceptor] {   while (true)   {     Socket* toAccept = new Socket;     acceptor.accept(*toAccept);     LOG(&quot;accepted&quot;);     go([toAccept] {       try       {         Socket socket = std::move(*toAccept);         delete toAccept;         Buffer buffer;         while (true)         {           buffer.resize(4000);           socket.readUntil(buffer, HTTP_DELIM_BODY);           socket.write(httpContent(             &quot;&lt;h1&gt;Hello synca!&lt;\/h1&gt;&quot;));         }       }       catch (std::exception& e)       {           LOG(&quot;error: &quot; &lt;&lt; e.what());       }     });   } }); dispatch(); <\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<p>\u0422\u0443\u0442 \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u0435: \u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u0435 \u0441\u043e\u043a\u0435\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0433\u043b\u0430\u0432\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u0430 \u043f\u043e\u0442\u043e\u043c\u0443 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 <code>dispatch<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0442\u044c\u0441\u044f \u0446\u0435\u043b\u044c\u044e, \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u044d\u0442\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u043c\u0438: \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u043a\u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u0435 \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>go<\/code>, \u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>dispatch<\/code> \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u044b \u0436\u0434\u0430\u043b\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432.<\/p>\n<p>  \u041d\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u043e\u0441\u0438\u0442 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440: \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u043a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0441\u0435\u0442\u0435\u0432\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u043d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442\u0430: \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0438\u043c\u0431\u0438\u043e\u0437 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432, \u0432\u0437\u044f\u0432 \u0438\u0437 \u043d\u0438\u0445 \u0441\u0430\u043c\u043e\u0435 \u043b\u0443\u0447\u0448\u0435\u0435, \u0442.\u0435. \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0443 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e.<\/p>\n<h4>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/e76\/aaf\/fae\/e76aaffaef4e682ce6f2ab5ea65e37ea.jpg\" \/><\/div>\n<p><br clear=\"all\"\/>  \u041e\u043f\u0438\u0448\u0443 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u0441\u043e\u043a\u0435\u0442\u043e\u0432. \u0427\u0430\u0441\u0442\u043e, \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0440\u0430\u0437\u0432\u0435\u0442\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f: \u0442\u043e\u0442, \u043a\u0442\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b, \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c, \u0430 \u043d\u043e\u0432\u044b\u0439 \u0441\u043e\u043a\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>goAccept<\/code>:<\/p>\n<pre><code class=\"cpp\">async::IoHandler onCompleteGoHandler(coro::Coro* coro, Handler handler) {     return [coro, handler](const Error& error) {         if (!error)             go(std::move(handler));         onComplete(coro, error);     }; }  struct Acceptor {     typedef std::function&lt;void(Socket&)&gt; Handler;     \/\/ ... };  void Acceptor::goAccept(Handler handler) {     VERIFY(coro::isInsideCoro(), &quot;goAccept must be called inside coro&quot;);     defer([this, handler](coro::Coro* coro) {         VERIFY(!coro::isInsideCoro(), &quot;goAccept completion must be called outside coro&quot;);         Socket* socket = new Socket;         acceptor.accept(socket-&gt;socket, onCompleteGoHandler(coro, [socket, handler] {             Socket s = std::move(*socket);             delete socket;             handler(s);         }));         LOG(&quot;accept scheduled&quot;);     }); } <\/code><\/pre>\n<p>  \u0418 \u0442\u043e\u0433\u0434\u0430 \u043d\u0430\u0448 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435:<\/p>\n<pre><code class=\"cpp\">Acceptor acceptor(8800); LOG(&quot;accepting&quot;); go([&acceptor] {     while (true)     {         acceptor.goAccept([](Socket& socket) {             try             {                 Buffer buffer;                 while (true)                 {                     buffer.resize(4000);                     socket.readUntil(buffer, HTTP_DELIM_BODY);                     socket.write(httpContent(&quot;&lt;h1&gt;Hello synca!&lt;\/h1&gt;&quot;));                 }             }             catch (std::exception& e)             {                 LOG(&quot;error: &quot; &lt;&lt; e.what());             }         });     } }); dispatch(); <\/code><\/pre>\n<p>  \u0427\u0442\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<h3>\u0412\u043e\u043f\u0440\u043e\u0441 1. \u0410 \u0447\u0442\u043e \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e?<\/h3>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/56f\/3e8\/2c1\/56f3e82c1426375a52319a6855b85529.jpg\" \/><\/div>\n<p><br clear=\"all\"\/>  \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0447\u0438\u0441\u0442\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\/\u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u0438 \u0441\u043c\u0435\u0436\u043d\u043e\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u043a\u0438.<\/p>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u0431\u044b\u043b\u043e \u0445\u043e\u0442\u0435\u043b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u043d\u043e \u043f\u043e\u0442\u043e\u043c \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c (!!!) \u043f\u043e\u0442\u043e\u043a\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0441\u043a\u043e\u0440\u0435\u0435 \u0433\u0438\u0433\u0430\u0431\u0438\u0442\u043d\u0430\u044f \u0441\u0435\u0442\u044c, \u043d\u0435\u0436\u0435\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u0440\u043e\u0432\u0435\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0442\u0435\u0441\u0442:  <\/p>\n<ol>\n<li>\u0421\u0435\u0440\u0432\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0434 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 30K RPS (\u0442.\u0435. 30 \u0442\u044b\u0449 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443).<\/li>\n<li>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 <code>async<\/code> \u0438 <code>synca<\/code>.<\/li>\n<\/ol>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435:  <\/p>\n<table>\n<tr>\n<th>\u041c\u0435\u0442\u043e\u0434<\/th>\n<th>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443<\/th>\n<th>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432<\/th>\n<th>\u0417\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u043e\u0433\u043e \u044f\u0434\u0440\u0430<\/th>\n<\/tr>\n<tr>\n<td>async<\/td>\n<td>30000<\/td>\n<td>1<\/td>\n<td>75\u00b15%<\/td>\n<\/tr>\n<tr>\n<td>synca<\/td>\n<td>30000<\/td>\n<td>1<\/td>\n<td>80\u00b15%<\/td>\n<\/tr>\n<\/table>\n<p>\u041e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u043a\u043e\u043b\u0435\u0431\u0430\u043d\u0438\u044f\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0445\u043e\u0434\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u044f. \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e \u0441 \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043a\u0430\u043d\u0430\u043b\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>  \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u043e\u0434\u043e\u0432 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 (\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u0441\u043e\u043a\u0435\u0442\u0430, \u0442.\u0435. \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043d\u0430 \u043d\u043e\u0432\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435) \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u043f\u0440\u0435\u043d\u0435\u0431\u0440\u0435\u0436\u0438\u043c\u043e \u043c\u0430\u043b\u044b. \u0410 \u0435\u0441\u043b\u0438 \u0435\u0449\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b \u0447\u0435\u0441\u0442\u043d\u043e \u043f\u0430\u0440\u0441\u0438\u043b HTTP \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0447\u0435\u0441\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0434\u0435\u043b\u0430\u043b \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0432\u0430\u0436\u043d\u043e\u0435 \u0438 \u043d\u0443\u0436\u043d\u043e\u0435, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u044f\u0432\u0438\u0442\u044c \u0441\u043c\u0435\u043b\u043e, \u0447\u0442\u043e <b>\u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u043e\u0431\u0449\u0435<\/b>.<\/p>\n<h3>\u0412\u043e\u043f\u0440\u043e\u0441 2. \u041d\u0443 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c. \u0410 \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0442\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0440\u0435\u0448\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438?<\/h3>\n<p>  <\/p>\n<h4>\u0422\u0435\u043e\u0440\u0435\u043c\u0430. \u041b\u044e\u0431\u0443\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c.<\/h4>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/c98\/f48\/fca\/c98f48fca9f4db9509980974baa0703c.jpg\" \/><\/div>\n<p><br clear=\"all\"\/>  <b>\u0414\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e.<\/b><br \/>  \u0412\u043d\u0430\u0447\u0430\u043b\u0435 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b. \u041b\u044e\u0431\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0442.\u043a. \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u043d\u044b\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0414\u0430\u043b\u0435\u0435 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0432 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435. \u0422\u0430\u043a\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u0438\u0434\u0435:<\/p>\n<pre><code class=\"cpp\">\/\/ \u043a\u043e\u0434 \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 async(..., handler); \/\/ \u043a\u043e\u0434 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 <\/code><\/pre>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u0434 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430:<\/p>\n<pre><code class=\"cpp\">\/\/ \u043a\u043e\u0434 \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 async(..., handler); <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443:<\/p>\n<pre><code class=\"cpp\">\/\/ \u043a\u043e\u0434 \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 synca(...); handler(); <\/code><\/pre>\n<p>  \u0422.\u0435. \u0432\u043d\u0443\u0442\u0440\u0438 <code>synca<\/code> \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>async<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043f\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0438 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a <code>handler()<\/code> \u044f\u0432\u043d\u043e. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u0449\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u0434 \u043f\u043e\u0441\u043b\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430. \u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d:<\/p>\n<pre><code class=\"cpp\">\/\/ \u043a\u043e\u0434 \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 go {     async(..., handler); } \/\/ \u043a\u043e\u0434 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u0434 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 <code>async<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 <code>go<\/code>, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:<\/p>\n<pre><code class=\"cpp\">\/\/ \u043a\u043e\u0434 \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 go {     synca(...);     handler(); } \/\/ \u043a\u043e\u0434 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 <\/code><\/pre>\n<p>  \u0422.\u0435. \u043d\u0430 \u043e\u0434\u0438\u043d \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0441\u0442\u0430\u043b\u043e \u043c\u0435\u043d\u044c\u0448\u0435. \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c\u0443 \u0432\u044b\u0437\u043e\u0432\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u043d\u0430 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445. <b>\u0427.\u0442.\u0434.<\/b><\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434\u044b<\/h3>\n<p>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0434\u043e\u043c\u043a\u0440\u0430\u0442\u043e\u043c \u0432\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0441\u043a\u0443\u044e \u0436\u0438\u0437\u043d\u044c. \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u043e\u0434\u0430, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0432 \u0434\u0440\u043e\u0436\u044c \u0434\u0430\u0436\u0435 \u0441\u0430\u043c\u044b\u0445 \u044f\u0440\u044b\u0445 \u0438 \u0437\u0430\u043a\u0430\u043b\u0435\u043d\u043d\u044b\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e, \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0441\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u043e \u0441\u0447\u0435\u0442\u043e\u0432 \u0441\u0442\u0430\u0440\u044b\u0439 \u0434\u043e\u0431\u0440\u044b\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434: \u0432 \u0443\u043c\u0435\u043b\u044b\u0445 \u0440\u0443\u043a\u0430\u0445 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u0435 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u043a\u0440\u043e\u0435\u0442 \u0432\u0441\u044e \u043c\u043e\u0449\u044c \u0438 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c!<\/p>\n<p>  \u0414\u043e \u043d\u043e\u0432\u044b\u0445 \u0432\u0441\u0442\u0440\u0435\u0447 \u0432 \u044d\u0444\u0438\u0440\u0435!<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/527\/0a4\/386\/5270a4386ae4ca3c3594e4f4db8476bf.jpg\" \/><\/div>\n<p><br clear=\"all\"\/>  P.S. \u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0437\u0434\u0435\u0441\u044c: <a href=\"https:\/\/bitbucket.org\/gridem\/synca\">bitbucket:gridem\/synca<\/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\/201826\/\"> http:\/\/habrahabr.ru\/post\/201826\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/397\/9e6\/382\/3979e63829a5f92aff5605016ff37596.jpg\" \/><\/div>\n<p><br clear=\"all\"\/>  \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c\u2026 \u0423\u0441\u043b\u044b\u0448\u0430\u0432 \u044d\u0442\u043e \u0441\u043b\u043e\u0432\u043e, \u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0431\u043b\u0435\u0441\u0442\u0435\u0442\u044c \u0433\u043b\u0430\u0437\u0430, \u0434\u044b\u0445\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u044b\u043c, \u0440\u0443\u043a\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0442\u0440\u044f\u0441\u0442\u0438\u0441\u044c, \u0433\u043e\u043b\u043e\u0441 \u2014 \u0437\u0430\u0438\u043a\u0430\u0442\u044c\u0441\u044f, \u043c\u043e\u0437\u0433 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0443\u0440\u043e\u0432\u043d\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438\u2026 \u0423 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u0432 \u043e\u043a\u0440\u0443\u0433\u043b\u044f\u044e\u0442\u0441\u044f \u0433\u043b\u0430\u0437\u0430, \u0437\u0432\u0443\u043a\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043d\u0435\u0447\u043b\u0435\u043d\u043e\u0440\u0430\u0437\u0434\u0435\u043b\u044c\u043d\u044b\u043c\u0438, \u0440\u0443\u043a\u0438 \u0441\u0436\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u0443\u043b\u0430\u043a\u0438, \u0430 \u0433\u043e\u043b\u043e\u0441 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u043e\u0431\u0435\u0440\u0442\u043e\u043d\u0430\u2026 \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435, \u0447\u0442\u043e \u0438\u0445 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u2014 \u044d\u0442\u043e \u0443\u0447\u0430\u0449\u0435\u043d\u043d\u044b\u0439 \u043f\u0443\u043b\u044c\u0441. \u0422\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b: \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u0440\u0432\u0443\u0442\u0441\u044f \u0432 \u0431\u043e\u0439, \u0430 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u044b \u043f\u044b\u0442\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u0445\u0440\u0443\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0440 \u0438 \u043e\u0441\u043e\u0437\u043d\u0430\u0442\u044c \u0440\u0438\u0441\u043a\u0438, \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0441\u0443\u0434\u043e\u0440\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0447\u0438\u043d\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0441\u0440\u043e\u043a\u043e\u0432 \u0432 \u0440\u0430\u0437\u044b\u2026 \u0418 \u0443\u0436\u0435 \u043f\u043e\u0442\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043e\u0441\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u0438 \u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u0432\u0441\u044e \u0433\u043e\u0440\u0435\u0447\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u043e\u0432\u043e\u0434\u044f \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u043d\u043e\u0447\u0438 \u0432 \u0434\u0435\u0431\u0430\u0433\u0433\u0435\u0440\u0435, \u043e\u0442\u0447\u0430\u044f\u043d\u043d\u043e \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0436\u0435 \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u2026<\/p>\n<p>  \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443 \u0440\u0438\u0441\u0443\u0435\u0442 \u043c\u043e\u0435 \u0432\u043e\u0441\u043f\u0430\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0441\u043b\u043e\u0432\u0435 \u201c\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c\u201d. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432\u0441\u0435 \u044d\u0442\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u044d\u043c\u043e\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u0438 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0430\u0432\u0434\u0430. \u0412\u0435\u0434\u044c \u0442\u0430\u043a?.. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043a\u0430\u0436\u0443\u0442, \u0447\u0442\u043e \u201c\u043f\u0440\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u043e\u201d. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u0438 \u0432\u0435\u0437\u0434\u0435 \u043f\u0440\u0438 \u0432\u0441\u044f\u043a\u043e\u043c \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0438 \u043d\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435. \u041d\u043e \u043b\u0443\u0447\u0448\u0435 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f, \u0431\u0430\u0433\u0438 \u043d\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f, \u0430 \u0431\u0435\u0441\u0441\u043e\u043d\u043d\u0438\u0446\u0430 \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442.<\/p>\n<p>  \u0422\u0430\u043a \u0447\u0442\u043e \u0436\u0435 \u0442\u0430\u043a\u043e\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c? \u041f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d\u0430 \u0442\u0430\u043a \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u0430? \u0410 \u0433\u043b\u0430\u0432\u043d\u043e\u0435: \u0447\u0442\u043e \u0441 \u043d\u0435\u0439 \u043d\u0435 \u0442\u0430\u043a?  <\/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-201826","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/201826","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=201826"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/201826\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=201826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=201826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=201826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}