diff --git a/lib/socket.js b/lib/socket.js index 9f8ac53..fbffef8 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -136,6 +136,26 @@ module.exports = class Socket extends Duplex { return true } + /** + * Handle incoming data from another source. + * Dangerous and undocumented method. + * @public + * @param {Buffer} data + */ + process(data) { + if (this[pReadableClosed]) { + return false + } + + if (this[pReadable] && this[pReadQueue].isEmpty()) { + this[pReadable] = this.push(data) + } else { + this[pReadQueue].push(data) + } + + return true + } + close() { if (!this[pSocketClosed] && this[pCloseTransport]) { this[pSocket].close() @@ -167,20 +187,12 @@ function denque(...args) { * @param {object} rinfo */ function handleMessage(message, rinfo) { - if (this[pReadableClosed]) { - return - } - // Drop messages from unknown sender. if (rinfo.address !== this[pRemoteAddress] || rinfo.port !== this[pRemotePort]) { return } - if (this[pReadable] && this[pReadQueue].isEmpty()) { - this[pReadable] = this.push(message) - } else { - this[pReadQueue].push(message) - } + return this.process(message) } /**