1
0
Fork 0

Codefix: check for errors in the function getting the socket error

pull/13799/head
Rubidium 2025-03-11 23:33:32 +01:00 committed by rubidium42
parent 486ad7d416
commit 0fde979b21
2 changed files with 4 additions and 3 deletions

View File

@ -27,8 +27,9 @@
/**
* Construct the network error with the given error code.
* @param error The error code.
* @param message The error message. Leave empty to determine this automatically based on the error number.
*/
NetworkError::NetworkError(int error) : error(error)
NetworkError::NetworkError(int error, const std::string &message) : error(error), message(message)
{
}
@ -185,7 +186,7 @@ NetworkError GetSocketError(SOCKET d)
{
int err;
socklen_t len = sizeof(err);
getsockopt(d, SOL_SOCKET, SO_ERROR, (char *)&err, &len);
if (getsockopt(d, SOL_SOCKET, SO_ERROR, (char *)&err, &len) != 0) return NetworkError(-1, "Could not get error for socket");
return NetworkError(err);
}

View File

@ -23,7 +23,7 @@ private:
int error; ///< The underlying error number from errno or WSAGetLastError.
mutable std::string message; ///< The string representation of the error (set on first call to #AsString).
public:
NetworkError(int error);
NetworkError(int error, const std::string &message = {});
bool HasError() const;
bool WouldBlock() const;