Browse Source

dgram: remove this aliases

This commit removes self = this style assignments from dgram.

PR-URL: https://github.com/nodejs/node/pull/11243
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
cjihrig 8 years ago
parent
commit
b594b3bc34
  1. 73
      lib/dgram.js

73
lib/dgram.js

@ -132,10 +132,9 @@ function replaceHandle(self, newHandle) {
} }
Socket.prototype.bind = function(port_ /*, address, callback*/) { Socket.prototype.bind = function(port_ /*, address, callback*/) {
var self = this;
let port = port_; let port = port_;
self._healthCheck(); this._healthCheck();
if (this._bindState !== BIND_STATE_UNBOUND) if (this._bindState !== BIND_STATE_UNBOUND)
throw new Error('Socket is already bound'); throw new Error('Socket is already bound');
@ -143,12 +142,12 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {
this._bindState = BIND_STATE_BINDING; this._bindState = BIND_STATE_BINDING;
if (typeof arguments[arguments.length - 1] === 'function') if (typeof arguments[arguments.length - 1] === 'function')
self.once('listening', arguments[arguments.length - 1]); this.once('listening', arguments[arguments.length - 1]);
if (port instanceof UDP) { if (port instanceof UDP) {
replaceHandle(self, port); replaceHandle(this, port);
startListening(self); startListening(this);
return self; return this;
} }
var address; var address;
@ -164,17 +163,17 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {
} }
// defaulting address for bind to all interfaces // defaulting address for bind to all interfaces
if (!address && self._handle.lookup === lookup4) { if (!address && this._handle.lookup === lookup4) {
address = '0.0.0.0'; address = '0.0.0.0';
} else if (!address && self._handle.lookup === lookup6) { } else if (!address && this._handle.lookup === lookup6) {
address = '::'; address = '::';
} }
// resolve address first // resolve address first
self._handle.lookup(address, function(err, ip) { this._handle.lookup(address, (err, ip) => {
if (err) { if (err) {
self._bindState = BIND_STATE_UNBOUND; this._bindState = BIND_STATE_UNBOUND;
self.emit('error', err); this.emit('error', err);
return; return;
} }
@ -182,51 +181,50 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {
cluster = require('cluster'); cluster = require('cluster');
var flags = 0; var flags = 0;
if (self._reuseAddr) if (this._reuseAddr)
flags |= UV_UDP_REUSEADDR; flags |= UV_UDP_REUSEADDR;
if (cluster.isWorker && !exclusive) { if (cluster.isWorker && !exclusive) {
function onHandle(err, handle) { const onHandle = (err, handle) => {
if (err) { if (err) {
var ex = exceptionWithHostPort(err, 'bind', ip, port); var ex = exceptionWithHostPort(err, 'bind', ip, port);
self.emit('error', ex); this.emit('error', ex);
self._bindState = BIND_STATE_UNBOUND; this._bindState = BIND_STATE_UNBOUND;
return; return;
} }
if (!self._handle) if (!this._handle)
// handle has been closed in the mean time. // handle has been closed in the mean time.
return handle.close(); return handle.close();
replaceHandle(self, handle); replaceHandle(this, handle);
startListening(self); startListening(this);
} };
cluster._getServer(self, { cluster._getServer(this, {
address: ip, address: ip,
port: port, port: port,
addressType: self.type, addressType: this.type,
fd: -1, fd: -1,
flags: flags flags: flags
}, onHandle); }, onHandle);
} else { } else {
if (!self._handle) if (!this._handle)
return; // handle has been closed in the mean time return; // handle has been closed in the mean time
const err = self._handle.bind(ip, port || 0, flags); const err = this._handle.bind(ip, port || 0, flags);
if (err) { if (err) {
var ex = exceptionWithHostPort(err, 'bind', ip, port); var ex = exceptionWithHostPort(err, 'bind', ip, port);
self.emit('error', ex); this.emit('error', ex);
self._bindState = BIND_STATE_UNBOUND; this._bindState = BIND_STATE_UNBOUND;
// Todo: close? // Todo: close?
return; return;
} }
startListening(self); startListening(this);
} }
}); });
return self; return this;
}; };
@ -326,7 +324,6 @@ Socket.prototype.send = function(buffer,
port, port,
address, address,
callback) { callback) {
const self = this;
let list; let list;
if (address || (port && typeof port !== 'function')) { if (address || (port && typeof port !== 'function')) {
@ -358,24 +355,26 @@ Socket.prototype.send = function(buffer,
if (typeof callback !== 'function') if (typeof callback !== 'function')
callback = undefined; callback = undefined;
self._healthCheck(); this._healthCheck();
if (self._bindState === BIND_STATE_UNBOUND) if (this._bindState === BIND_STATE_UNBOUND)
self.bind({port: 0, exclusive: true}, null); this.bind({port: 0, exclusive: true}, null);
if (list.length === 0) if (list.length === 0)
list.push(Buffer.alloc(0)); list.push(Buffer.alloc(0));
// If the socket hasn't been bound yet, push the outbound packet onto the // If the socket hasn't been bound yet, push the outbound packet onto the
// send queue and send after binding is complete. // send queue and send after binding is complete.
if (self._bindState !== BIND_STATE_BOUND) { if (this._bindState !== BIND_STATE_BOUND) {
enqueue(self, self.send.bind(self, list, port, address, callback)); enqueue(this, this.send.bind(this, list, port, address, callback));
return; return;
} }
self._handle.lookup(address, function afterDns(ex, ip) { const afterDns = (ex, ip) => {
doSend(ex, self, ip, list, address, port, callback); doSend(ex, this, ip, list, address, port, callback);
}); };
this._handle.lookup(address, afterDns);
}; };

Loading…
Cancel
Save