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

Side by Side Diff: runtime/bin/socket_patch.dart

Issue 13680002: StreamConsumer has an addStream and a close functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update comments. Created 7 years, 8 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 | « pkg/http/test/safe_http_server.dart ('k') | sdk/lib/async/stream.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 patch class RawServerSocket { 5 patch class RawServerSocket {
6 /* patch */ static Future<RawServerSocket> bind([String address = "127.0.0.1", 6 /* patch */ static Future<RawServerSocket> bind([String address = "127.0.0.1",
7 int port = 0, 7 int port = 0,
8 int backlog = 0]) { 8 int backlog = 0]) {
9 return _RawServerSocket.bind(address, port, backlog); 9 return _RawServerSocket.bind(address, port, backlog);
10 } 10 }
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 socket._consumerDone(error); 682 socket._consumerDone(error);
683 }, 683 },
684 onDone: () { 684 onDone: () {
685 socket._consumerDone(); 685 socket._consumerDone();
686 }, 686 },
687 unsubscribeOnError: true); 687 unsubscribeOnError: true);
688 } 688 }
689 return socket._doneFuture; 689 return socket._doneFuture;
690 } 690 }
691 691
692 Future<Socket> addStream(Stream<List<int>> stream) {
693 Completer completer = new Completer<Socket>();
694 if (socket._raw != null) {
695 subscription = stream.listen(
696 (data) {
697 assert(!paused);
698 assert(buffer == null);
699 buffer = data;
700 offset = 0;
701 write();
702 },
703 onError: (error) {
704 socket._consumerDone(error);
705 completer.completeError(error.error, error.stackTrace);
706 },
707 onDone: () {
708 completer.complete(socket);
709 },
710 unsubscribeOnError: true);
711 }
712 return completer.future;
713 }
714
715 Future<Socket> close() {
716 socket._consumerDone();
717 return completer.future;
718 }
719
692 void write() { 720 void write() {
693 try { 721 try {
694 if (subscription == null) return; 722 if (subscription == null) return;
695 assert(buffer != null); 723 assert(buffer != null);
696 // Write as much as possible. 724 // Write as much as possible.
697 offset += socket._write(buffer, offset, buffer.length - offset); 725 offset += socket._write(buffer, offset, buffer.length - offset);
698 if (offset < buffer.length) { 726 if (offset < buffer.length) {
699 if (!paused) { 727 if (!paused) {
700 paused = true; 728 paused = true;
701 // TODO(ajohnsen): It would be nice to avoid this check. 729 // TODO(ajohnsen): It would be nice to avoid this check.
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 _raw.onBadCertificate = callback; 973 _raw.onBadCertificate = callback;
946 } 974 }
947 975
948 X509Certificate get peerCertificate { 976 X509Certificate get peerCertificate {
949 if (_raw == null) { 977 if (_raw == null) {
950 throw new StateError("peerCertificate called on destroyed SecureSocket"); 978 throw new StateError("peerCertificate called on destroyed SecureSocket");
951 } 979 }
952 return _raw.peerCertificate; 980 return _raw.peerCertificate;
953 } 981 }
954 } 982 }
OLDNEW
« no previous file with comments | « pkg/http/test/safe_http_server.dart ('k') | sdk/lib/async/stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698