-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Use Sock in CNode #23604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Sock in CNode #23604
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept and light code-review ACK ba8cc5b4e5c38e163d01b38f8a73da7c10ce0999
The first commit seems unrelated to the other two, I guess this will be useful in a later chopped off PR?
ba8cc5b to
846e995
Compare
|
Invalidates (light) ACK from @theStack
Oh, good catch! The idea is to use |
|
Previously invalidated (light) ACK from @theStack |
theStack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Light re-ACK 78cda19bb859be69a8bdb006c210b8d47d56acc9
(as per git range-diff ba8cc5b4...78cda19b)
|
Invalidates (light) ACK from @theStack |
|
Concept ACK. CI failures are unrelated. |
jonatack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 0ec56c651ee87d10e7c9b730dcdfffe26b95d88c
|
ACK d22a47754208f18d5bd674c28458bb82bbd1b9b9 |
theStack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Light re-ACK 1477f3aa73c4bec6e04682be63071592a032d506
(as per git range-diff 78cda19b...1477f3aa)
stratospher
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 1477f3a.
w0xlt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK 1477f3a
Great explanation of why use shared_ptr instead of std::unique_ptr for m_sock
This way it can be used in `ConsumeNode()`.
|
Invalidates ACKs from @jonatack, @theStack, @stratospher, @w0xlt |
jonatack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK af7fc2864e6fb9323fbefc9a9080ba23057143a9 🧦
src/net.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a silly question: LOCK(node.m_sock_mutex); applies even to node.m_sock->Send(...) operation but then here one can return contained sockets out of the function.
I understand that m_sock_mutex guards only m_sock member read & write operations but not necessarily the contained socket. Is that correct or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good question.
Before this PR the mutex protects the value of the socket variable - that is, to make sure it does not change from e.g. 7 (it is a file descriptor) to INVALID_SOCKET in the middle of constructs like:
if (socket != INVALID_SOCKET) {
... do something with the socket, assuming it is valid ...
}After this PR, it is the same with the exception that the variable is not a bare integer anymore, but a shared_ptr and an empty such pointer is used to designate what was designated before by INVALID_SOCKET.
PastaPastaPasta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one request
Change `CNode` to use a pointer to `Sock` instead of a bare `SOCKET`. This will help mocking / testing / fuzzing more code.
-BEGIN VERIFY SCRIPT- sed -i -e 's/cs_hSocket/m_sock_mutex/g' $(git grep -l cs_hSocket) -END VERIFY SCRIPT-
|
Invalidates ACK from @jonatack Previously invalidated ACKs from @theStack, @stratospher, @w0xlt |
|
re-ACK ef5014d changes since last review are the removal of an unneeded dtor and the addition of a style commit |
w0xlt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reACK ef5014d
| m_serializer = std::make_unique<V1TransportSerializer>(V1TransportSerializer()); | ||
| } | ||
|
|
||
| CNode::~CNode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies if this is a silly question but just wanted to clarify - removing this destructor, it's implicit that the shared_ptr for Sock will be reset and the Sock's destructor will responsible for closing the socket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://en.cppreference.com/w/cpp/language/destructor "Implicitly-declared destructor".
The default destructor for CNode will call all the destructors of all of it's members. The destructor for shared_ptr will reduce the reference counter, and then if that reference counter is zero, the destructor for Sock will be called. If the RC is not zero, then the Sock will continue to exist on the heap (presumably being used by another thread), until the owner of that shared_ptr calls the destructor.
PastaPastaPasta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK ef5014d, I have reviewed the code, and believe it makes sense to merge
theStack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since my last ACK was only "light" and happened weeks ago, so I decided to do a full review of this PR again instead of looking at the range-diff. Changes LGTM!
Cod-review ACK ef5014d
This is a piece of #21878, chopped off to ease review.
Change
CNodeto use a pointer toSockinstead of a bareSOCKET.This will help mocking / testing / fuzzing more code.