diff --git a/src/node_net.cc b/src/node_net.cc index 8fe579c7e5..8ba1b7185b 100644 --- a/src/node_net.cc +++ b/src/node_net.cc @@ -648,8 +648,6 @@ static Handle Accept(const Arguments& args) { } -#ifdef __POSIX__ - static Handle SocketError(const Arguments& args) { HandleScope scope; @@ -657,17 +655,24 @@ static Handle SocketError(const Arguments& args) { int error; socklen_t len = sizeof(int); + +#ifdef __POSIX__ int r = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len); if (r < 0) { return ThrowException(ErrnoException(errno, "getsockopt")); } +#else // __MINGW32__ + int r = getsockopt(_get_osfhandle(fd), SOL_SOCKET, SO_ERROR, (char*)&error, &len); + + if (r < 0) { + return ThrowException(ErrnoException(WSAGetLastError(), "getsockopt")); + } +#endif return scope.Close(Integer::New(error)); } -#endif // __POSIX__ - // var bytesRead = t.read(fd, buffer, offset, length); // returns null on EAGAIN or EINTR, raises an exception on all other errors @@ -1505,8 +1510,8 @@ void InitNet(Handle target) { NODE_SET_METHOD(target, "bind", Bind); NODE_SET_METHOD(target, "listen", Listen); NODE_SET_METHOD(target, "accept", Accept); -#ifdef __POSIX__ NODE_SET_METHOD(target, "socketError", SocketError); +#ifdef __POSIX__ NODE_SET_METHOD(target, "toRead", ToRead); NODE_SET_METHOD(target, "setNoDelay", SetNoDelay); NODE_SET_METHOD(target, "setBroadcast", SetBroadcast);