transports: disables the Nagle algorithm, enable keep-alive functionality of tcp

This commit is contained in:
Micooz 2018-07-01 17:36:32 +08:00
parent e850b20b4b
commit 09937f33e5

@ -30,6 +30,8 @@ export class TcpInbound extends Inbound {
this._socket.on('timeout', this.onTimeout);
this._socket.on('end', this.onHalfClose);
this._socket.on('close', this.onClose);
this._socket.setNoDelay(true);
this._socket.setKeepAlive(true);
this._socket.setTimeout && this._socket.setTimeout(this._config.timeout);
}
@ -299,6 +301,8 @@ export class TcpOutbound extends Outbound {
this._socket.on('timeout', this.onTimeout);
this._socket.on('data', this.onReceive);
this._socket.on('drain', this.onDrain);
this._socket.setNoDelay(true);
this._socket.setKeepAlive(true);
this._socket.setTimeout(this._config.timeout);
} catch (err) {
logger.error(`[${this.name}] [${this.remote}] cannot connect to ${targetHost}:${targetPort}, ${err.message}`);