BNetEndpoint: Fix socket leak and reduce Accept() overhead.

When using the copy constructor of BNetEndpoint the socket of the
original endpoint gets dup'ed. The Accept() method later directly reset
the fSocket member of the newly created BNetEndpoint to the socket
returned by accept(). The socket dup'ed by the copy constructor was
therefore leaked.

Of course dup'ing the socket and copying the local and remote addresses
is superfluous in the accept case, as these members all get set to new
values. To reduce that overhead there is now a new private constructor
that directly gets the final socket and remote and local address.
This commit is contained in:
Michael Lotz
2013-11-24 22:36:29 +01:00
parent 5c38483e0c
commit dcc56bf748
2 changed files with 35 additions and 14 deletions
+4
View File
@@ -78,6 +78,10 @@ class BNetEndpoint : public BArchivable {
const BNetAddress& RemoteAddr();
private:
BNetEndpoint(const BNetEndpoint& other, int socket,
const struct sockaddr_in& localAddress,
const struct sockaddr_in& peerAddress);
status_t _SetupSocket();
virtual void _ReservedBNetEndpointFBCCruft1();