From cecc35130369e485229bb75c4223000ffd060755 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 26 Nov 2010 02:40:39 +0100 Subject: [PATCH] Make node_net Shutdown work on windows --- src/node_net.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/node_net.cc b/src/node_net.cc index 7a07f55115..a942b0d48a 100644 --- a/src/node_net.cc +++ b/src/node_net.cc @@ -56,6 +56,13 @@ # define inet_ntop ares_inet_ntop #endif +// SHUT_* constants aren't available on windows but there are 1:1 equivalents +#ifdef __MINGW32__ +# define SHUT_RD SD_RECEIVE +# define SHUT_WR SD_SEND +# define SHUT_RDWR SD_BOTH +#endif + #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) @@ -365,8 +372,6 @@ static Handle Close(const Arguments& args) { } -#ifdef __POSIX__ - // t.shutdown(fd, "read"); -- SHUT_RD // t.shutdown(fd, "write"); -- SHUT_WR // t.shutdown(fd, "readwrite"); -- SHUT_RDWR @@ -392,13 +397,20 @@ static Handle Shutdown(const Arguments& args) { } } +#ifdef __POSIX__ if (0 > shutdown(fd, how)) { return ThrowException(ErrnoException(errno, "shutdown")); } +#else // __MINGW32__ + if (0 > shutdown(_get_osfhandle(fd), how)) { + return ThrowException(ErrnoException(WSAGetLastError(), "shutdown")); + } +#endif // __MINGW32__ return Undefined(); } +#ifdef __POSIX__ // Connect with unix // t.connect(fd, "/tmp/socket") @@ -1458,9 +1470,9 @@ void InitNet(Handle target) { NODE_SET_METHOD(target, "socket", Socket); NODE_SET_METHOD(target, "close", Close); + NODE_SET_METHOD(target, "shutdown", Shutdown); #ifdef __POSIX__ - NODE_SET_METHOD(target, "shutdown", Shutdown); NODE_SET_METHOD(target, "pipe", Pipe); NODE_SET_METHOD(target, "socketpair", SocketPair);