|
|
@ -73,7 +73,7 @@ function setupChannel(target, channel) { |
|
|
|
|
|
|
|
var jsonBuffer = ''; |
|
|
|
|
|
|
|
channel.onread = function(pool, offset, length) { |
|
|
|
channel.onread = function(pool, offset, length, recvStream) { |
|
|
|
if (pool) { |
|
|
|
for (var i = 0; i < length; i++) { |
|
|
|
if (pool[offset + i] === LF) { |
|
|
@ -82,7 +82,7 @@ function setupChannel(target, channel) { |
|
|
|
jsonBuffer = pool.toString('ascii', i, length); |
|
|
|
offset = i + 1; |
|
|
|
|
|
|
|
target.emit('message', message); |
|
|
|
target.emit('message', message, recvStream); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
@ -91,11 +91,14 @@ function setupChannel(target, channel) { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
target.send = function(message, fd) { |
|
|
|
if (fd) throw new Error("not yet implemented"); |
|
|
|
|
|
|
|
target.send = function(message, sendStream) { |
|
|
|
if (!target._channel) throw new Error("channel closed"); |
|
|
|
|
|
|
|
// Open up net.Socket instances
|
|
|
|
if (sendStream instanceof require('net').Socket) { |
|
|
|
sendStream = sendStream._handle; |
|
|
|
} |
|
|
|
|
|
|
|
// For overflow protection don't write if channel queue is too deep.
|
|
|
|
if (channel.writeQueueSize > 1024 * 1024) { |
|
|
|
return false; |
|
|
@ -103,7 +106,7 @@ function setupChannel(target, channel) { |
|
|
|
|
|
|
|
var buffer = Buffer(JSON.stringify(message) + '\n'); |
|
|
|
|
|
|
|
var writeReq = channel.write(buffer); |
|
|
|
var writeReq = channel.write(buffer, 0, buffer.length, sendStream); |
|
|
|
|
|
|
|
if (!writeReq) { |
|
|
|
throw new Error(errno + " cannot write to IPC channel."); |
|
|
|