Fix for notification queue stalling.

The 'ondrain' event for a socket isn't called if the entire buffer was flushed during the .write() call. Therefore the queue will stall in these cases. Instead we immediately call the .socketDrained() method to continue queue processing.
This commit is contained in:
Andrew Naylor 2012-06-23 00:22:05 +01:00
Родитель e3c768b65f
Коммит 69dbf09396
1 изменённых файлов: 5 добавлений и 1 удалений

Просмотреть файл

@ -170,9 +170,11 @@ Connection.prototype.connect = function () {
* @private
*/
Connection.prototype.socketDrained = function() {
debug("Socket drained");
if (this.socket && (this.socket.socket.bufferSize != 0 || !this.socket.writable)) {
return;
}
debug("Socket writeable");
if (this.notificationBuffer.length > 0) {
debug("Sending notification from buffer");
this.sendNotification(this.notificationBuffer.shift());
@ -360,7 +362,9 @@ Connection.prototype.sendNotification = function (notification) {
//Payload
position += data.write(message, position, encoding);
this.socket.write(data);
if(this.socket.write(data)) {
this.socketDrained();
}
}.bind(this)).fail(function (error) {
this.raiseError(error, notification);
});