summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndreas Madsen <amwebdk@gmail.com>2013-02-27 19:31:24 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2013-03-07 17:51:17 +0100
commitbdf7ac2c5dcdbb59d9a4db7e8eaa66462b1bed26 (patch)
tree6f60145995a6f6be0121658ce355d0addc6bf0df /lib
parent71694361f97035555a269625f68cfbd06effe58a (diff)
downloadandroid-node-v8-bdf7ac2c5dcdbb59d9a4db7e8eaa66462b1bed26.tar.gz
android-node-v8-bdf7ac2c5dcdbb59d9a4db7e8eaa66462b1bed26.tar.bz2
android-node-v8-bdf7ac2c5dcdbb59d9a4db7e8eaa66462b1bed26.zip
child_process: support sending dgram socket
child.send can send net servers and sockets. Now that we have support for dgram clusters this functionality should be extended to include dgram sockets.
Diffstat (limited to 'lib')
-rw-r--r--lib/child_process.js21
-rw-r--r--lib/dgram.js39
2 files changed, 47 insertions, 13 deletions
diff --git a/lib/child_process.js b/lib/child_process.js
index a4a5d2b3a9..80735d4d0c 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -21,6 +21,7 @@
var EventEmitter = require('events').EventEmitter;
var net = require('net');
+var dgram = require('dgram');
var Process = process.binding('process_wrap').Process;
var util = require('util');
var constants; // if (!constants) constants = process.binding('constants');
@@ -167,6 +168,24 @@ var handleConversion = {
got: function(message, handle, emit) {
emit(handle);
}
+ },
+
+ 'dgram.Socket': {
+ simultaneousAccepts: false,
+
+ send: function(message, socket) {
+ message.dgramType = socket.type;
+
+ return socket._handle;
+ },
+
+ got: function(message, handle, emit) {
+ var socket = new dgram.Socket(message.dgramType);
+
+ socket.bind(handle, function() {
+ emit(socket);
+ });
+ }
}
};
@@ -377,6 +396,8 @@ function setupChannel(target, channel) {
} else if (handle instanceof process.binding('tcp_wrap').TCP ||
handle instanceof process.binding('pipe_wrap').Pipe) {
message.type = 'net.Native';
+ } else if (handle instanceof dgram.Socket) {
+ message.type = 'dgram.Socket';
} else if (handle instanceof process.binding('udp_wrap').UDP) {
message.type = 'dgram.Native';
} else {
diff --git a/lib/dgram.js b/lib/dgram.js
index 91c2243681..e13f066710 100644
--- a/lib/dgram.js
+++ b/lib/dgram.js
@@ -141,8 +141,20 @@ function startListening(socket) {
socket.emit('listening');
}
+function replaceHandle(self, newHandle) {
-Socket.prototype.bind = function(port, address, callback) {
+ // Set up the handle that we got from master.
+ newHandle.lookup = self._handle.lookup;
+ newHandle.bind = self._handle.bind;
+ newHandle.send = self._handle.send;
+ newHandle.owner = self;
+
+ // Replace the existing handle by the handle we got from master.
+ self._handle.close();
+ self._handle = newHandle;
+}
+
+Socket.prototype.bind = function(/*port, address, callback*/) {
var self = this;
self._healthCheck();
@@ -152,8 +164,18 @@ Socket.prototype.bind = function(port, address, callback) {
this._bindState = BIND_STATE_BINDING;
- if (typeof callback === 'function')
- self.once('listening', callback);
+ if (typeof arguments[arguments.length - 1] === 'function')
+ self.once('listening', arguments[arguments.length - 1]);
+
+ var UDP = process.binding('udp_wrap').UDP;
+ if (arguments[0] instanceof UDP) {
+ replaceHandle(self, arguments[0]);
+ startListening(self);
+ return;
+ }
+
+ var port = arguments[0];
+ var address = arguments[1];
// resolve address first
self._handle.lookup(address, function(err, ip) {
@@ -172,16 +194,7 @@ Socket.prototype.bind = function(port, address, callback) {
// handle has been closed in the mean time.
return handle.close();
- // Set up the handle that we got from master.
- handle.lookup = self._handle.lookup;
- handle.bind = self._handle.bind;
- handle.send = self._handle.send;
- handle.owner = self;
-
- // Replace the existing handle by the handle we got from master.
- self._handle.close();
- self._handle = handle;
-
+ replaceHandle(self, handle);
startListening(self);
});