Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: sdk/lib/io/websocket_impl.dart

Issue 22872012: Remove Encoding-enum from dart:io and add interface in dart:convert. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typo. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/string_transformer.dart ('k') | tests/lib/convert/encoding_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 456 }
457 if (message is _WebSocketPing) { 457 if (message is _WebSocketPing) {
458 addFrame(_WebSocketOpcode.PING, message.payload, sink); 458 addFrame(_WebSocketOpcode.PING, message.payload, sink);
459 return; 459 return;
460 } 460 }
461 List<int> data; 461 List<int> data;
462 int opcode; 462 int opcode;
463 if (message != null) { 463 if (message != null) {
464 if (message is String) { 464 if (message is String) {
465 opcode = _WebSocketOpcode.TEXT; 465 opcode = _WebSocketOpcode.TEXT;
466 data = _encodeString(message); 466 data = UTF8.encode(message);
467 } else { 467 } else {
468 if (message is !List<int>) { 468 if (message is !List<int>) {
469 throw new ArgumentError(message); 469 throw new ArgumentError(message);
470 } 470 }
471 opcode = _WebSocketOpcode.BINARY; 471 opcode = _WebSocketOpcode.BINARY;
472 data = message; 472 data = message;
473 } 473 }
474 } else { 474 } else {
475 opcode = _WebSocketOpcode.TEXT; 475 opcode = _WebSocketOpcode.TEXT;
476 } 476 }
477 addFrame(opcode, data, sink); 477 addFrame(opcode, data, sink);
478 } 478 }
479 479
480 void handleDone(EventSink<List<int>> sink) { 480 void handleDone(EventSink<List<int>> sink) {
481 int code = webSocket._outCloseCode; 481 int code = webSocket._outCloseCode;
482 String reason = webSocket._outCloseReason; 482 String reason = webSocket._outCloseReason;
483 List<int> data; 483 List<int> data;
484 if (code != null) { 484 if (code != null) {
485 data = new List<int>(); 485 data = new List<int>();
486 data.add((code >> 8) & 0xFF); 486 data.add((code >> 8) & 0xFF);
487 data.add(code & 0xFF); 487 data.add(code & 0xFF);
488 if (reason != null) { 488 if (reason != null) {
489 data.addAll(_encodeString(reason)); 489 data.addAll(UTF8.encode(reason));
490 } 490 }
491 } 491 }
492 addFrame(_WebSocketOpcode.CLOSE, data, sink); 492 addFrame(_WebSocketOpcode.CLOSE, data, sink);
493 sink.close(); 493 sink.close();
494 } 494 }
495 495
496 void addFrame(int opcode, List<int> data, EventSink<List<int>> sink) { 496 void addFrame(int opcode, List<int> data, EventSink<List<int>> sink) {
497 createFrame(opcode, data, webSocket._serverSide).forEach(sink.add); 497 createFrame(opcode, data, webSocket._serverSide).forEach(sink.add);
498 } 498 }
499 499
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 (code < WebSocketStatus.NORMAL_CLOSURE || 874 (code < WebSocketStatus.NORMAL_CLOSURE ||
875 code == WebSocketStatus.RESERVED_1004 || 875 code == WebSocketStatus.RESERVED_1004 ||
876 code == WebSocketStatus.NO_STATUS_RECEIVED || 876 code == WebSocketStatus.NO_STATUS_RECEIVED ||
877 code == WebSocketStatus.ABNORMAL_CLOSURE || 877 code == WebSocketStatus.ABNORMAL_CLOSURE ||
878 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && 878 (code > WebSocketStatus.INTERNAL_SERVER_ERROR &&
879 code < WebSocketStatus.RESERVED_1015) || 879 code < WebSocketStatus.RESERVED_1015) ||
880 (code >= WebSocketStatus.RESERVED_1015 && 880 (code >= WebSocketStatus.RESERVED_1015 &&
881 code < 3000)); 881 code < 3000));
882 } 882 }
883 } 883 }
OLDNEW
« no previous file with comments | « sdk/lib/io/string_transformer.dart ('k') | tests/lib/convert/encoding_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698