Commit bfee4359 authored by jan.koester's avatar jan.koester
Browse files

fixed accept

parent 65fc51fa
Loading
Loading
Loading
Loading
+6 −0
Changes for src/posix/tcp.cpp: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -291,6 +291,12 @@ void tcp::accept(std::unique_ptr<socket>& csock, bool nonblock) {
    }
#endif

    // Callers may pass an empty unique_ptr (they only want the accepted
    // socket); fill it with a plain tcp then. An existing object (ssl,
    // the event loop's preallocated connection socket) just takes the fd.
    if (!csock)
        csock = std::make_unique<tcp>(cfd);
    else
        *csock = cfd;
    csock->_Addr = peer;
    csock->_AddrLen = peerLen;
+11 −6
Changes for src/windows/tcp.cpp: 11 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -145,6 +145,12 @@ void tcp::accept(std::unique_ptr<socket>& csock, bool nonblock) {
        throw e;
    }

    // Callers may pass an empty unique_ptr (they only want the accepted
    // socket); fill it with a plain tcp then. An existing object (ssl,
    // the event loop's preallocated connection socket) just takes the fd.
    if (!csock)
        csock = std::make_unique<tcp>(cfd);
    else
        *csock = cfd;
    csock->_Addr = peer;
    csock->_AddrLen = peerLen;
@@ -485,12 +491,11 @@ void tcp::accept(LPFN_ACCEPTEX lpfnAcceptEx, std::unique_ptr<socket>& csock) {
        }
    }

    // Store the accept socket for later retrieval
    // Note: *csock was already a valid object (managed by caller), but its _Socket needed to be set?
    // Wait, the caller passes csock which contains a new tcp object but _Socket is probably INVALID.
    // The acceptSock we created is the handle.
    // The previous implementation did: *csock = acceptSock;
    // But csock is unique_ptr<socket>. operator=(SOCKET) is virtual.
    // Hand the accept socket to the caller's object, or a new tcp if the
    // caller passed an empty unique_ptr.
    if (!csock)
        csock = std::make_unique<tcp>(acceptSock);
    else
        *csock = acceptSock;
}