Skip to content

Commit 9cca5d6

Browse files
committed
Needed changes for addChildApp
1 parent 1e134ac commit 9cca5d6

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/App.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,17 +581,33 @@ struct TemplatedApp {
581581
httpContext->getSocketContextData()->childApps.push_back((void *) app);
582582

583583
httpContext->onPreOpen([](struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR fd) -> LIBUS_SOCKET_DESCRIPTOR {
584+
584585
HttpContext<SSL> *httpContext = (HttpContext<SSL> *) context;
585586

586-
int &roundRobin = &httpContext->getSocketContextData()->roundRobin;
587-
BuilderPatternReturnType *receivingApp = (BuilderPatternReturnType *) httpContext->getSocketContextData()->childApps[roundRobin];
587+
if (httpContext->getSocketContextData()->childApps.empty()) {
588+
return fd;
589+
}
590+
591+
//std::cout << "Distributing fd: " << fd << " from context: " << context << std::endl;
592+
593+
unsigned int *roundRobin = &httpContext->getSocketContextData()->roundRobin;
594+
595+
//std::cout << "Round robin is: " << *roundRobin << " and size of apps is: " << httpContext->getSocketContextData()->childApps.size() << std::endl;
596+
597+
BuilderPatternReturnType *receivingApp = (BuilderPatternReturnType *) httpContext->getSocketContextData()->childApps[*roundRobin];
598+
599+
600+
//std::cout << "Loop is " << receivingApp->getLoop() << std::endl;
601+
588602

589603
receivingApp->getLoop()->defer([fd, receivingApp]() {
604+
//std::cout << "About to adopt socket " << fd << " on receivingApp " << receivingApp << std::endl;
590605
receivingApp->adoptSocket(fd);
606+
//std::cout << "Done " << std::endl;
591607
});
592608

593-
if (++roundRobin == httpContext->getSocketContextData()->childApps.size()) {
594-
roundRobin = 0;
609+
if (++(*roundRobin) == httpContext->getSocketContextData()->childApps.size()) {
610+
*roundRobin = 0;
595611
}
596612

597613
return fd + 1;

0 commit comments

Comments
 (0)