|
@ -235,11 +235,15 @@ class Request { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
reply (value, opts = {}) { |
|
|
reply (value, opts = {}) { |
|
|
this.sendReply(0, value || null, opts.token !== false, this.target !== null && opts.closerNodes !== false, opts.to || this.from) |
|
|
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) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
error (code, opts = {}) { |
|
|
error (code, opts = {}) { |
|
|
this.sendReply(code, null, opts.token === true, this.target !== null && opts.closerNodes !== false, opts.to || this.from) |
|
|
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) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
relay (value, to) { |
|
|
relay (value, to) { |
|
@ -261,6 +265,10 @@ class Request { |
|
|
this._sendNow() |
|
|
this._sendNow() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sendReply (error, value, token, hasCloserNodes) { |
|
|
|
|
|
this._sendReply(error, value, token, hasCloserNodes, this.from, this.socket) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
_sendNow () { |
|
|
_sendNow () { |
|
|
if (this.destroyed) return |
|
|
if (this.destroyed) return |
|
|
this.sent++ |
|
|
this.sent++ |
|
@ -283,10 +291,10 @@ class Request { |
|
|
this.onerror(err || DESTROY, this) |
|
|
this.onerror(err || DESTROY, this) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
sendReply (error, value, token, hasCloserNodes, from) { |
|
|
_sendReply (error, value, token, hasCloserNodes, from, socket) { |
|
|
if (this.socket === null || this.destroyed) return |
|
|
if (socket === null || this.destroyed) return |
|
|
|
|
|
|
|
|
const id = this._io.ephemeral === false && this.socket === this._io.serverSocket |
|
|
const id = this._io.ephemeral === false && socket === this._io.serverSocket |
|
|
const closerNodes = hasCloserNodes ? this._io.table.closest(this.target) : EMPTY_ARRAY |
|
|
const closerNodes = 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
|
|
|
const state = { start: 0, end: 1 + 1 + 6 + 2, buffer: null } // (type | version) + flags + to + tid
|
|
|
|
|
|
|
|
@ -309,7 +317,7 @@ class Request { |
|
|
if (error > 0) c.uint.encode(state, error) |
|
|
if (error > 0) c.uint.encode(state, error) |
|
|
if (value) c.buffer.encode(state, value) |
|
|
if (value) c.buffer.encode(state, value) |
|
|
|
|
|
|
|
|
this.socket.send(state.buffer, 0, state.buffer.byteLength, from.port, from.host) |
|
|
socket.send(state.buffer, 0, state.buffer.byteLength, from.port, from.host) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_encodeRequest (token, value) { |
|
|
_encodeRequest (token, value) { |
|
|