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 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 header[index++] = 126; | 664 header[index++] = 126; |
665 lengthBytes = 2; | 665 lengthBytes = 2; |
666 } | 666 } |
667 // Write the length in network byte order into the header. | 667 // Write the length in network byte order into the header. |
668 for (int i = 0; i < lengthBytes; i++) { | 668 for (int i = 0; i < lengthBytes; i++) { |
669 header[index++] = dataLength >> (((lengthBytes - 1) - i) * 8) & 0xFF; | 669 header[index++] = dataLength >> (((lengthBytes - 1) - i) * 8) & 0xFF; |
670 } | 670 } |
671 if (mask) { | 671 if (mask) { |
672 header[1] |= 1 << 7; | 672 header[1] |= 1 << 7; |
673 var maskBytes = _IOCrypto.getRandomBytes(4); | 673 var maskBytes = _IOCrypto.getRandomBytes(4); |
674 header.setRange(index, 4, maskBytes); | 674 header.setRange(index, index + 4, maskBytes); |
675 index += 4; | 675 index += 4; |
676 if (data != null) { | 676 if (data != null) { |
677 var list = new Uint8List(data.length); | 677 var list = new Uint8List(data.length); |
678 for (int i = 0; i < data.length; i++) { | 678 for (int i = 0; i < data.length; i++) { |
679 list[i] = data[i] ^ maskBytes[i % 4]; | 679 list[i] = data[i] ^ maskBytes[i % 4]; |
680 } | 680 } |
681 data = list; | 681 data = list; |
682 } | 682 } |
683 } | 683 } |
684 assert(index == headerSize); | 684 assert(index == headerSize); |
685 try { | 685 try { |
686 _socket.add(header); | 686 _socket.add(header); |
687 if (data != null) { | 687 if (data != null) { |
688 _socket.add(data); | 688 _socket.add(data); |
689 } | 689 } |
690 } catch (_) { | 690 } catch (_) { |
691 // The socket can be closed before _socket.done have a chance | 691 // The socket can be closed before _socket.done have a chance |
692 // to complete. | 692 // to complete. |
693 _writeClosed = true; | 693 _writeClosed = true; |
694 } | 694 } |
695 } | 695 } |
696 } | 696 } |
OLD | NEW |