From 61af4207dae4e43aa16f17c77b34391bb1e3da5b Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Mon, 7 Feb 2011 23:39:36 +0100 Subject: [PATCH] Fix dns on windows --- lib/dns.js | 10 ++++++++-- src/node_os.cc | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) 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 }