-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: make bind() and listen() mockable/testable #24378
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
Conversation
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 ACK
I'm not too familiar on fuzzing and setting errno. May I ask what is the rationale for choosing the errno arrays in the fuzz tests? According to the linux manpages, there are some more possible errno vaues that bind
and listen
could set:
https://man7.org/linux/man-pages/man2/bind.2.html (EACCES, EADDRINUSE, EBADF, EINVAL, ENOTSOCK)
https://man7.org/linux/man-pages/man2/listen.2.html (EADDRINUSE, EBADF, ENOTSOCK, EOPNOTSUPP)
Note that there's a typo in the PR title: s/mockatble/mockable/
Not much, other than the first one must be a permanent error in order to avoid infinite loops in case the app code decides to retry on bitcoin/src/test/fuzz/util.cpp Lines 78 to 80 in c9ed992
I think it is good to have both temporary errors (e.g. Line 28 in c9ed992
Line 1677 in c9ed992
I added the comments and |
5249fc7
to
c2f80ba
Compare
|
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. |
ACK c2f80ba |
This will help to increase `Sock` usage and make more code mockable.
This will help to increase `Sock` usage and make more code mockable.
c2f80ba
to
b2733ab
Compare
|
ACK b2733ab |
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.
Approach ACK, light ACK
Should #include <sys/socket.h>
headers be added? (socklen_t
, etc.)
@@ -2409,7 +2408,7 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError, | |||
LogPrintf("Bound to %s\n", addrBind.ToString()); | |||
|
|||
// Listen for incoming connections | |||
if (listen(sock->Get(), SOMAXCONN) == SOCKET_ERROR) | |||
if (sock->Listen(SOMAXCONN) == SOCKET_ERROR) |
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.
if you retouch, maybe fix up the bracket here like you did above
You mean in |
Code review ACK b2733ab |
…able b2733ab net: add new method Sock::Listen() that wraps listen() (Vasil Dimov) 3ad7de2 net: add new method Sock::Bind() that wraps bind() (Vasil Dimov) Pull request description: _This is a piece of bitcoin#21878, chopped off to ease review._ Add new methods `Sock::Bind()` and `Sock::Listen()` that wrap `bind()` and `listen()`. This will help to increase `Sock` usage and make more code mockable. ACKs for top commit: pk-b2: ACK b2733ab laanwj: Code review ACK b2733ab Tree-SHA512: c6e737606703e2106fe60cc000cfbbae3a7f43deadb25f70531e2cac0457e0b0581440279d14c76c492eb85c12af4adde52c30baf74542c41597e419817488e8
This is a piece of #21878, chopped off to ease review.
Add new methods
Sock::Bind()
andSock::Listen()
that wrapbind()
andlisten()
.This will help to increase
Sock
usage and make more code mockable.