vapor-community / sockets

🔌 Non-blocking TCP socket layer, with event-driven server and client.
MIT License
575 stars 54 forks source link

errno values aren't portable #80

Closed weissi closed 7 years ago

weissi commented 8 years ago

In Error.swift, a lookup table errorDescriptions from errno value to error string is defined. It seems like it's a copy from Linux as there is

        11: "Resource temporarily unavailable",

which corresponds to EAGAIN I think. However, on the different Unices, the errno values aren't the same. for example on Linux

$ uname -srvmp
Linux 4.4.0-36-generic #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016 x86_64 x86_64
$ find /usr/include/ -name 'errno*' -exec grep EAGAIN '{}' \;
#define EWOULDBLOCK EAGAIN  /* Operation would block */
#define EAGAIN      11  /* Try again */

but on macOS:

$ uname -srvmp
 Darwin 16.1.0 Darwin Kernel Version 16.1.0: Sat Sep 17 23:18:50 PDT 2016; root:xnu-3789.20.47~8/DEVELOPMENT_X86_64 x86_64 i386
$ find /usr/include/ -name 'errno*' -exec grep EAGAIN '{}' \;
                    /* 11 was EAGAIN */
 #define    EAGAIN      35      /* Resource temporarily unavailable */
 #define    EWOULDBLOCK EAGAIN      /* Operation would block */

On macOS, 11 is EDEADLK:

#define EDEADLK     11      /* Resource deadlock avoided */
                    /* 11 was EAGAIN */

The correct way of generating this table would be to use strerror(3) or maybe include a platform specific version.

andreasley commented 7 years ago

Fixed in version 1.2.0

tanner0101 commented 7 years ago

Closing this if it's fixed.