Permalink
Browse files

Define winsock error numbers

  • Loading branch information...
1 parent c99962e commit 0eb4c2157da0ff3a429a89badce91f4f3598af60 @piscisaureus piscisaureus committed Jan 17, 2011
Showing with 470 additions and 7 deletions.
  1. +0 −3 TODO.win32
  2. +1 −1 lib/net.js
  3. +228 −0 src/node.cc
  4. +237 −0 src/node_constants.cc
  5. +4 −3 src/node_os.cc
View
3 TODO.win32
@@ -55,9 +55,6 @@
If socket() fails it returns -1 so _open_osfhandle fails as well, but and we'll always return/throw EBADF.
If _open_osfhandle fails but socket doesn't, a stray handle is left open. It should be fixed.
-- Check error number mappings.
- Winsock errnos are sometimes different. Subtracting WSABASEERR from errnos works in most cases.
-
- Think about `make install`
- Extensions
View
2 lib/net.js
@@ -48,7 +48,7 @@ var errnoException = binding.errnoException;
var sendMsg = binding.sendMsg;
var recvMsg = binding.recvMsg;
-var EINPROGRESS = constants.EINPROGRESS;
+var EINPROGRESS = constants.EINPROGRESS || constants.WSAEINPROGRESS;
var ENOENT = constants.ENOENT;
var EMFILE = constants.EMFILE;
View
228 src/node.cc
@@ -616,6 +616,234 @@ static inline const char *errno_string(int errorno) {
ERRNO_CASE(EXDEV);
#endif
+#ifdef WSAEINTR
+ ERRNO_CASE(WSAEINTR);
+#endif
+
+#ifdef WSAEBADF
+ ERRNO_CASE(WSAEBADF);
+#endif
+
+#ifdef WSAEACCES
+ ERRNO_CASE(WSAEACCES);
+#endif
+
+#ifdef WSAEFAULT
+ ERRNO_CASE(WSAEFAULT);
+#endif
+
+#ifdef WSAEINVAL
+ ERRNO_CASE(WSAEINVAL);
+#endif
+
+#ifdef WSAEMFILE
+ ERRNO_CASE(WSAEMFILE);
+#endif
+
+#ifdef WSAEWOULDBLOCK
+ ERRNO_CASE(WSAEWOULDBLOCK);
+#endif
+
+#ifdef WSAEINPROGRESS
+ ERRNO_CASE(WSAEINPROGRESS);
+#endif
+
+#ifdef WSAEALREADY
+ ERRNO_CASE(WSAEALREADY);
+#endif
+
+#ifdef WSAENOTSOCK
+ ERRNO_CASE(WSAENOTSOCK);
+#endif
+
+#ifdef WSAEDESTADDRREQ
+ ERRNO_CASE(WSAEDESTADDRREQ);
+#endif
+
+#ifdef WSAEMSGSIZE
+ ERRNO_CASE(WSAEMSGSIZE);
+#endif
+
+#ifdef WSAEPROTOTYPE
+ ERRNO_CASE(WSAEPROTOTYPE);
+#endif
+
+#ifdef WSAENOPROTOOPT
+ ERRNO_CASE(WSAENOPROTOOPT);
+#endif
+
+#ifdef WSAEPROTONOSUPPORT
+ ERRNO_CASE(WSAEPROTONOSUPPORT);
+#endif
+
+#ifdef WSAESOCKTNOSUPPORT
+ ERRNO_CASE(WSAESOCKTNOSUPPORT);
+#endif
+
+#ifdef WSAEOPNOTSUPP
+ ERRNO_CASE(WSAEOPNOTSUPP);
+#endif
+
+#ifdef WSAEPFNOSUPPORT
+ ERRNO_CASE(WSAEPFNOSUPPORT);
+#endif
+
+#ifdef WSAEAFNOSUPPORT
+ ERRNO_CASE(WSAEAFNOSUPPORT);
+#endif
+
+#ifdef WSAEADDRINUSE
+ ERRNO_CASE(WSAEADDRINUSE);
+#endif
+
+#ifdef WSAEADDRNOTAVAIL
+ ERRNO_CASE(WSAEADDRNOTAVAIL);
+#endif
+
+#ifdef WSAENETDOWN
+ ERRNO_CASE(WSAENETDOWN);
+#endif
+
+#ifdef WSAENETUNREACH
+ ERRNO_CASE(WSAENETUNREACH);
+#endif
+
+#ifdef WSAENETRESET
+ ERRNO_CASE(WSAENETRESET);
+#endif
+
+#ifdef WSAECONNABORTED
+ ERRNO_CASE(WSAECONNABORTED);
+#endif
+
+#ifdef WSAECONNRESET
+ ERRNO_CASE(WSAECONNRESET);
+#endif
+
+#ifdef WSAENOBUFS
+ ERRNO_CASE(WSAENOBUFS);
+#endif
+
+#ifdef WSAEISCONN
+ ERRNO_CASE(WSAEISCONN);
+#endif
+
+#ifdef WSAENOTCONN
+ ERRNO_CASE(WSAENOTCONN);
+#endif
+
+#ifdef WSAESHUTDOWN
+ ERRNO_CASE(WSAESHUTDOWN);
+#endif
+
+#ifdef WSAETOOMANYREFS
+ ERRNO_CASE(WSAETOOMANYREFS);
+#endif
+
+#ifdef WSAETIMEDOUT
+ ERRNO_CASE(WSAETIMEDOUT);
+#endif
+
+#ifdef WSAECONNREFUSED
+ ERRNO_CASE(WSAECONNREFUSED);
+#endif
+
+#ifdef WSAELOOP
+ ERRNO_CASE(WSAELOOP);
+#endif
+
+#ifdef WSAENAMETOOLONG
+ ERRNO_CASE(WSAENAMETOOLONG);
+#endif
+
+#ifdef WSAEHOSTDOWN
+ ERRNO_CASE(WSAEHOSTDOWN);
+#endif
+
+#ifdef WSAEHOSTUNREACH
+ ERRNO_CASE(WSAEHOSTUNREACH);
+#endif
+
+#ifdef WSAENOTEMPTY
+ ERRNO_CASE(WSAENOTEMPTY);
+#endif
+
+#ifdef WSAEPROCLIM
+ ERRNO_CASE(WSAEPROCLIM);
+#endif
+
+#ifdef WSAEUSERS
+ ERRNO_CASE(WSAEUSERS);
+#endif
+
+#ifdef WSAEDQUOT
+ ERRNO_CASE(WSAEDQUOT);
+#endif
+
+#ifdef WSAESTALE
+ ERRNO_CASE(WSAESTALE);
+#endif
+
+#ifdef WSAEREMOTE
+ ERRNO_CASE(WSAEREMOTE);
+#endif
+
+#ifdef WSASYSNOTREADY
+ ERRNO_CASE(WSASYSNOTREADY);
+#endif
+
+#ifdef WSAVERNOTSUPPORTED
+ ERRNO_CASE(WSAVERNOTSUPPORTED);
+#endif
+
+#ifdef WSANOTINITIALISED
+ ERRNO_CASE(WSANOTINITIALISED);
+#endif
+
+#ifdef WSAEDISCON
+ ERRNO_CASE(WSAEDISCON);
+#endif
+
+#ifdef WSAENOMORE
+ ERRNO_CASE(WSAENOMORE);
+#endif
+
+#ifdef WSAECANCELLED
+ ERRNO_CASE(WSAECANCELLED);
+#endif
+
+#ifdef WSAEINVALIDPROCTABLE
+ ERRNO_CASE(WSAEINVALIDPROCTABLE);
+#endif
+
+#ifdef WSAEINVALIDPROVIDER
+ ERRNO_CASE(WSAEINVALIDPROVIDER);
+#endif
+
+#ifdef WSAEPROVIDERFAILEDINIT
+ ERRNO_CASE(WSAEPROVIDERFAILEDINIT);
+#endif
+
+#ifdef WSASYSCALLFAILURE
+ ERRNO_CASE(WSASYSCALLFAILURE);
+#endif
+
+#ifdef WSASERVICE_NOT_FOUND
+ ERRNO_CASE(WSASERVICE_NOT_FOUND);
+#endif
+
+#ifdef WSATYPE_NOT_FOUND
+ ERRNO_CASE(WSATYPE_NOT_FOUND);
+#endif
+
+#ifdef WSA_E_NO_MORE
+ ERRNO_CASE(WSA_E_NO_MORE);
+#endif
+
+#ifdef WSA_E_CANCELLED
+ ERRNO_CASE(WSA_E_CANCELLED);
+#endif
+
default: return "";
}
}
View
237 src/node_constants.cc
@@ -10,6 +10,11 @@
#include <sys/types.h>
#include <sys/stat.h>
+#ifdef __MINGW32__
+# include <platform_win32.h>
+# include <platform_win32_winsock.h>
+#endif
+
namespace node {
using namespace v8;
@@ -443,6 +448,238 @@ void DefineConstants(Handle<Object> target) {
NODE_DEFINE_CONSTANT(target, EXDEV);
#endif
+#ifdef WSAEINTR
+ NODE_DEFINE_CONSTANT(target, WSAEINTR);
+#endif
+
+#ifdef WSAEBADF
+ NODE_DEFINE_CONSTANT(target, WSAEBADF);
+#endif
+
+#ifdef WSAEACCES
+ NODE_DEFINE_CONSTANT(target, WSAEACCES);
+#endif
+
+#ifdef WSAEFAULT
+ NODE_DEFINE_CONSTANT(target, WSAEFAULT);
+#endif
+
+#ifdef WSAEINVAL
+ NODE_DEFINE_CONSTANT(target, WSAEINVAL);
+#endif
+
+#ifdef WSAEMFILE
+ NODE_DEFINE_CONSTANT(target, WSAEMFILE);
+#endif
+
+#ifdef WSAEWOULDBLOCK
+ NODE_DEFINE_CONSTANT(target, WSAEWOULDBLOCK);
+#endif
+
+#ifdef WSAEINPROGRESS
+ NODE_DEFINE_CONSTANT(target, WSAEINPROGRESS);
+#endif
+
+#ifdef WSAEALREADY
+ NODE_DEFINE_CONSTANT(target, WSAEALREADY);
+#endif
+
+#ifdef WSAENOTSOCK
+ NODE_DEFINE_CONSTANT(target, WSAENOTSOCK);
+#endif
+
+#ifdef WSAEDESTADDRREQ
+ NODE_DEFINE_CONSTANT(target, WSAEDESTADDRREQ);
+#endif
+
+#ifdef WSAEMSGSIZE
+ NODE_DEFINE_CONSTANT(target, WSAEMSGSIZE);
+#endif
+
+#ifdef WSAEPROTOTYPE
+ NODE_DEFINE_CONSTANT(target, WSAEPROTOTYPE);
+#endif
+
+#ifdef WSAENOPROTOOPT
+ NODE_DEFINE_CONSTANT(target, WSAENOPROTOOPT);
+#endif
+
+#ifdef WSAEPROTONOSUPPORT
+ NODE_DEFINE_CONSTANT(target, WSAEPROTONOSUPPORT);
+#endif
+
+#ifdef WSAESOCKTNOSUPPORT
+ NODE_DEFINE_CONSTANT(target, WSAESOCKTNOSUPPORT);
+#endif
+
+#ifdef WSAEOPNOTSUPP
+ NODE_DEFINE_CONSTANT(target, WSAEOPNOTSUPP);
+#endif
+
+#ifdef WSAEPFNOSUPPORT
+ NODE_DEFINE_CONSTANT(target, WSAEPFNOSUPPORT);
+#endif
+
+#ifdef WSAEAFNOSUPPORT
+ NODE_DEFINE_CONSTANT(target, WSAEAFNOSUPPORT);
+#endif
+
+#ifdef WSAEADDRINUSE
+ NODE_DEFINE_CONSTANT(target, WSAEADDRINUSE);
+#endif
+
+#ifdef WSAEADDRNOTAVAIL
+ NODE_DEFINE_CONSTANT(target, WSAEADDRNOTAVAIL);
+#endif
+
+#ifdef WSAENETDOWN
+ NODE_DEFINE_CONSTANT(target, WSAENETDOWN);
+#endif
+
+#ifdef WSAENETUNREACH
+ NODE_DEFINE_CONSTANT(target, WSAENETUNREACH);
+#endif
+
+#ifdef WSAENETRESET
+ NODE_DEFINE_CONSTANT(target, WSAENETRESET);
+#endif
+
+#ifdef WSAECONNABORTED
+ NODE_DEFINE_CONSTANT(target, WSAECONNABORTED);
+#endif
+
+#ifdef WSAECONNRESET
+ NODE_DEFINE_CONSTANT(target, WSAECONNRESET);
+#endif
+
+#ifdef WSAENOBUFS
+ NODE_DEFINE_CONSTANT(target, WSAENOBUFS);
+#endif
+
+#ifdef WSAEISCONN
+ NODE_DEFINE_CONSTANT(target, WSAEISCONN);
+#endif
+
+#ifdef WSAENOTCONN
+ NODE_DEFINE_CONSTANT(target, WSAENOTCONN);
+#endif
+
+#ifdef WSAESHUTDOWN
+ NODE_DEFINE_CONSTANT(target, WSAESHUTDOWN);
+#endif
+
+#ifdef WSAETOOMANYREFS
+ NODE_DEFINE_CONSTANT(target, WSAETOOMANYREFS);
+#endif
+
+#ifdef WSAETIMEDOUT
+ NODE_DEFINE_CONSTANT(target, WSAETIMEDOUT);
+#endif
+
+#ifdef WSAECONNREFUSED
+ NODE_DEFINE_CONSTANT(target, WSAECONNREFUSED);
+#endif
+
+#ifdef WSAELOOP
+ NODE_DEFINE_CONSTANT(target, WSAELOOP);
+#endif
+
+#ifdef WSAENAMETOOLONG
+ NODE_DEFINE_CONSTANT(target, WSAENAMETOOLONG);
+#endif
+
+#ifdef WSAEHOSTDOWN
+ NODE_DEFINE_CONSTANT(target, WSAEHOSTDOWN);
+#endif
+
+#ifdef WSAEHOSTUNREACH
+ NODE_DEFINE_CONSTANT(target, WSAEHOSTUNREACH);
+#endif
+
+#ifdef WSAENOTEMPTY
+ NODE_DEFINE_CONSTANT(target, WSAENOTEMPTY);
+#endif
+
+#ifdef WSAEPROCLIM
+ NODE_DEFINE_CONSTANT(target, WSAEPROCLIM);
+#endif
+
+#ifdef WSAEUSERS
+ NODE_DEFINE_CONSTANT(target, WSAEUSERS);
+#endif
+
+#ifdef WSAEDQUOT
+ NODE_DEFINE_CONSTANT(target, WSAEDQUOT);
+#endif
+
+#ifdef WSAESTALE
+ NODE_DEFINE_CONSTANT(target, WSAESTALE);
+#endif
+
+#ifdef WSAEREMOTE
+ NODE_DEFINE_CONSTANT(target, WSAEREMOTE);
+#endif
+
+#ifdef WSASYSNOTREADY
+ NODE_DEFINE_CONSTANT(target, WSASYSNOTREADY);
+#endif
+
+#ifdef WSAVERNOTSUPPORTED
+ NODE_DEFINE_CONSTANT(target, WSAVERNOTSUPPORTED);
+#endif
+
+#ifdef WSANOTINITIALISED
+ NODE_DEFINE_CONSTANT(target, WSANOTINITIALISED);
+#endif
+
+#ifdef WSAEDISCON
+ NODE_DEFINE_CONSTANT(target, WSAEDISCON);
+#endif
+
+#ifdef WSAENOMORE
+ NODE_DEFINE_CONSTANT(target, WSAENOMORE);
+#endif
+
+#ifdef WSAECANCELLED
+ NODE_DEFINE_CONSTANT(target, WSAECANCELLED);
+#endif
+
+#ifdef WSAEINVALIDPROCTABLE
+ NODE_DEFINE_CONSTANT(target, WSAEINVALIDPROCTABLE);
+#endif
+
+#ifdef WSAEINVALIDPROVIDER
+ NODE_DEFINE_CONSTANT(target, WSAEINVALIDPROVIDER);
+#endif
+
+#ifdef WSAEPROVIDERFAILEDINIT
+ NODE_DEFINE_CONSTANT(target, WSAEPROVIDERFAILEDINIT);
+#endif
+
+#ifdef WSASYSCALLFAILURE
+ NODE_DEFINE_CONSTANT(target, WSASYSCALLFAILURE);
+#endif
+
+#ifdef WSASERVICE_NOT_FOUND
+ NODE_DEFINE_CONSTANT(target, WSASERVICE_NOT_FOUND);
+#endif
+
+#ifdef WSATYPE_NOT_FOUND
+ NODE_DEFINE_CONSTANT(target, WSATYPE_NOT_FOUND);
+#endif
+
+#ifdef WSA_E_NO_MORE
+ NODE_DEFINE_CONSTANT(target, WSA_E_NO_MORE);
+#endif
+
+#ifdef WSA_E_CANCELLED
+ NODE_DEFINE_CONSTANT(target, WSA_E_CANCELLED);
+#endif
+
+#ifdef WSAEREFUSED
+ NODE_DEFINE_CONSTANT(target, WSAEREFUSED);
+#endif
+
#ifdef SIGHUP
NODE_DEFINE_CONSTANT(target, SIGHUP);
#endif
View
7 src/node_os.cc
@@ -28,10 +28,11 @@ static Handle<Value> GetHostname(const Arguments& args) {
int r = gethostname(s, 255);
if (r < 0) {
-#ifdef __MINGW32__
- errno = WSAGetLastError() - WSABASEERR;
-#endif
+#ifdef __POSIX__
return ThrowException(ErrnoException(errno, "gethostname"));
+#else // __MINGW32__
+ return ThrowException(ErrnoException(WSAGetLastError(), "gethostname"));
+#endif // __MINGW32__
}
return scope.Close(String::New(s));

0 comments on commit 0eb4c21

Please sign in to comment.