sofa-rpc-node/lib/server/response.js
2018-05-25 22:13:31 +08:00

43 lines
998 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
class RpcResponse {
constructor(req, connection) {
this.req = req;
this.connection = connection;
this.meta = {
start: Date.now(),
rt: 0,
data: null,
responseEncodeRT: 0,
serviceName: req.data.serverSignature,
interfaceName: req.data.interfaceName,
method: req.data.methodName,
remoteIp: connection.remoteAddress,
reqSize: req.meta && req.meta.size || 0,
resSize: 0,
resultCode: '00', // 00成功01异常03超时04路由失败
};
}
get socket() {
return this.connection.socket;
}
get remoteAddress() {
return this.connection.remoteAddress;
}
get isClosed() {
return this.connection.isClosed;
}
async send(res) {
const packet = await this.connection.send(this.req, res);
this.meta.data = packet.meta.data;
this.meta.resSize = packet.meta.size;
this.meta.responseEncodeRT = packet.meta.encodeRT;
}
}
module.exports = RpcResponse;