use public properties to check if a socket is open or not

This commit is contained in:
Andris Reinman 2021-05-31 16:19:44 +03:00
parent 9c04a286e2
commit 425652d4c0
4 changed files with 4 additions and 10 deletions

View file

@ -203,7 +203,7 @@ class IMAPConnection extends EventEmitter {
* @param {String|Array} data If data is Array, send a multi-line response
*/
send(payload, callback) {
if (this._socket && this._socket.writable) {
if (this._socket && !this._socket.destroyed && this._socket.readyState === 'open') {
try {
this[!this.compression ? '_socket' : '_deflate'].write(payload + '\r\n', 'binary', (...args) => {
if (args[0]) {

View file

@ -744,7 +744,6 @@ module.exports.sendCapabilityResponse = connection => {
capabilities.push('SPECIAL-USE');
capabilities.push('UIDPLUS');
capabilities.push('UNSELECT');
capabilities.push('ENABLE');
capabilities.push('CONDSTORE');
capabilities.push('UTF8=ACCEPT');

View file

@ -70,14 +70,14 @@ class POP3Connection extends EventEmitter {
}
write(payload) {
if (!this._socket || !this._socket.writable) {
if (!this._socket || this._socket.destroyed || this._socket.readyState !== 'open') {
return;
}
this._socket.write(payload);
}
send(payload) {
if (!this._socket || !this._socket.writable) {
if (!this._socket || this._socket.destroyed || this._socket.readyState !== 'open') {
return;
}

View file

@ -459,14 +459,9 @@ function validationErrors(validationResult) {
}
function checkSocket(socket) {
if (!socket || !socket._writableState || !socket._readableState) {
if (!socket || socket.destroyed || socket.readyState !== 'open') {
throw new Error('Socket not open');
}
for (let s of [socket._writableState, socket._readableState]) {
if (s.destroyed || s.errored || s.closed) {
throw new Error('Socket not open');
}
}
}
module.exports = {