OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; | 7 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; |
8 | 8 |
9 class _WebSocketMessageType { | 9 class _WebSocketMessageType { |
10 static const int NONE = 0; | 10 static const int NONE = 0; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 179 |
180 if (_remainingPayloadBytes == 0) { | 180 if (_remainingPayloadBytes == 0) { |
181 _controlFrameEnd(sink); | 181 _controlFrameEnd(sink); |
182 } | 182 } |
183 } else { | 183 } else { |
184 switch (_currentMessageType) { | 184 switch (_currentMessageType) { |
185 case _WebSocketMessageType.NONE: | 185 case _WebSocketMessageType.NONE: |
186 throw new WebSocketException("Protocol error"); | 186 throw new WebSocketException("Protocol error"); |
187 | 187 |
188 case _WebSocketMessageType.TEXT: | 188 case _WebSocketMessageType.TEXT: |
189 _buffer.add(_decodeString(buffer.getRange(index, payload))); | 189 _buffer.write(_decodeString(buffer.getRange(index, payload))); |
190 index += payload; | 190 index += payload; |
191 if (_remainingPayloadBytes == 0) { | 191 if (_remainingPayloadBytes == 0) { |
192 _messageFrameEnd(sink); | 192 _messageFrameEnd(sink); |
193 } | 193 } |
194 break; | 194 break; |
195 | 195 |
196 case _WebSocketMessageType.BINARY: | 196 case _WebSocketMessageType.BINARY: |
197 _buffer.add(buffer.getRange(index, payload)); | 197 _buffer.write(buffer.getRange(index, payload)); |
198 index += payload; | 198 index += payload; |
199 if (_remainingPayloadBytes == 0) { | 199 if (_remainingPayloadBytes == 0) { |
200 _messageFrameEnd(sink); | 200 _messageFrameEnd(sink); |
201 } | 201 } |
202 break; | 202 break; |
203 | 203 |
204 default: | 204 default: |
205 throw new WebSocketException("Protocol error"); | 205 throw new WebSocketException("Protocol error"); |
206 } | 206 } |
207 } | 207 } |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 if (data != null) { | 663 if (data != null) { |
664 _socket.add(data); | 664 _socket.add(data); |
665 } | 665 } |
666 } catch (_) { | 666 } catch (_) { |
667 // The socket can be closed before _socket.done have a chance | 667 // The socket can be closed before _socket.done have a chance |
668 // to complete. | 668 // to complete. |
669 _writeClosed = true; | 669 _writeClosed = true; |
670 } | 670 } |
671 } | 671 } |
672 } | 672 } |
OLD | NEW |