Revert "Revert "Fixed packet send callback design issue""

This reverts commit ead08d6e5b.
This commit is contained in:
roam
2013-01-15 17:17:47 +08:00
parent ead08d6e5b
commit 41ee77e3c6
3 changed files with 28 additions and 3 deletions

View File

@@ -247,6 +247,13 @@ Socket.prototype.setupSendCallback = function () {
if ('function' == typeof seqFn) {
debug('executing send callback');
seqFn(self.transport);
} else if (Array.isArray(seqFn)) {
debug('executing batch send callback');
for (var i in seqFn) {
if ('function' == typeof seqFn) {
seqFn[i](self.transport);
}
}
}
}
});
@@ -288,9 +295,8 @@ Socket.prototype.sendPacket = function (type, data, callback) {
this.writeBuffer.push(packet);
//add send callback to object
if (callback) {
this.packetsFn.push(callback);
}
this.packetsFn.push(callback);
this.flush();
}
};
@@ -309,6 +315,9 @@ Socket.prototype.flush = function () {
this.server.emit('flush', this, this.writeBuffer);
var wbuf = this.writeBuffer;
this.writeBuffer = [];
if (!this.transport.supportsFraming) {
this.packetsFn = [this.packetsFn];
}
this.transport.send(wbuf);
this.emit('drain');
this.server.emit('drain', this);

View File

@@ -36,6 +36,14 @@ FlashSocket.prototype.__proto__ = WebSocket.prototype;
FlashSocket.prototype.name = 'flashsocket';
/**
* Advertise framing support.
*
* @api public
*/
FlashSocket.prototype.supportsFraming = true;
/**
* Listens for new configuration changes of the Manager
* this way we can enable and disable the flash server.

View File

@@ -55,6 +55,14 @@ WebSocket.prototype.name = 'websocket';
WebSocket.prototype.handlesUpgrades = true;
/**
* Advertise framing support.
*
* @api public
*/
WebSocket.prototype.supportsFraming = true;
/**
* Processes the incoming data.
*