diff --git a/src/network/core/os_abstraction.cpp b/src/network/core/os_abstraction.cpp index 41d5471b72..238f368f6e 100644 --- a/src/network/core/os_abstraction.cpp +++ b/src/network/core/os_abstraction.cpp @@ -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); } diff --git a/src/network/core/os_abstraction.h b/src/network/core/os_abstraction.h index cc35c01436..86c37db105 100644 --- a/src/network/core/os_abstraction.h +++ b/src/network/core/os_abstraction.h @@ -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;