|
|
@ -237,25 +237,26 @@ class Request { |
|
|
|
reply (value, opts = {}) { |
|
|
|
const socket = opts.socket || this.socket |
|
|
|
const to = opts.to || this.from |
|
|
|
this._sendReply(0, value || null, opts.token !== false, this.target !== null && opts.closerNodes !== false, to, socket) |
|
|
|
this._sendReply(0, value || null, opts.token !== false, opts.closerNodes !== false, to, socket) |
|
|
|
} |
|
|
|
|
|
|
|
error (code, opts = {}) { |
|
|
|
const socket = opts.socket || this.socket |
|
|
|
const to = opts.to || this.from |
|
|
|
this._sendReply(code, null, opts.token === true, this.target !== null && opts.closerNodes !== false, to, socket) |
|
|
|
this._sendReply(code, null, opts.token === true, opts.closerNodes !== false, to, socket) |
|
|
|
} |
|
|
|
|
|
|
|
relay (value, to) { |
|
|
|
const buffer = this._encodeRequest(null, value) |
|
|
|
this.socket.send(buffer, 0, buffer.byteLength, to.port, to.host) |
|
|
|
relay (value, to, opts) { |
|
|
|
const socket = (opts && opts.socket) || this.socket |
|
|
|
const buffer = this._encodeRequest(null, value, socket) |
|
|
|
socket.send(buffer, 0, buffer.byteLength, to.port, to.host) |
|
|
|
} |
|
|
|
|
|
|
|
send (force = false) { |
|
|
|
if (this.destroyed) return |
|
|
|
|
|
|
|
if (this.socket === null) return |
|
|
|
if (this._buffer === null) this._buffer = this._encodeRequest(this.token, this.value) |
|
|
|
if (this._buffer === null) this._buffer = this._encodeRequest(this.token, this.value, this.socket) |
|
|
|
|
|
|
|
if (!force && this._io.congestion.isFull()) { |
|
|
|
this._io._pending.push(this) |
|
|
@ -295,7 +296,7 @@ class Request { |
|
|
|
if (socket === null || this.destroyed) return |
|
|
|
|
|
|
|
const id = this._io.ephemeral === false && socket === this._io.serverSocket |
|
|
|
const closerNodes = hasCloserNodes ? this._io.table.closest(this.target) : EMPTY_ARRAY |
|
|
|
const closerNodes = (this.target !== null && hasCloserNodes) ? this._io.table.closest(this.target) : EMPTY_ARRAY |
|
|
|
const state = { start: 0, end: 1 + 1 + 6 + 2, buffer: null } // (type | version) + flags + to + tid
|
|
|
|
|
|
|
|
if (id) state.end += 32 |
|
|
@ -320,8 +321,8 @@ class Request { |
|
|
|
socket.send(state.buffer, 0, state.buffer.byteLength, from.port, from.host) |
|
|
|
} |
|
|
|
|
|
|
|
_encodeRequest (token, value) { |
|
|
|
const id = this._io.ephemeral === false && this.socket === this._io.serverSocket |
|
|
|
_encodeRequest (token, value, socket) { |
|
|
|
const id = this._io.ephemeral === false && socket === this._io.serverSocket |
|
|
|
const state = { start: 0, end: 1 + 1 + 6 + 2, buffer: null } // (type | version) + flags + to + tid
|
|
|
|
|
|
|
|
if (id) state.end += 32 |
|
|
|