Fix DEFLATE for short messages that weren't flushed to socket

This commit is contained in:
Andris Reinman 2017-05-16 13:35:29 +03:00
parent 9c68053987
commit ba2a57e670
2 changed files with 14 additions and 1 deletions

View file

@ -49,7 +49,10 @@ module.exports = {
this.writeStream.unpipe(this._socket);
this._deflate.pipe(this._socket);
let reading = false;
let readNext = () => {
reading = true;
let chunk;
while ((chunk = this.writeStream.read()) !== null) {
if (this._deflate && this._deflate.write(chunk) === false) {
@ -60,8 +63,14 @@ module.exports = {
if (this._deflate) {
this._deflate.flush();
}
reading = false;
};
this.writeStream.on('readable', readNext);
this.writeStream.on('readable', () => {
if (!reading) {
readNext();
}
});
this._socket.unpipe(this._parser);
this._socket.pipe(this._inflate).pipe(this._parser);

View file

@ -126,6 +126,10 @@ class IMAPConnection extends EventEmitter {
send(payload, callback) {
if (this._socket && this._socket.writable) {
this[!this.compression ? '_socket' : '_deflate'].write(payload + '\r\n', 'binary', callback);
if(this.compression){
// make sure we transmit the message immediatelly
this._deflate.flush();
}
this._server.logger.debug({
tnx: 'send',
cid: this.id