mirror of https://github.com/OpenTTD/OpenTTD
Codefix: check for errors in the function getting the socket error
parent
486ad7d416
commit
0fde979b21
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue