-
-
Notifications
You must be signed in to change notification settings - Fork 971
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
Codechange: encapsulate network error handling (and fix #9142) #9146
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.
I think this is fine; I only wonder if we shouldn't just put this in the header-file, so we can let compilers optimize it away immediately. Otherwise I guess it needs some LTO to do it properly. No clue if it matters either way.
Also, I would like a second opinion on the C++ side of this, but yeah .. I think this is the better solution to go with, as we don't force every OS into a Linux-like experience :D
d49abc7
to
e30e5a7
Compare
e30e5a7
to
c2989c2
Compare
I realise my previous comments somewhat contradict this, but given (almost?) every use of NetworkError::AsString/GetLastAsString is in DEBUG() that need a const char*... maybe that would be a better return type? :> Would save the very noisy c_str() call every time... |
8ccbd97
to
145d128
Compare
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.
Code is fine by me
Closes #9142.
Motivation / Problem
The discussion about #9142 and how to solve that nicely (and permanently) yielded another rabbit hole.
This does solve #9142, but it should also prevent it from happening again as doing it another way would break the compile for at least Windows.
Description
Create a NetworkError class that has functions to query what kind of error it is. This way the actual definition of what a particular error entails needs to be coded only once. #9142 is a nice example of why the current method is not sustainable; if someone else adds a new place where recv/send is used, and would just use
err == EWOULDBLOCK
then #9142 happens again. By abstracting the whole error type determination to a single location, it needs to be set only once and can then be reused.To not have huge amounts of complicated #ifdefs in os_abstraction.h, the actual implementation has been placed in os_abstraction.cpp and some of the functions defined in os_abstraction.h have been moved as well.
By this refactor the #ifdefs for the functionality are also moved into the functions themselves, so for one function you can easily see the implementation for the different environments, whereas you had to really look well through os_abstraction.h before to find out what would happen exactly in different environments.
Limitations
None, as far as I know.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.