mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-12 17:19:09 +00:00
Codefix: check for errors in the function getting the socket error
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user