Skip to content

Commit 61af420

Browse files
piscisaureusry
authored andcommitted
Fix dns on windows
1 parent 3ec0305 commit 61af420

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

lib/dns.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ function updateTimer() {
3333

3434

3535
var channel = new dns.Channel({SOCK_STATE_CB: function(socket, read, write) {
36-
var watcher;
36+
var watcher, fd;
37+
38+
if (process.platform == 'win32') {
39+
fd = process.binding('os').openOSHandle(socket);
40+
} else {
41+
fd = socket;
42+
}
3743

3844
if (socket in watchers) {
3945
watcher = watchers[socket].watcher;
@@ -56,7 +62,7 @@ var channel = new dns.Channel({SOCK_STATE_CB: function(socket, read, write) {
5662
delete activeWatchers[socket];
5763
return;
5864
} else {
59-
watcher.set(socket, read == 1, write == 1);
65+
watcher.set(fd, read == 1, write == 1);
6066
watcher.start();
6167
activeWatchers[socket] = watcher;
6268
}

src/node_os.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <string.h>
1010

1111
#ifdef __MINGW32__
12+
# include <io.h>
13+
1214
# include <platform_win32.h>
1315
# include <platform_win32_winsock.h>
1416
#endif
@@ -138,6 +140,20 @@ static Handle<Value> GetLoadAvg(const Arguments& args) {
138140
return scope.Close(loads);
139141
}
140142

143+
#ifdef __MINGW32__
144+
static Handle<Value> OpenOSHandle(const Arguments& args) {
145+
HandleScope scope;
146+
147+
intptr_t handle = args[0]->IntegerValue();
148+
149+
int fd = _open_osfhandle(handle, 0);
150+
if (fd < 0)
151+
return ThrowException(ErrnoException(errno, "_open_osfhandle"));
152+
153+
return scope.Close(Integer::New(fd));
154+
}
155+
#endif // __MINGW32__
156+
141157
void OS::Initialize(v8::Handle<v8::Object> target) {
142158
HandleScope scope;
143159

@@ -149,6 +165,10 @@ void OS::Initialize(v8::Handle<v8::Object> target) {
149165
NODE_SET_METHOD(target, "getCPUs", GetCPUInfo);
150166
NODE_SET_METHOD(target, "getOSType", GetOSType);
151167
NODE_SET_METHOD(target, "getOSRelease", GetOSRelease);
168+
169+
#ifdef __MINGW32__
170+
NODE_SET_METHOD(target, "openOSHandle", OpenOSHandle);
171+
#endif
152172
}
153173

154174

0 commit comments

Comments
 (0)