Skip to content

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Jun 20, 2022

This is a piece of #21878, chopped off to ease review.

  • Sock::Release() is unused, thus remove it
  • CloseSocket() is only called from Sock::Reset(), so move the body of CloseSocket() inside Sock::Reset() and remove CloseSocket() - this helps to hide low level file descriptor sockets inside the Sock class.
  • Rename Sock::Reset() to Sock::Close() and make it private - to be used only in the destructor and in the Sock assignment operator. This simplifies the public API by removing one method from it.

vasild added 2 commits June 20, 2022 15:01
Do the closing in `Sock::Reset()` and remove the standalone
`CloseSocket()`.

This reduces the exposure of low-level sockets (i.e. integer file
descriptors) outside of the `Sock` class.
@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 20, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #21878 (Make all networking code mockable by vasild)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@vasild
Copy link
Contributor Author

vasild commented Jun 21, 2022

e8ff3f0c52..e0537dada6: remove Sock::Reset()

@vasild vasild changed the title Remove Sock::Release() and CloseSocket() Remove Sock::Release(), Sock::Reset() and CloseSocket() Jun 21, 2022
@laanwj
Copy link
Member

laanwj commented Jun 21, 2022

Concept ACK! Nice cleanup now!

Outside of `Sock`, `Sock::Reset()` was used in just one place (in
`i2p.cpp`) which can use the assignment operator instead.

This simplifies the public `Sock` API by having one method less.
@vasild vasild force-pushed the remove_Sock_Release_and_CloseSocket branch from e0537da to a724c39 Compare June 22, 2022 07:28
@vasild
Copy link
Contributor Author

vasild commented Jun 22, 2022

e0537dada6...a724c39606: make Close() private and call it from both the destructor and the assignment operator.

@vasild vasild changed the title Remove Sock::Release(), Sock::Reset() and CloseSocket() Remove Sock::Release() and CloseSocket() Jun 22, 2022
@laanwj
Copy link
Member

laanwj commented Jun 22, 2022

Code review ACK a724c39

@laanwj laanwj merged commit a085a55 into bitcoin:master Jun 22, 2022
@vasild vasild deleted the remove_Sock_Release_and_CloseSocket branch June 22, 2022 11:50
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 22, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants