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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } | 270 } |
271 } | 271 } |
272 | 272 |
273 void _messageFrameEnd(EventSink sink) { | 273 void _messageFrameEnd(EventSink sink) { |
274 if (_fin) { | 274 if (_fin) { |
275 switch (_currentMessageType) { | 275 switch (_currentMessageType) { |
276 case _WebSocketMessageType.TEXT: | 276 case _WebSocketMessageType.TEXT: |
277 sink.add(_buffer.toString()); | 277 sink.add(_buffer.toString()); |
278 break; | 278 break; |
279 case _WebSocketMessageType.BINARY: | 279 case _WebSocketMessageType.BINARY: |
280 if (_buffer.length == 0) { | 280 sink.add(_buffer.readBytes()); |
281 sink.add(const []); | |
282 } else { | |
283 sink.add(_buffer.readBytes(_buffer.length)); | |
284 } | |
285 break; | 281 break; |
286 } | 282 } |
287 _buffer = null; | 283 _buffer = null; |
288 _currentMessageType = _WebSocketMessageType.NONE; | 284 _currentMessageType = _WebSocketMessageType.NONE; |
289 } | 285 } |
290 _prepareForNextFrame(); | 286 _prepareForNextFrame(); |
291 } | 287 } |
292 | 288 |
293 void _controlFrameEnd(EventSink sink) { | 289 void _controlFrameEnd(EventSink sink) { |
294 switch (_opcode) { | 290 switch (_opcode) { |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 code == WebSocketStatus.RESERVED_1015) { | 740 code == WebSocketStatus.RESERVED_1015) { |
745 throw new WebSocketException("Reserved status code $code"); | 741 throw new WebSocketException("Reserved status code $code"); |
746 } | 742 } |
747 _outCloseCode = code; | 743 _outCloseCode = code; |
748 _outCloseReason = reason; | 744 _outCloseReason = reason; |
749 _writeClosed = true; | 745 _writeClosed = true; |
750 } | 746 } |
751 return _sink.close(); | 747 return _sink.close(); |
752 } | 748 } |
753 } | 749 } |
OLD | NEW |