mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Implemented Socket buffering/flushing:
- Fires upon upgrade - Fires when the transport is drained.
This commit is contained in:
@@ -122,6 +122,7 @@ Socket.prototype.setTransport = function (transport) {
|
||||
this.transport = transport;
|
||||
this.transport.once('error', this.onError.bind(this));
|
||||
this.transport.on('packet', this.onPacket.bind(this));
|
||||
this.transport.on('drain', this.flush.bind(this));
|
||||
this.transport.once('close', this.onClose.bind(this, 'transport close'));
|
||||
};
|
||||
|
||||
@@ -141,6 +142,7 @@ Socket.prototype.upgrade = function (transport) {
|
||||
// therefore we don't worry about the `open` event
|
||||
this.setTransport(transport);
|
||||
this.ping();
|
||||
this.flush();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -196,6 +198,20 @@ Socket.prototype.sendPacket = function (type, data) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Attempts to flush the packets buffer.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.flush = function () {
|
||||
if ('close' != this.readyState && this.transport.writable) {
|
||||
debug('flushing buffer to transport');
|
||||
this.transport.send(this.writeBuffer);
|
||||
this.writeBuffer = [];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Closes the socket and underlying transport.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user