-
Notifications
You must be signed in to change notification settings - Fork 3
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
Set Neon to return meaningful socket errors on Windows during socket.recv() calls. #445
Conversation
src/socketx.h
Outdated
@@ -3,6 +3,7 @@ | |||
#include <winsock.h> | |||
typedef int socklen_t; | |||
#pragma warning(disable: 4127) // incompatible with FD_SET() | |||
#define socketerror WSAGetLastError() |
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.
Use #define socketerror()
so the use of this doesn't look like a variable.
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.
Fixed.
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.
This has not been fixed.
src/socketx.h
Outdated
@@ -15,5 +16,6 @@ typedef int socklen_t; | |||
typedef int SOCKET; | |||
const int INVALID_SOCKET = -1; | |||
inline void closesocket(int x) { close(x); } | |||
#define socketerror errno |
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.
Use #define socketerror()
so the use of this doesn't look like a variable.
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.
Fixed.
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.
Also this has not been fixed.
lib/net.cpp
Outdated
sizeof(msgbuf), | ||
NULL); | ||
#else | ||
snprintf(msgbuf, sizeof(msgbuf), "%s", strerror(err)); |
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.
To avoid an unnecessary copy, this case can be simply return strerror(err)
. You should be aware of default constructors and how it is unnecessary to explicitly call std::string(...)
for character buffers.
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.
Fixed.
lib/net.cpp
Outdated
{ | ||
static char msgbuf[256] = { '\0' }; | ||
#ifdef _WIN32 | ||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
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.
The return value of FormatMessage is not checked here, and it should be.
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.
Fixed.
lib/net.cpp
Outdated
#else | ||
snprintf(msgbuf, sizeof(msgbuf), "%s", strerror(err)); | ||
#endif | ||
if (msgbuf[0] == '\0') { |
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.
This seems like a redundant test, as I can see no case where the error message function succeeds but still returns an empty message. Instead, check for success of FormatMessage. (Note that strerror() has no error return value and is documented to always return a valid string.)
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.
Removed unnecessary check, and simplified the logic.
e8ffd2e
to
aa8e389
Compare
src/socketx.h
Outdated
@@ -3,6 +3,7 @@ | |||
#include <winsock.h> | |||
typedef int socklen_t; | |||
#pragma warning(disable: 4127) // incompatible with FD_SET() | |||
#define socketerror WSAGetLastError() |
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.
This has not been fixed.
src/socketx.h
Outdated
@@ -15,5 +16,6 @@ typedef int socklen_t; | |||
typedef int SOCKET; | |||
const int INVALID_SOCKET = -1; | |||
inline void closesocket(int x) { close(x); } | |||
#define socketerror errno |
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.
Also this has not been fixed.
5fa1f81
to
d03a469
Compare
lib/net.cpp
Outdated
@@ -15,6 +15,25 @@ | |||
|
|||
// https://wiki.openssl.org/index.php/SSL/TLS_Client | |||
|
|||
static std::string socket_error(int err) |
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.
You seem to have something named socketerror
and something else named socket_error
. Please find names that are more different.
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 changed this to error_to_string()
, and the macro to GetSocketError()
.
d03a469
to
62a2eb9
Compare
lib/net.cpp
Outdated
static std::string error_to_string(int err) | ||
{ | ||
#ifdef _WIN32 | ||
static char msgbuf[256] = { '\0' }; |
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.
Why is this declared static? It doesn't need to be static.
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.
Removed static.
src/socketx.h
Outdated
@@ -15,5 +16,6 @@ typedef int socklen_t; | |||
typedef int SOCKET; | |||
const int INVALID_SOCKET = -1; | |||
inline void closesocket(int x) { close(x); } | |||
#define GetSocketError() errno |
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.
This naming convention is inconsistent. Nothing else in the socket library uses CamelCase. Choose something consistent.
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.
Changed name to socket_error()
lib/net.cpp
Outdated
@@ -15,6 +15,25 @@ | |||
|
|||
// https://wiki.openssl.org/index.php/SSL/TLS_Client | |||
|
|||
static std::string error_to_string(int err) |
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.
This name is too generic - what kind of error? This is specifically related to sockets, so socket should be mentioned in the name somewhere.
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.
Changed name to socket_error_message()
62a2eb9
to
51e45db
Compare
Fix net.neon to return meaningful errors on recv()