| 771 | } |
| 772 | |
| 773 | std::unique_ptr<Sock> HTTPServer::AcceptConnection(const Sock& listen_sock, CService& addr) |
| 774 | { |
| 775 | // Make sure we only operate on our own listening sockets |
| 776 | Assume(std::ranges::any_of(m_listen, [&](const auto& sock) { return sock.get() == &listen_sock; })); |
| 777 | |
| 778 | sockaddr_storage storage; |
| 779 | socklen_t len{sizeof(storage)}; |
| 780 | auto sa = reinterpret_cast<sockaddr*>(&storage); |
| 781 | |
| 782 | auto sock{listen_sock.Accept(sa, &len)}; |
| 783 | |
| 784 | if (!sock) { |
| 785 | const int err{WSAGetLastError()}; |
| 786 | if (err != WSAEWOULDBLOCK) { |
| 787 | LogDebug(BCLog::HTTP, |
| 788 | "Cannot accept new connection: %s", |
| 789 | NetworkErrorString(err)); |
| 790 | } |
| 791 | return {}; |
| 792 | } |
| 793 | |
| 794 | // The OS handed us a valid socket but we can't determine its source address. |
| 795 | // In the unlikely event this occurs, the invalid address will be rejected |
| 796 | // by the downstream ClientAllowed() check. |
| 797 | if (!addr.SetSockAddr(sa, len)) { |
| 798 | LogDebug(BCLog::HTTP, |
| 799 | "Unknown socket family"); |
| 800 | } |
| 801 | |
| 802 | return sock; |
| 803 | } |
| 804 | |
| 805 | HTTPServer::Id HTTPServer::GetNewId() |
| 806 | { |
nothing calls this directly
no test coverage detected