node-mbed-dtls
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -0,1 +1,5 @@ | ||
# 1.2.1 | ||
* Allow sockets a chance to send closing alerts on server close | ||
# 1.2.0 | ||
@@ -2,0 +6,0 @@ |
{ | ||
"name": "node-mbed-dtls", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Node mbed DTLS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -25,3 +25,3 @@ 'use strict'; | ||
this.emit('error', err); | ||
this.close(); | ||
this._closeSocket(); | ||
}); | ||
@@ -46,3 +46,4 @@ this.dgramSocket.once('close', () => { | ||
} | ||
this.dgramSocket.close(); | ||
this._closing = true; | ||
this._endSockets(); | ||
} | ||
@@ -83,2 +84,5 @@ | ||
client = null; | ||
if (this._closing && Object.keys(this.sockets).length === 0) { | ||
this._closeSocket(); | ||
} | ||
}); | ||
@@ -92,3 +96,3 @@ | ||
_close() { | ||
_endSockets() { | ||
this.dgramSocket.removeListener('message', this._onMessage); | ||
@@ -98,5 +102,9 @@ Object.keys(this.sockets).forEach(skey => { | ||
if (s) { | ||
s.close(); | ||
s.end(); | ||
} | ||
}); | ||
} | ||
_close() { | ||
this._endSockets(); | ||
this.sockets = {}; | ||
@@ -107,2 +115,6 @@ | ||
} | ||
_closeSocket() { | ||
this.dgramSocket.close(); | ||
} | ||
} | ||
@@ -109,0 +121,0 @@ |
@@ -16,2 +16,3 @@ 'use strict'; | ||
this.remotePort = port; | ||
this._hadError = false; | ||
const key = `${address}:${port}`; | ||
@@ -51,5 +52,14 @@ | ||
if (!this.dgramSocket || !this.dgramSocket._handle) { | ||
if (this._clientEnd) { | ||
process.nextTick(() => { | ||
this._finishEnd(); | ||
}); | ||
} | ||
return; | ||
} | ||
this.dgramSocket.send(msg, 0, msg.length, this.remotePort, this.remoteAddress); | ||
this.dgramSocket.send(msg, 0, msg.length, this.remotePort, this.remoteAddress, () => { | ||
if (this._clientEnd) { | ||
this._finishEnd(); | ||
} | ||
}); | ||
} | ||
@@ -64,8 +74,9 @@ | ||
if (code === MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) { | ||
this.close(); | ||
this._end(); | ||
return; | ||
} | ||
this._hadError = true; | ||
this.emit('error', code, msg); | ||
this.close(); | ||
this._end(); | ||
} | ||
@@ -82,3 +93,3 @@ | ||
if (err) { | ||
this.close(); | ||
this._end(); | ||
return; | ||
@@ -101,3 +112,3 @@ } | ||
if (err) { | ||
this.close(); | ||
this._end(); | ||
return; | ||
@@ -119,9 +130,21 @@ } | ||
close() { | ||
end() { | ||
this._clientEnd = true; | ||
this._end(); | ||
} | ||
_end() { | ||
super.end(); | ||
this.push(null); | ||
this.mbedSocket.close(); | ||
this.mbedSocket = null; | ||
if (!this._clientEnd) { | ||
this._finishEnd(); | ||
} | ||
} | ||
_finishEnd() { | ||
this.dgramSocket = null; | ||
this.server = null; | ||
this.emit('close'); | ||
this.emit('close', this._hadError); | ||
this.removeAllListeners(); | ||
@@ -128,0 +151,0 @@ } |
8714653
360