transports: add bufferSize getters for h2 and ws

This commit is contained in:
Micooz 2018-07-02 20:05:11 +08:00
parent e96a304659
commit babfa8307a
3 changed files with 24 additions and 12 deletions

@ -34,6 +34,10 @@ export class Http2Inbound extends Inbound {
return 'h2:inbound';
}
get bufferSize() {
return this._session ? this._session.socket.bufferSize : 0;
}
get writable() {
return this._stream && this._stream.writable;
}
@ -104,6 +108,10 @@ export class Http2Outbound extends Outbound {
return 'h2:outbound';
}
get bufferSize() {
return this._session ? this._session.socket.bufferSize : 0;
}
get writable() {
return this._stream && this._stream.writable;
}

@ -69,10 +69,8 @@ export class TcpInbound extends Inbound {
logger.debug(`[${this.name}] [${this.remote}] recv paused due to outbound.bufferSize=${outbound.bufferSize} >= ${MAX_BUFFERED_SIZE}`);
this.pause();
outbound.once('drain', () => {
if (this._socket && !this._socket.destroyed) {
logger.debug(`[${this.name}] [${this.remote}] resume to recv`);
this.resume();
}
logger.debug(`[${this.name}] [${this.remote}] resume to recv`);
this.resume();
});
}
}
@ -101,13 +99,13 @@ export class TcpInbound extends Inbound {
}
pause() {
if (this._socket && typeof this._socket.pause === 'function') {
if (this._socket && !this._socket.destroyed) {
this._socket.pause();
}
}
resume() {
if (this._socket && typeof this._socket.resume === 'function') {
if (this._socket && !this._socket.destroyed) {
this._socket.resume();
}
}
@ -198,10 +196,8 @@ export class TcpOutbound extends Outbound {
logger.debug(`[${this.name}] [${this.remote}] recv paused due to inbound.bufferSize=${inbound.bufferSize} >= ${MAX_BUFFERED_SIZE}`);
this.pause();
inbound.once('drain', () => {
if (this._socket && !this._socket.destroyed) {
logger.debug(`[${this.name}] [${this.remote}] resume to recv`);
this.resume();
}
logger.debug(`[${this.name}] [${this.remote}] resume to recv`);
this.resume();
});
}
}
@ -230,13 +226,13 @@ export class TcpOutbound extends Outbound {
}
pause() {
if (this._socket && typeof this._socket.pause === 'function') {
if (this._socket && !this._socket.destroyed) {
this._socket.pause();
}
}
resume() {
if (this._socket && typeof this._socket.resume === 'function') {
if (this._socket && !this._socket.destroyed) {
this._socket.resume();
}
}

@ -30,6 +30,10 @@ export class WsInbound extends Inbound {
return 'ws:inbound';
}
get bufferSize() {
return this._socket ? this._socket.bufferedAmount : 0;
}
get writable() {
return this._socket && this._socket.readyState === WebSocket.OPEN;
}
@ -88,6 +92,10 @@ export class WsOutbound extends Outbound {
return 'ws:outbound';
}
get bufferSize() {
return this._socket ? this._socket.bufferedAmount : 0;
}
get writable() {
return this._socket && this._socket.readyState === WebSocket.OPEN;
}