Permalink
Browse files

switchProtocols without upgradeHead.

  • Loading branch information...
1 parent 54630ee commit 0ca0d2018a1f17da31399b10c2d2231435a87122 @stephank committed Apr 4, 2012
Showing with 6 additions and 10 deletions.
  1. +6 −10 lib/faye/websocket.js
View
@@ -52,27 +52,23 @@ var WebSocket = function(request, response, supportedProtos, options) {
this.protocol = self._parser.protocol || '';
this.version = self._parser.getVersion();
- response.switchProtocols(function(socket, head) {
+ response.switchProtocols(function(socket) {
self._stream = socket;
self._stream.setTimeout(0);
self._stream.setNoDelay(true);
- var dataListener = function(data) {
+ self._stream.addListener('data', function(data) {
var reply = self._parser.parse(data);
if (!reply) return;
try { self._stream.write(reply, 'binary') } catch (e) {}
self._open();
- };
- self._stream.addListener('data', dataListener);
-
- var closeListener = function() {
- self.close(1006, '', false);
- };
+ });
['close', 'end', 'error'].forEach(function(event) {
- self._stream.addListener(event, closeListener);
+ self._stream.addListener(event, function() {
+ self.close(1006, '', false);
+ });
});
- if (head.length !== 0) dataListener(head);
if (self._parser.isOpen()) self.readyState = API.OPEN;
process.nextTick(function() { self._open() });

0 comments on commit 0ca0d20

Please sign in to comment.