Browse Source

Move net2 bindings out of process

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
953fa3a5f5
  1. 4
      lib/http2.js
  2. 53
      lib/net.js
  3. 20
      src/node.cc

4
lib/http2.js

@ -2,6 +2,8 @@ var sys = require('sys');
var net = require('net'); var net = require('net');
var events = require('events'); var events = require('events');
var HTTPParser = process.binding('http_parser').HTTPParser;
var CRLF = "\r\n"; var CRLF = "\r\n";
var STATUS_CODES = exports.STATUS_CODES = { var STATUS_CODES = exports.STATUS_CODES = {
100 : 'Continue', 100 : 'Continue',
@ -315,7 +317,7 @@ function newParser (type) {
parser = parserFreeList.shift(); parser = parserFreeList.shift();
parser.reinitialize(type); parser.reinitialize(type);
} else { } else {
parser = new process.HTTPParser(type); parser = new HTTPParser(type);
parser.onMessageBegin = function () { parser.onMessageBegin = function () {
parser.incoming = new IncomingMessage(parser.socket); parser.incoming = new IncomingMessage(parser.socket);

53
lib/net.js

@ -1,5 +1,7 @@
var sys = require("sys"); var sys = require("sys");
var fs = require("fs"); var fs = require("fs");
var events = require("events");
var debugLevel = 0; var debugLevel = 0;
if ('NODE_DEBUG' in process.ENV) debugLevel = 1; if ('NODE_DEBUG' in process.ENV) debugLevel = 1;
function debug (x) { function debug (x) {
@ -8,30 +10,33 @@ function debug (x) {
} }
} }
var binding = process.binding('net');
var Buffer = process.Buffer; var Buffer = process.Buffer;
var IOWatcher = process.IOWatcher; var IOWatcher = process.IOWatcher;
var assert = process.assert; var assert = process.assert;
var socket = process.socket;
var bind = process.bind; var socket = binding.socket;
var connect = process.connect; var bind = binding.bind;
var listen = process.listen; var connect = binding.connect;
var accept = process.accept; var listen = binding.listen;
var close = process.close; var accept = binding.accept;
var shutdown = process.shutdown; var close = binding.close;
var read = process.read; var shutdown = binding.shutdown;
var recvMsg = process.recvMsg; var read = binding.read;
var sendFD = process.sendFD; var recvMsg = binding.recvMsg;
var write = process.write; var sendFD = binding.sendFD;
var toRead = process.toRead; var write = binding.write;
var setNoDelay = process.setNoDelay; var toRead = binding.toRead;
var socketError = process.socketError; var setNoDelay = binding.setNoDelay;
var getsockname = process.getsockname; var socketError = binding.socketError;
var getaddrinfo = process.getaddrinfo; var getsockname = binding.getsockname;
var needsLookup = process.needsLookup; var getaddrinfo = binding.getaddrinfo;
var errnoException = process.errnoException; var needsLookup = binding.needsLookup;
var EINPROGRESS = process.EINPROGRESS; var errnoException = binding.errnoException;
var ENOENT = process.ENOENT; var EINPROGRESS = binding.EINPROGRESS;
var ENOENT = binding.ENOENT;
var END_OF_FILE = 0; var END_OF_FILE = 0;
@ -357,7 +362,7 @@ function initSocket (self) {
} }
function Socket (fd) { function Socket (fd) {
process.EventEmitter.call(this); events.EventEmitter.call(this);
this.fd = null; this.fd = null;
@ -372,7 +377,7 @@ function Socket (fd) {
this.writable = true; this.writable = true;
} }
}; };
sys.inherits(Socket, process.EventEmitter); sys.inherits(Socket, events.EventEmitter);
exports.Socket = Socket; exports.Socket = Socket;
@ -750,7 +755,7 @@ Socket.prototype.close = function () {
function Server (listener) { function Server (listener) {
process.EventEmitter.call(this); events.EventEmitter.call(this);
var self = this; var self = this;
if (listener) { if (listener) {
@ -778,7 +783,7 @@ function Server (listener) {
} }
}; };
} }
sys.inherits(Server, process.EventEmitter); sys.inherits(Server, events.EventEmitter);
exports.Server = Server; exports.Server = Server;

20
src/node.cc

@ -1139,6 +1139,24 @@ static Handle<Value> Binding(const Arguments& args) {
binding_cache->Set(module, exports); binding_cache->Set(module, exports);
} }
} else if (!strcmp(*module_v, "net")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
InitNet2(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "http_parser")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
InitHttpParser(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "natives")) { } else if (!strcmp(*module_v, "natives")) {
if (binding_cache->Has(module)) { if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject(); exports = binding_cache->Get(module)->ToObject();
@ -1267,8 +1285,6 @@ static void Load(int argc, char *argv[]) {
IOWatcher::Initialize(process); // io_watcher.cc IOWatcher::Initialize(process); // io_watcher.cc
IdleWatcher::Initialize(process); // idle_watcher.cc IdleWatcher::Initialize(process); // idle_watcher.cc
Timer::Initialize(process); // timer.cc Timer::Initialize(process); // timer.cc
InitNet2(process); // net2.cc
InitHttpParser(process); // http_parser.cc
ChildProcess::Initialize(process); // child_process.cc ChildProcess::Initialize(process); // child_process.cc
DefineConstants(process); // constants.cc DefineConstants(process); // constants.cc

Loading…
Cancel
Save