File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -576,6 +576,29 @@ struct TemplatedApp {
576
576
return std::move (static_cast <BuilderPatternReturnType &&>(*this ));
577
577
}
578
578
579
+ BuilderPatternReturnType &&addChildApp(BuilderPatternReturnType *app) {
580
+ /* Add this app to httpContextData list over child apps and set onPreOpen */
581
+ httpContext->getSocketContextData ()->childApps .push_back ((void *) app);
582
+
583
+ httpContext->onPreOpen ([](struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR fd) -> LIBUS_SOCKET_DESCRIPTOR {
584
+ HttpContext<SSL> *httpContext = (HttpContext<SSL> *) context;
585
+
586
+ int &roundRobin = &httpContext->getSocketContextData ()->roundRobin ;
587
+ BuilderPatternReturnType *receivingApp = (BuilderPatternReturnType *) httpContext->getSocketContextData ()->childApps [roundRobin];
588
+
589
+ receivingApp->getLoop ()->defer ([fd, receivingApp]() {
590
+ receivingApp->adoptSocket (fd);
591
+ });
592
+
593
+ if (++roundRobin == httpContext->getSocketContextData ()->childApps .size ()) {
594
+ roundRobin = 0 ;
595
+ }
596
+
597
+ return fd + 1 ;
598
+ });
599
+ return std::move (static_cast <BuilderPatternReturnType &&>(*this ));
600
+ }
601
+
579
602
/* adopt an externally accepted socket */
580
603
BuilderPatternReturnType &&adoptSocket(LIBUS_SOCKET_DESCRIPTOR accepted_fd) {
581
604
httpContext->adoptAcceptedSocket (accepted_fd);
Original file line number Diff line number Diff line change @@ -49,6 +49,10 @@ struct alignas(16) HttpContextData {
49
49
HttpRouter<RouterData> router;
50
50
void *upgradedWebSocket = nullptr ;
51
51
bool isParsingHttp = false ;
52
+
53
+ /* If we are main acceptor, distribute to these apps */
54
+ std::vector<void *> childApps;
55
+ unsigned int roundRobin = 0 ;
52
56
};
53
57
54
58
}
You can’t perform that action at this time.
0 commit comments