server: remove buffering from handleSocket

This commit is contained in:
Guillermo Rauch
2012-08-26 18:13:49 -07:00
parent d1cbdfff77
commit 79af5e17cc

View File

@@ -271,29 +271,16 @@ Server.prototype.onWebSocket = function(req, socket){
var policy = readFileSync(__dirname + '/transports/flashsocket.xml');
Server.prototype.handleSocket = function (socket) {
var chunks = ''
, buffer = false
socket.on('data', function onData (data) {
if (!buffer && 60 == data[0]) {
buffer = true;
} else {
socket.removeListener('data', onData);
return;
}
if (chunks.length < 23) {
chunks += data.toString('ascii');
}
if (chunks.length >= 23) {
if ('<policy-file-request/>\0' == chunks.substr(0, 23)) {
Server.prototype.handleSocket = function(socket){
socket.on('data', function onData(data){
// no need for buffering as node will discard subsequent packets
// since they constitute a malformed HTTP request
if (60 == data[0] && 23 == data.length) {
var str = data.slice(0, 23).toString();
if ('<policy-file-request/>\0' == str) {
socket.end(policy);
} else {
chunks = null;
socket.removeListener('data', onData);
}
}
socket.removeListener('data', onData);
});
};