From 2d39e1341c156cb05bb594d76e5f963f7d8bdefb Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 26 Nov 2010 03:03:01 +0100 Subject: [PATCH] Make node_net Connect work --- src/node_net.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/node_net.cc b/src/node_net.cc index a942b0d48a..b25b341273 100644 --- a/src/node_net.cc +++ b/src/node_net.cc @@ -410,8 +410,6 @@ static Handle Shutdown(const Arguments& args) { return Undefined(); } -#ifdef __POSIX__ - // Connect with unix // t.connect(fd, "/tmp/socket") // @@ -433,17 +431,24 @@ static Handle Connect(const Arguments& args) { Handle error = ParseAddressArgs(args[1], args[2], false); if (!error.IsEmpty()) return ThrowException(error); +#ifdef __POSIX__ int r = connect(fd, addr, addrlen); - if (r < 0 && errno != EINPROGRESS) { return ThrowException(ErrnoException(errno, "connect")); } +#else // __MINGW32__ + int r = connect(_get_osfhandle(fd), addr, addrlen); + if (r == INVALID_SOCKET) { + int winsockErrno = WSAGetLastError(); + if (winsockErrno != WSAEALREADY && winsockErrno != WSAEINPROGRESS) { + return ThrowException(ErrnoException(winsockErrno, "connect")); + } + } +#endif // __MINGW32__ return Undefined(); } -#endif // __POSIX__ - #ifdef __POSIX__ @@ -1475,10 +1480,9 @@ void InitNet(Handle target) { #ifdef __POSIX__ NODE_SET_METHOD(target, "pipe", Pipe); NODE_SET_METHOD(target, "socketpair", SocketPair); - - NODE_SET_METHOD(target, "connect", Connect); #endif // __POSIX__ + NODE_SET_METHOD(target, "connect", Connect); NODE_SET_METHOD(target, "bind", Bind); NODE_SET_METHOD(target, "listen", Listen); NODE_SET_METHOD(target, "accept", Accept);