diff options
author | Bert Belder <bertbelder@gmail.com> | 2010-11-26 05:03:01 +0300 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2010-12-21 01:51:18 +0300 |
commit | 2d39e1341c156cb05bb594d76e5f963f7d8bdefb (patch) | |
tree | 9385fd82d77736fccb6d2a2ac9e68c33b1adc72e /src | |
parent | cecc35130369e485229bb75c4223000ffd060755 (diff) |
Make node_net Connect work
Diffstat (limited to 'src')
-rw-r--r-- | src/node_net.cc | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/node_net.cc b/src/node_net.cc index a942b0d48ae..b25b3412739 100644 --- a/src/node_net.cc +++ b/src/node_net.cc @@ -410,8 +410,6 @@ static Handle<Value> Shutdown(const Arguments& args) { return Undefined(); } -#ifdef __POSIX__ - // Connect with unix // t.connect(fd, "/tmp/socket") // @@ -433,17 +431,24 @@ static Handle<Value> Connect(const Arguments& args) { Handle<Value> 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<Object> 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); |