MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / AcceptConnection

Method AcceptConnection

src/httpserver.cpp:773–803  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

771}
772
773std::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
805HTTPServer::Id HTTPServer::GetNewId()
806{

Callers

nothing calls this directly

Calls 5

any_ofClass · 0.85
NetworkErrorStringFunction · 0.85
SetSockAddrMethod · 0.80
getMethod · 0.45
AcceptMethod · 0.45

Tested by

no test coverage detected