dgram: hide _healthCheck() and _stopReceiving()
These methods are private APIs of dgram sockets, but do not need to be exposed via the Socket prototype. PR-URL: https://github.com/nodejs/node/pull/21923 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
c4de500c87
commit
d497ebbf9c
34
lib/dgram.js
34
lib/dgram.js
@ -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();
|
||||
@ -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);
|
||||
@ -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],
|
||||
@ -544,7 +544,7 @@ function socketCloseNT(self) {
|
||||
|
||||
|
||||
Socket.prototype.address = function() {
|
||||
this._healthCheck();
|
||||
healthCheck(this);
|
||||
|
||||
var out = {};
|
||||
var err = this._handle.getsockname(out);
|
||||
@ -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(
|
||||
@ -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');
|
||||
@ -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');
|
||||
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user