Skip to content

Commit

Permalink
dgram: hide _healthCheck() and _stopReceiving()
Browse files Browse the repository at this point in the history
These methods are private APIs of dgram sockets, but do not
need to be exposed via the Socket prototype.

PR-URL: #21923
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Wyatt Preul <wpreul@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
cjihrig authored and targos committed Jul 31, 2018
1 parent e0336b2 commit b5b7438
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function bufferSize(self, size, buffer) {
Socket.prototype.bind = function(port_, address_ /* , callback */) {
let port = port_;

this._healthCheck();
healthCheck(this);

if (this._bindState !== BIND_STATE_UNBOUND)
throw new ERR_SOCKET_ALREADY_BOUND();
Expand Down Expand Up @@ -444,7 +444,7 @@ Socket.prototype.send = function(buffer,
throw new ERR_INVALID_ARG_TYPE('address', ['string', 'falsy'], address);
}

this._healthCheck();
healthCheck(this);

if (this._bindState === BIND_STATE_UNBOUND)
this.bind({ port: 0, exclusive: true }, null);
Expand Down Expand Up @@ -525,8 +525,8 @@ Socket.prototype.close = function(callback) {
return this;
}

this._healthCheck();
this._stopReceiving();
healthCheck(this);
stopReceiving(this);
this._handle.close();
this._handle = null;
defaultTriggerAsyncIdScope(this[async_id_symbol],
Expand All @@ -544,7 +544,7 @@ function socketCloseNT(self) {


Socket.prototype.address = function() {
this._healthCheck();
healthCheck(this);

var out = {};
var err = this._handle.getsockname(out);
Expand Down Expand Up @@ -603,7 +603,7 @@ Socket.prototype.setMulticastLoopback = function(arg) {


Socket.prototype.setMulticastInterface = function(interfaceAddress) {
this._healthCheck();
healthCheck(this);

if (typeof interfaceAddress !== 'string') {
throw new ERR_INVALID_ARG_TYPE(
Expand All @@ -618,7 +618,7 @@ Socket.prototype.setMulticastInterface = function(interfaceAddress) {

Socket.prototype.addMembership = function(multicastAddress,
interfaceAddress) {
this._healthCheck();
healthCheck(this);

if (!multicastAddress) {
throw new ERR_MISSING_ARGS('multicastAddress');
Expand All @@ -633,7 +633,7 @@ Socket.prototype.addMembership = function(multicastAddress,

Socket.prototype.dropMembership = function(multicastAddress,
interfaceAddress) {
this._healthCheck();
healthCheck(this);

if (!multicastAddress) {
throw new ERR_MISSING_ARGS('multicastAddress');
Expand All @@ -646,22 +646,22 @@ Socket.prototype.dropMembership = function(multicastAddress,
};


Socket.prototype._healthCheck = function() {
if (!this._handle) {
function healthCheck(socket) {
if (!socket._handle) {
// Error message from dgram_legacy.js.
throw new ERR_SOCKET_DGRAM_NOT_RUNNING();
}
};
}


Socket.prototype._stopReceiving = function() {
if (!this._receiving)
function stopReceiving(socket) {
if (!socket._receiving)
return;

this._handle.recvStop();
this._receiving = false;
this.fd = null; // compatibility hack
};
socket._handle.recvStop();
socket._receiving = false;
socket.fd = null; // compatibility hack
}


function onMessage(nread, handle, buf, rinfo) {
Expand Down

0 comments on commit b5b7438

Please sign in to comment.