Index: src/exceptions/OFAcceptFailedException.m ================================================================== --- src/exceptions/OFAcceptFailedException.m +++ src/exceptions/OFAcceptFailedException.m @@ -71,8 +71,12 @@ OF_GETTER(_socket, false) } - (int)errNo { +#ifdef _WIN32 + return of_wsaerr_to_errno(_errNo); +#else return _errNo; +#endif } @end Index: src/exceptions/OFAddressTranslationFailedException.m ================================================================== --- src/exceptions/OFAddressTranslationFailedException.m +++ src/exceptions/OFAddressTranslationFailedException.m @@ -115,8 +115,12 @@ OF_GETTER(_socket, false) } - (int)errNo { +#ifdef _WIN32 + return of_wsaerr_to_errno(_errNo); +#else return _errNo; +#endif } @end Index: src/exceptions/OFBindFailedException.m ================================================================== --- src/exceptions/OFBindFailedException.m +++ src/exceptions/OFBindFailedException.m @@ -95,8 +95,12 @@ OF_GETTER(_socket, false) } - (int)errNo { +#ifdef _WIN32 + return of_wsaerr_to_errno(_errNo); +#else return _errNo; +#endif } @end Index: src/exceptions/OFConnectionFailedException.m ================================================================== --- src/exceptions/OFConnectionFailedException.m +++ src/exceptions/OFConnectionFailedException.m @@ -96,8 +96,12 @@ OF_GETTER(_socket, false) } - (int)errNo { +#ifdef _WIN32 + return of_wsaerr_to_errno(_errNo); +#else return _errNo; +#endif } @end Index: src/exceptions/OFException.h ================================================================== --- src/exceptions/OFException.h +++ src/exceptions/OFException.h @@ -19,10 +19,51 @@ @class OFString; @class OFArray; @class OFMutableArray; #define OF_BACKTRACE_SIZE 32 + +#if defined(_WIN32) && defined(OF_HAVE_SOCKETS) +# define EADDRINUSE WSAEADDRINUSE +# define EADDRNOTAVAIL WSAEADDRNOTAVAIL +# define EAFNOSUPPORT WSAEAFNOSUPPORT +# define EALREADY WSAEALREADY +# define ECONNABORTED WSAECONNABORTED +# define ECONNABORTED WSAECONNABORTED +# define ECONNREFUSED WSAECONNREFUSED +# define ECONNRESET WSAECONNRESET +# define ECONNRESET WSAECONNRESET +# define EDESTADDRREQ WSAEDESTADDRREQ +# define EDQUOT WSAEDQUOT +# define EHOSTDOWN WSAEHOSTDOWN +# define EHOSTUNREACH WSAEHOSTUNREACH +# define EINPROGRESS WSAEINPROGRESS +# define EISCONN WSAEISCONN +# define ELOOP WSAELOOP +# define EMSGSIZE WSAEMSGSIZE +# define ENETDOWN WSAENETDOWN +# define ENETRESET WSAENETRESET +# define ENETUNREACH WSAENETUNREACH +# define ENOBUFS WSAENOBUFS +# define ENOPROTOOPT WSAENOPROTOOPT +# define ENOTCONN WSAENOTCONN +# define ENOTSOCK WSAENOTSOCK +# define EOPNOTSUPP WSAEOPNOTSUPP +# define EPFNOSUPPORT WSAEPFNOSUPPORT +# define EPROCLIM WSAEPROCLIM +# define EPROTONOSUPPORT WSAEPROTONOSUPPORT +# define EPROTOTYPE WSAEPROTOTYPE +# define EREMOTE WSAEREMOTE +# define ESHUTDOWN WSAESHUTDOWN +# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT +# define ESTALE WSAESTALE +# define ETIMEDOUT WSAETIMEDOUT +# define ETOOMANYREFS WSAETOOMANYREFS +# define EUSERS WSAEUSERS +# define EWOULDBLOCK WSAEWOULDBLOCK +extern int of_wsaerr_to_errno(int); +#endif /*! * @brief The base class for all exceptions in ObjFW * * The OFException class is the base class for all exceptions in ObjFW, except Index: src/exceptions/OFException.m ================================================================== --- src/exceptions/OFException.m +++ src/exceptions/OFException.m @@ -27,10 +27,15 @@ #import "OFException.h" #import "OFString.h" #import "OFArray.h" #import "autorelease.h" + +#ifdef _WIN32 +# include +# include +#endif struct _Unwind_Context; typedef enum { _URC_OK = 0, _URC_END_OF_STACK = 5 @@ -66,10 +71,39 @@ return _URC_OK; } return _URC_END_OF_STACK; } + +#if defined(_WIN32) && defined(OF_HAVE_SOCKETS) +int +of_wsaerr_to_errno(int wsaerr) +{ + switch (wsaerr) { + case WSAEACCES: + return EACCES; + case WSAEBADF: + return EBADF; + case WSAEDISCON: + return EPIPE; + case WSAEFAULT: + return EFAULT; + case WSAEINTR: + return EINTR; + case WSAEINVAL: + return EINVAL; + case WSAENAMETOOLONG: + return ENAMETOOLONG; + case WSAENOTEMPTY: + return ENOTEMPTY; + case WSAEWOULDBLOCK: + return EAGAIN; + default: + return wsaerr; + } +} +#endif @implementation OFException + (instancetype)exception { return [[[self alloc] init] autorelease]; Index: src/exceptions/OFListenFailedException.m ================================================================== --- src/exceptions/OFListenFailedException.m +++ src/exceptions/OFListenFailedException.m @@ -80,8 +80,12 @@ return _backLog; } - (int)errNo { +#ifdef _WIN32 + return of_wsaerr_to_errno(_errNo); +#else return _errNo; +#endif } @end Index: src/exceptions/OFReadOrWriteFailedException.m ================================================================== --- src/exceptions/OFReadOrWriteFailedException.m +++ src/exceptions/OFReadOrWriteFailedException.m @@ -89,8 +89,12 @@ return _requestedLength; } - (int)errNo { +#ifdef _WIN32 + return of_wsaerr_to_errno(_errNo); +#else return _errNo; +#endif } @end