| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 final String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; | 5 final String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; |
| 6 | 6 |
| 7 class _WebSocketMessageType { | 7 class _WebSocketMessageType { |
| 8 static final int NONE = 0; | 8 static final int NONE = 0; |
| 9 static final int BINARY = 1; | 9 static final int BINARY = 1; |
| 10 static final int TEXT = 2; | 10 static final int TEXT = 2; |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 _socket.close(); | 503 _socket.close(); |
| 504 } | 504 } |
| 505 | 505 |
| 506 _sendFrame(int opcode, List<int> data) { | 506 _sendFrame(int opcode, List<int> data) { |
| 507 bool mask = false; // Masking not implemented for server. | 507 bool mask = false; // Masking not implemented for server. |
| 508 int dataLength = data == null ? 0 : data.length; | 508 int dataLength = data == null ? 0 : data.length; |
| 509 // Determine the header size. | 509 // Determine the header size. |
| 510 int headerSize = (mask) ? 6 : 2; | 510 int headerSize = (mask) ? 6 : 2; |
| 511 if (dataLength > 65535) { | 511 if (dataLength > 65535) { |
| 512 headerSize += 8; | 512 headerSize += 8; |
| 513 } else if (dataLength > 126) { | 513 } else if (dataLength > 125) { |
| 514 headerSize += 2; | 514 headerSize += 2; |
| 515 } | 515 } |
| 516 List<int> header = new List<int>(headerSize); | 516 List<int> header = new List<int>(headerSize); |
| 517 int index = 0; | 517 int index = 0; |
| 518 // Set FIN and opcode. | 518 // Set FIN and opcode. |
| 519 header[index++] = 0x80 | opcode; | 519 header[index++] = 0x80 | opcode; |
| 520 // Determine size and position of length field. | 520 // Determine size and position of length field. |
| 521 int lengthBytes = 1; | 521 int lengthBytes = 1; |
| 522 int firstLengthByte = 1; | 522 int firstLengthByte = 1; |
| 523 if (dataLength > 65535) { | 523 if (dataLength > 65535) { |
| 524 header[index++] = 127; | 524 header[index++] = 127; |
| 525 lengthBytes = 8; | 525 lengthBytes = 8; |
| 526 } else if (dataLength > 126) { | 526 } else if (dataLength > 125) { |
| 527 header[index++] = 126; | 527 header[index++] = 126; |
| 528 lengthBytes = 2; | 528 lengthBytes = 2; |
| 529 } | 529 } |
| 530 // Write the length in network byte order into the header. | 530 // Write the length in network byte order into the header. |
| 531 for (int i = 0; i < lengthBytes; i++) { | 531 for (int i = 0; i < lengthBytes; i++) { |
| 532 header[index++] = dataLength >> (((lengthBytes - 1) - i) * 8) & 0xFF; | 532 header[index++] = dataLength >> (((lengthBytes - 1) - i) * 8) & 0xFF; |
| 533 } | 533 } |
| 534 assert(index == headerSize); | 534 assert(index == headerSize); |
| 535 _socket.outputStream.write(header); | 535 _socket.outputStream.write(header); |
| 536 if (data != null) { | 536 if (data != null) { |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 | 849 |
| 850 class _WebSocketCloseEvent implements CloseEvent { | 850 class _WebSocketCloseEvent implements CloseEvent { |
| 851 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); | 851 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); |
| 852 bool get wasClean() => _wasClean; | 852 bool get wasClean() => _wasClean; |
| 853 int get code() => _code; | 853 int get code() => _code; |
| 854 String get reason() => _reason; | 854 String get reason() => _reason; |
| 855 bool _wasClean; | 855 bool _wasClean; |
| 856 int _code; | 856 int _code; |
| 857 String _reason; | 857 String _reason; |
| 858 } | 858 } |
| OLD | NEW |