Skip to content

Commit

Permalink
Added Socket.process method.
Browse files Browse the repository at this point in the history
  • Loading branch information
reklatsmasters committed Feb 13, 2018
1 parent 65489c2 commit ba804eb
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions lib/socket.js
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}

/**
Expand Down

0 comments on commit ba804eb

Please sign in to comment.