Chromium Code Reviews| Index: runtime/bin/websocket_impl.dart |
| diff --git a/runtime/bin/websocket_impl.dart b/runtime/bin/websocket_impl.dart |
| index 0eaecbb6219e02abd8ac373f9c32565a6273ebe6..12e8e3f8598759a9de03aa83345648d5ba3f6d5b 100644 |
| --- a/runtime/bin/websocket_impl.dart |
| +++ b/runtime/bin/websocket_impl.dart |
| @@ -63,10 +63,10 @@ class _WebSocketProtocolProcessor { |
| int index = offset; |
| int lastIndex = offset + count; |
| try { |
| - if (_state == _State.CLOSED) { |
| + if (_state == CLOSED) { |
| throw new WebSocketException("Data on closed connection"); |
| } |
| - if (_state == _State.FAILURE) { |
| + if (_state == FAILURE) { |
| throw new WebSocketException("Data on failed connection"); |
| } |
| while ((index < lastIndex) && _state != CLOSED && _state != FAILURE) { |
| @@ -130,11 +130,13 @@ class _WebSocketProtocolProcessor { |
| if (_len < 126) { |
| _lengthDone(); |
| } else if (_len == 126) { |
| - _ len = 0; |
| + _len = 0; |
| _remainingLenBytes = 2; |
| + _state = LEN_REST; |
| } else if (_len == 127) { |
| - _ len = 0; |
| + _len = 0; |
| _remainingLenBytes = 8; |
| + _state = LEN_REST; |
| } |
| break; |
| @@ -157,7 +159,7 @@ class _WebSocketProtocolProcessor { |
| case PAYLOAD: |
| // The payload is not handled one byte at the time but in blocks. |
| int payload; |
| - if (lastIndex - index >= _remainingPayloadBytes) { |
| + if (lastIndex - index <= _remainingPayloadBytes) { |
| payload = lastIndex - index; |
| } else { |
| payload = _remainingPayloadBytes; |
| @@ -184,8 +186,8 @@ class _WebSocketProtocolProcessor { |
| } |
| _remainingPayloadBytes -= payload; |
| index += payload; |
| - if (_fin) { |
| - _messageEnd(); |
| + if (_remainingPayloadBytes == 0) { |
| + _frameEnd(); |
| } |
| break; |
| @@ -267,24 +269,26 @@ class _WebSocketProtocolProcessor { |
| } |
| void _startPayload() { |
| - // Check whether there is any payload. If not indicate empty message or |
| + // Check whether there is any payload. If not indicate empty message or |
|
Mads Ager (google)
2012/04/25 10:47:46
Finish comment. :)
Søren Gjesse
2012/04/27 11:58:24
Done.
|
| if (_remainingPayloadBytes == 0) { |
| if (_currentMessageType ==_WebSocketMessageType.CLOSE) { |
| if (onClosed != null) onClosed(null, null); |
| } else { |
| - _messageEnd(); |
| + _frameEnd(); |
| } |
| } else { |
| _state = PAYLOAD; |
| } |
| } |
| - void _messageEnd() { |
| + void _frameEnd() { |
| if (_remainingPayloadBytes != 0) { |
| throw new WebSocketException("Protocol error"); |
| } |
| - if (onMessageEnd != null) onMessageEnd(); |
| - _currentMessageType = _WebSocketMessageType.NONE; |
| + if (_fin) { |
| + if (onMessageEnd != null) onMessageEnd(); |
| + _currentMessageType = _WebSocketMessageType.NONE; |
| + } |
| _reset(); |
| } |
| @@ -306,7 +310,7 @@ class _WebSocketProtocolProcessor { |
| // throw the error. |
| if (onError != null) { |
| onError(e); |
| - _state = _State.FAILURE; |
| + _state = FAILURE; |
| } else { |
| throw e; |
| } |