@@ -593,7 +593,7 @@ struct TemplatedApp {
593593 }
594594
595595 /* Register event handler for accepted FD. Can be used together with adoptSocket. */
596- TemplatedApp &&preOpen(LIBUS_SOCKET_DESCRIPTOR (*handler)(struct us_socket_context_t *, LIBUS_SOCKET_DESCRIPTOR)) {
596+ TemplatedApp &&preOpen(LIBUS_SOCKET_DESCRIPTOR (*handler)(struct us_socket_context_t *, LIBUS_SOCKET_DESCRIPTOR, char *, int )) {
597597 httpContext->onPreOpen (handler);
598598 return std::move (static_cast <TemplatedApp &&>(*this ));
599599 }
@@ -614,7 +614,7 @@ struct TemplatedApp {
614614 /* Add this app to httpContextData list over child apps and set onPreOpen */
615615 httpContext->getSocketContextData ()->childApps .push_back ((void *) app);
616616
617- httpContext->onPreOpen ([](struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR fd) -> LIBUS_SOCKET_DESCRIPTOR {
617+ httpContext->onPreOpen ([](struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR fd, char *ip, int ip_length ) -> LIBUS_SOCKET_DESCRIPTOR {
618618
619619 HttpContext<SSL> *httpContext = (HttpContext<SSL> *) context;
620620
@@ -634,9 +634,9 @@ struct TemplatedApp {
634634 // std::cout << "Loop is " << receivingApp->getLoop() << std::endl;
635635
636636
637- receivingApp->getLoop ()->defer ([fd, receivingApp]() {
637+ receivingApp->getLoop ()->defer ([fd, ipStore = std::string (ip, ip + ip_length), receivingApp]() {
638638 // std::cout << "About to adopt socket " << fd << " on receivingApp " << receivingApp << std::endl;
639- receivingApp->adoptSocket (fd);
639+ receivingApp->adoptSocket (fd, std::string_view (ipStore) );
640640 // std::cout << "Done " << std::endl;
641641 });
642642
@@ -650,8 +650,8 @@ struct TemplatedApp {
650650 }
651651
652652 /* adopt an externally accepted socket */
653- TemplatedApp &&adoptSocket(LIBUS_SOCKET_DESCRIPTOR accepted_fd) {
654- httpContext->adoptAcceptedSocket (accepted_fd);
653+ TemplatedApp &&adoptSocket(LIBUS_SOCKET_DESCRIPTOR accepted_fd, std::string_view ip = std::string_view() ) {
654+ httpContext->adoptAcceptedSocket (accepted_fd, ( char *) ip. data (), ( int ) ip. length () );
655655 return std::move (static_cast <TemplatedApp &&>(*this ));
656656 }
657657
0 commit comments