Move IOWatcher and Timer to process.binding
This commit is contained in:
parent
5a801d63d1
commit
01b3418e2e
@ -4,7 +4,7 @@ var events = require("events");
|
|||||||
var dns = require('dns');
|
var dns = require('dns');
|
||||||
|
|
||||||
var Buffer = require('buffer').Buffer;
|
var Buffer = require('buffer').Buffer;
|
||||||
var IOWatcher = process.IOWatcher;
|
var IOWatcher = process.binding('io_watcher').IOWatcher;
|
||||||
var binding = process.binding('net');
|
var binding = process.binding('net');
|
||||||
var socket = binding.socket;
|
var socket = binding.socket;
|
||||||
var recvfrom = binding.recvfrom;
|
var recvfrom = binding.recvfrom;
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
var dns = process.binding('cares');
|
var dns = process.binding('cares');
|
||||||
var net = process.binding('net');
|
var net = process.binding('net');
|
||||||
|
var IOWatcher = process.binding('io_watcher').IOWatcher;
|
||||||
|
|
||||||
|
|
||||||
var watchers = {};
|
var watchers = {};
|
||||||
var activeWatchers = {};
|
var activeWatchers = {};
|
||||||
|
var Timer = process.binding('timer').Timer;
|
||||||
|
|
||||||
|
var timer = new Timer();
|
||||||
var timer = new process.Timer();
|
|
||||||
|
|
||||||
timer.callback = function () {
|
timer.callback = function () {
|
||||||
var sockets = Object.keys(activeWatchers);
|
var sockets = Object.keys(activeWatchers);
|
||||||
@ -44,7 +45,7 @@ var channel = new dns.Channel({SOCK_STATE_CB: function (socket, read, write) {
|
|||||||
if (socket in watchers) {
|
if (socket in watchers) {
|
||||||
watcher = watchers[socket].watcher;
|
watcher = watchers[socket].watcher;
|
||||||
} else {
|
} else {
|
||||||
watcher = new process.IOWatcher();
|
watcher = new IOWatcher();
|
||||||
watchers[socket] = { read: read
|
watchers[socket] = { read: read
|
||||||
, write: write
|
, write: write
|
||||||
, watcher: watcher
|
, watcher: watcher
|
||||||
|
@ -23,7 +23,8 @@ var binding = process.binding('net');
|
|||||||
var Buffer = require('buffer').Buffer;
|
var Buffer = require('buffer').Buffer;
|
||||||
var FreeList = require('freelist').FreeList;
|
var FreeList = require('freelist').FreeList;
|
||||||
|
|
||||||
var IOWatcher = process.IOWatcher;
|
var IOWatcher = process.binding('io_watcher').IOWatcher;
|
||||||
|
var Timer = process.binding('timer').Timer;
|
||||||
var assert = process.assert;
|
var assert = process.assert;
|
||||||
|
|
||||||
var socket = binding.socket;
|
var socket = binding.socket;
|
||||||
@ -125,7 +126,7 @@ var timeout = new (function () {
|
|||||||
if (lists[msecs]) {
|
if (lists[msecs]) {
|
||||||
list = lists[msecs];
|
list = lists[msecs];
|
||||||
} else {
|
} else {
|
||||||
list = new process.Timer();
|
list = new Timer();
|
||||||
list._idleNext = list;
|
list._idleNext = list;
|
||||||
list._idlePrev = list;
|
list._idlePrev = list;
|
||||||
|
|
||||||
|
18
src/node.cc
18
src/node.cc
@ -1464,6 +1464,16 @@ static Handle<Value> Binding(const Arguments& args) {
|
|||||||
DefineConstants(exports);
|
DefineConstants(exports);
|
||||||
binding_cache->Set(module, exports);
|
binding_cache->Set(module, exports);
|
||||||
|
|
||||||
|
} else if (!strcmp(*module_v, "io_watcher")) {
|
||||||
|
exports = Object::New();
|
||||||
|
IOWatcher::Initialize(exports);
|
||||||
|
binding_cache->Set(module, exports);
|
||||||
|
|
||||||
|
} else if (!strcmp(*module_v, "timer")) {
|
||||||
|
exports = Object::New();
|
||||||
|
Timer::Initialize(exports);
|
||||||
|
binding_cache->Set(module, exports);
|
||||||
|
|
||||||
} else if (!strcmp(*module_v, "natives")) {
|
} else if (!strcmp(*module_v, "natives")) {
|
||||||
exports = Object::New();
|
exports = Object::New();
|
||||||
// Explicitly define native sources.
|
// Explicitly define native sources.
|
||||||
@ -1620,14 +1630,6 @@ static void Load(int argc, char *argv[]) {
|
|||||||
process->Set(String::NewSymbol("EventEmitter"),
|
process->Set(String::NewSymbol("EventEmitter"),
|
||||||
EventEmitter::constructor_template->GetFunction());
|
EventEmitter::constructor_template->GetFunction());
|
||||||
|
|
||||||
|
|
||||||
// Initialize the C++ modules..................filename of module
|
|
||||||
IOWatcher::Initialize(process); // io_watcher.cc
|
|
||||||
// Not in use at the moment.
|
|
||||||
//IdleWatcher::Initialize(process); // idle_watcher.cc
|
|
||||||
Timer::Initialize(process); // timer.cc
|
|
||||||
// coverity[stack_use_callee]
|
|
||||||
|
|
||||||
// Compile, execute the src/node.js file. (Which was included as static C
|
// Compile, execute the src/node.js file. (Which was included as static C
|
||||||
// string in node_natives.h. 'natve_node' is the string containing that
|
// string in node_natives.h. 'natve_node' is the string containing that
|
||||||
// source code.)
|
// source code.)
|
||||||
|
12
src/node.js
12
src/node.js
@ -158,28 +158,34 @@ function addTimerListener (callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Timer; // lazy load
|
||||||
|
|
||||||
global.setTimeout = function (callback, after) {
|
global.setTimeout = function (callback, after) {
|
||||||
var timer = new process.Timer();
|
if (!Timer) Timer = process.binding("timer").Timer;
|
||||||
|
var timer = new Timer();
|
||||||
addTimerListener.apply(timer, arguments);
|
addTimerListener.apply(timer, arguments);
|
||||||
timer.start(after, 0);
|
timer.start(after, 0);
|
||||||
return timer;
|
return timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
global.setInterval = function (callback, repeat) {
|
global.setInterval = function (callback, repeat) {
|
||||||
var timer = new process.Timer();
|
if (!Timer) Timer = process.binding("timer").Timer;
|
||||||
|
var timer = new Timer();
|
||||||
addTimerListener.apply(timer, arguments);
|
addTimerListener.apply(timer, arguments);
|
||||||
timer.start(repeat, repeat ? repeat : 1);
|
timer.start(repeat, repeat ? repeat : 1);
|
||||||
return timer;
|
return timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
global.clearTimeout = function (timer) {
|
global.clearTimeout = function (timer) {
|
||||||
if (timer instanceof process.Timer) {
|
if (!Timer) Timer = process.binding("timer").Timer;
|
||||||
|
if (timer instanceof Timer) {
|
||||||
timer.stop();
|
timer.stop();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
global.clearInterval = global.clearTimeout;
|
global.clearInterval = global.clearTimeout;
|
||||||
|
|
||||||
|
|
||||||
var stdout;
|
var stdout;
|
||||||
process.__defineGetter__('stdout', function () {
|
process.__defineGetter__('stdout', function () {
|
||||||
if (stdout) return stdout;
|
if (stdout) return stdout;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user