diff --git a/src/src/SocketFunctions.cpp b/src/src/SocketFunctions.cpp index 12be3df..1acba2b 100644 --- a/src/src/SocketFunctions.cpp +++ b/src/src/SocketFunctions.cpp @@ -15,11 +15,13 @@ #include #endif +#include + namespace MinimalSocket { namespace { #ifdef _WIN32 #define REBIND_OPTION SO_REUSEADDR -#else +#elif defined(__unix__) || defined(__APPLE__) #define REBIND_OPTION SO_REUSEPORT #endif } // namespace @@ -148,31 +150,40 @@ void turnToNonBlocking(SocketID socket_id) { #elif defined(__unix__) || defined(__APPLE__) // https://jameshfisher.com/2017/04/05/set_socket_nonblocking/ int flags = ::fcntl(socket_id, F_GETFL); + std::cout << "=====> 0" << std::endl; if (::fcntl(socket_id, F_SETFL, flags | O_NONBLOCK) == -1) { + std::cout << "=====> 1" << std::endl; throw Error{"Unable to set up the non blocking mode"}; } #endif + std::cout << "=====> 2" << std::endl; } int isTimeoutErrorCode(int code) { return #ifdef _WIN32 code == WSAETIMEDOUT || code == WSAEWOULDBLOCK; -#else +#elif defined(__unix__) code == EAGAIN || code == EWOULDBLOCK; +#elif defined(__APPLE__) + code == EAGAIN; #endif } bool checkResult(int value, int errorValue, const std::string &error_msg, bool canBeTimedOut) { if (value != errorValue) { + std::cout << "=====> 3" << std::endl; return false; } + std::cout << "=====> 4" << std::endl; SocketError maybe_error(error_msg); if (canBeTimedOut && isTimeoutErrorCode(maybe_error.getErrorCode())) { + std::cout << "=====> 5" << std::endl; // just out of time: tolerable return true; } + std::cout << "=====> 6" << std::endl; throw maybe_error; } } // namespace MinimalSocket \ No newline at end of file