diff --git a/lib/dns.js b/lib/dns.js index 8d7eef2a64..516c7c20c2 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -33,7 +33,13 @@ function updateTimer() { var channel = new dns.Channel({SOCK_STATE_CB: function(socket, read, write) { - var watcher; + var watcher, fd; + + if (process.platform == 'win32') { + fd = process.binding('os').openOSHandle(socket); + } else { + fd = socket; + } if (socket in watchers) { watcher = watchers[socket].watcher; @@ -56,7 +62,7 @@ var channel = new dns.Channel({SOCK_STATE_CB: function(socket, read, write) { delete activeWatchers[socket]; return; } else { - watcher.set(socket, read == 1, write == 1); + watcher.set(fd, read == 1, write == 1); watcher.start(); activeWatchers[socket] = watcher; } diff --git a/src/node_os.cc b/src/node_os.cc index 8c85d1b0c8..643eb69ffb 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -9,6 +9,8 @@ #include #ifdef __MINGW32__ +# include + # include # include #endif @@ -138,6 +140,20 @@ static Handle GetLoadAvg(const Arguments& args) { return scope.Close(loads); } +#ifdef __MINGW32__ +static Handle OpenOSHandle(const Arguments& args) { + HandleScope scope; + + intptr_t handle = args[0]->IntegerValue(); + + int fd = _open_osfhandle(handle, 0); + if (fd < 0) + return ThrowException(ErrnoException(errno, "_open_osfhandle")); + + return scope.Close(Integer::New(fd)); +} +#endif // __MINGW32__ + void OS::Initialize(v8::Handle target) { HandleScope scope; @@ -149,6 +165,10 @@ void OS::Initialize(v8::Handle target) { NODE_SET_METHOD(target, "getCPUs", GetCPUInfo); NODE_SET_METHOD(target, "getOSType", GetOSType); NODE_SET_METHOD(target, "getOSRelease", GetOSRelease); + +#ifdef __MINGW32__ + NODE_SET_METHOD(target, "openOSHandle", OpenOSHandle); +#endif }