From b8d07cc4608536119b3d99ee041d5820aad040ef Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 1 Mar 2016 12:34:56 +0000 Subject: [PATCH] Fixes for error handling in NetChannel - return the correct errno value instead of using -1 --- simgear/io/raw_socket.cxx | 9 +++++++++ simgear/io/raw_socket.hxx | 3 ++- simgear/io/sg_netChannel.cxx | 6 +++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/simgear/io/raw_socket.cxx b/simgear/io/raw_socket.cxx index c0c3ff22..1eae0c4c 100644 --- a/simgear/io/raw_socket.cxx +++ b/simgear/io/raw_socket.cxx @@ -684,6 +684,15 @@ bool Socket::isNonBlockingError () #endif } +int Socket::errorNumber() +{ +#if defined(WINSOCK) + return WSAGetLastError(); +#else + return errno; +#endif +} + ////////////////////////////////////////////////////////////////////// // diff --git a/simgear/io/raw_socket.hxx b/simgear/io/raw_socket.hxx index 833b75c3..698ca5eb 100644 --- a/simgear/io/raw_socket.hxx +++ b/simgear/io/raw_socket.hxx @@ -101,7 +101,8 @@ public: void setBroadcast ( bool broadcast ) ; static bool isNonBlockingError () ; - + static int errorNumber(); + static int select ( Socket** reads, Socket** writes, int timeout ) ; } ; diff --git a/simgear/io/sg_netChannel.cxx b/simgear/io/sg_netChannel.cxx index 303e4ba5..3fe0decf 100644 --- a/simgear/io/sg_netChannel.cxx +++ b/simgear/io/sg_netChannel.cxx @@ -114,7 +114,7 @@ NetChannel::send (const void * buffer, int size, int flags) write_blocked = true ; return 0; } else { - this->handleError (result); + this->handleError (errorNumber()); close(); return -1; } @@ -134,7 +134,7 @@ NetChannel::recv (void * buffer, int size, int flags) } else if (isNonBlockingError ()) { return 0; } else { - this->handleError (result); + this->handleError (errorNumber()); close(); return -1; } @@ -207,7 +207,7 @@ NetChannel::handleResolve() return 0; } else { // some other error condition - handleError (result); + handleError (errorNumber()); close(); return -1; } -- 2.39.5