Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIgor Zinkovsky <igorzi@microsoft.com>2012-01-20 04:52:23 +0400
committerIgor Zinkovsky <igorzi@microsoft.com>2012-02-01 05:45:50 +0400
commitdb3c4efd1d95e6c7fc47b9c07216beb7029cf7bc (patch)
tree3f61d611f6c92945c9962455aed479968cfb9c6c /lib
parent33b7fc250f061af42b595decf6c0edf360c5aae9 (diff)
support for sharing streams accross isolates
Diffstat (limited to 'lib')
-rw-r--r--lib/child_process.js42
-rw-r--r--lib/net.js23
2 files changed, 39 insertions, 26 deletions
diff --git a/lib/child_process.js b/lib/child_process.js
index a1eac7744dd..9723730ce77 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -68,29 +68,13 @@ function mergeOptions(target, overrides) {
function setupChannel(target, channel) {
- var isWindows = process.platform === 'win32';
target._channel = channel;
var jsonBuffer = '';
-
- if (isWindows) {
- var setSimultaneousAccepts = function(handle) {
- var simultaneousAccepts = (process.env.NODE_MANY_ACCEPTS &&
- process.env.NODE_MANY_ACCEPTS != '0') ? true : false;
-
- if (handle._simultaneousAccepts != simultaneousAccepts) {
- handle.setSimultaneousAccepts(simultaneousAccepts);
- handle._simultaneousAccepts = simultaneousAccepts;
- }
- }
- }
-
channel.buffering = false;
channel.onread = function(pool, offset, length, recvHandle) {
- if (recvHandle && setSimultaneousAccepts) {
- // Update simultaneous accepts on Windows
- setSimultaneousAccepts(recvHandle);
- }
+ // Update simultaneous accepts on Windows
+ net._setSimultaneousAccepts(recvHandle);
if (pool) {
jsonBuffer += pool.toString('ascii', offset, offset + length);
@@ -140,10 +124,8 @@ function setupChannel(target, channel) {
var buffer = Buffer(JSON.stringify(message) + '\n');
- if (sendHandle && setSimultaneousAccepts) {
- // Update simultaneous accepts on Windows
- setSimultaneousAccepts(sendHandle);
- }
+ // Update simultaneous accepts on Windows
+ net._setSimultaneousAccepts(sendHandle);
var writeReq = channel.write(buffer, 0, buffer.length, sendHandle);
@@ -582,9 +564,13 @@ Isolate.prototype.spawn = function(options) {
self._handle = isolates.create(options.args, options.options);
if (!self._handle) throw new Error('Cannot create isolate.');
- self._handle.onmessage = function(msg) {
+ self._handle.onmessage = function(msg, recvHandle) {
msg = JSON.parse('' + msg);
- self.emit('message', msg);
+
+ // Update simultaneous accepts on Windows
+ net._setSimultaneousAccepts(recvHandle);
+
+ self.emit('message', msg, recvHandle);
};
self._handle.onexit = function() {
@@ -600,10 +586,14 @@ Isolate.prototype.kill = function(sig) {
};
-Isolate.prototype.send = function(msg) {
+Isolate.prototype.send = function(msg, sendHandle) {
if (typeof msg === 'undefined') throw new TypeError('Bad argument.');
if (!this._handle) throw new Error('Isolate not running.');
msg = JSON.stringify(msg);
msg = new Buffer(msg);
- return this._handle.send(msg);
+
+ // Update simultaneous accepts on Windows
+ net._setSimultaneousAccepts(sendHandle);
+
+ return this._handle.send(msg, sendHandle);
};
diff --git a/lib/net.js b/lib/net.js
index a14a00c0a80..006036aaf29 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -942,3 +942,26 @@ exports.isIPv4 = function(input) {
exports.isIPv6 = function(input) {
return exports.isIP(input) === 6;
};
+
+
+if (process.platform === 'win32') {
+ var simultaneousAccepts;
+
+ exports._setSimultaneousAccepts = function(handle) {
+ if (typeof handle === 'undefined') {
+ return;
+ }
+
+ if (typeof simultaneousAccepts === 'undefined') {
+ simultaneousAccepts = (process.env.NODE_MANY_ACCEPTS &&
+ process.env.NODE_MANY_ACCEPTS != '0') ? true : false;
+ }
+
+ if (handle._simultaneousAccepts != simultaneousAccepts) {
+ handle.setSimultaneousAccepts(simultaneousAccepts);
+ handle._simultaneousAccepts = simultaneousAccepts;
+ }
+ }
+} else {
+ exports._setSimultaneousAccepts = function(handle) {}
+}