Fixes for error handling in NetChannel

- return the correct errno value instead of using -1
This commit is contained in:
James Turner
2016-03-01 12:34:56 +00:00
parent 43dacf5951
commit b8d07cc460
3 changed files with 14 additions and 4 deletions
+9
View File
@@ -684,6 +684,15 @@ bool Socket::isNonBlockingError ()
#endif #endif
} }
int Socket::errorNumber()
{
#if defined(WINSOCK)
return WSAGetLastError();
#else
return errno;
#endif
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// //
+1
View File
@@ -101,6 +101,7 @@ public:
void setBroadcast ( bool broadcast ) ; void setBroadcast ( bool broadcast ) ;
static bool isNonBlockingError () ; static bool isNonBlockingError () ;
static int errorNumber();
static int select ( Socket** reads, Socket** writes, int timeout ) ; static int select ( Socket** reads, Socket** writes, int timeout ) ;
} ; } ;
+3 -3
View File
@@ -114,7 +114,7 @@ NetChannel::send (const void * buffer, int size, int flags)
write_blocked = true ; write_blocked = true ;
return 0; return 0;
} else { } else {
this->handleError (result); this->handleError (errorNumber());
close(); close();
return -1; return -1;
} }
@@ -134,7 +134,7 @@ NetChannel::recv (void * buffer, int size, int flags)
} else if (isNonBlockingError ()) { } else if (isNonBlockingError ()) {
return 0; return 0;
} else { } else {
this->handleError (result); this->handleError (errorNumber());
close(); close();
return -1; return -1;
} }
@@ -207,7 +207,7 @@ NetChannel::handleResolve()
return 0; return 0;
} else { } else {
// some other error condition // some other error condition
handleError (result); handleError (errorNumber());
close(); close();
return -1; return -1;
} }