aboutsummaryrefslogtreecommitdiff
path: root/lib/dgram.js
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/dgram.js
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/dgram.js')
-rw-r--r--lib/dgram.js39
1 files changed, 26 insertions, 13 deletions
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);
});