forked from nodejs/node-v0.x-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_io_watcher.js
More file actions
46 lines (33 loc) · 1017 Bytes
/
_io_watcher.js
File metadata and controls
46 lines (33 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var assert = process.assert;
var set = require('_set');
var ioAlloc = process.binding('io_watcher').ioAlloc;
var ioFree = process.binding('io_watcher').ioFree;
var ioStop = process.binding('io_watcher').ioStop;
var ioStart = process.binding('io_watcher').ioStart;
var ioSet = process.binding('io_watcher').ioSet;
// We keep a reference to each watcher so they are not GCed.
var allWatchers = set.create();
function IOWatcher(object) {
this.pointer = ioAlloc(object);
allWatchers.add(this);
};
exports.IOWatcher = IOWatcher;
IOWatcher.prototype.set = function(fd, readable, writable) {
assert(this.pointer);
this.stop();
ioSet(this.pointer, fd, readable, writable);
};
IOWatcher.prototype.start = function() {
assert(this.pointer);
ioStart(this.pointer);
};
IOWatcher.prototype.stop = function() {
assert(this.pointer);
ioStop(this.pointer);
};
IOWatcher.prototype.free = function() {
assert(this.pointer);
ioFree(this.pointer);
this.pointer = null;
allWatchers.remove(this);
};