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

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

Issue 12330109: dart:io | Fix writing to a Socket while and after calling destroy() on it. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | « no previous file | tests/standalone/standalone.status » ('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 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 class _SocketStreamConsumer extends StreamConsumer<List<int>, Socket> { 651 class _SocketStreamConsumer extends StreamConsumer<List<int>, Socket> {
652 StreamSubscription subscription; 652 StreamSubscription subscription;
653 final _Socket socket; 653 final _Socket socket;
654 int offset; 654 int offset;
655 List<int> buffer; 655 List<int> buffer;
656 bool paused = false; 656 bool paused = false;
657 657
658 _SocketStreamConsumer(this.socket); 658 _SocketStreamConsumer(this.socket);
659 659
660 Future<Socket> consume(Stream<List<int>> stream) { 660 Future<Socket> consume(Stream<List<int>> stream) {
661 subscription = stream.listen( 661 if (socket._raw != null) {
Anders Johnsen 2013/02/25 14:36:37 == null) return socket._doneFuture;, to avoid nest
Bill Hesse 2013/02/25 14:49:23 I just put that nesting in, on purpose, because it
662 (data) { 662 subscription = stream.listen((data) {
663 assert(!paused); 663 assert(!paused);
664 assert(buffer == null); 664 assert(buffer == null);
665 buffer = data; 665 buffer = data;
666 offset = 0; 666 offset = 0;
667 write(); 667 write();
668 }, 668 },
669 onDone: () { 669 onDone: () {
670 socket._consumerDone(); 670 socket._consumerDone();
671 }); 671 });
672 }
672 return socket._doneFuture; 673 return socket._doneFuture;
673 } 674 }
674 675
675 void write() { 676 void write() {
676 try { 677 try {
677 if (subscription == null) return; 678 if (subscription == null) return;
678 assert(buffer != null); 679 assert(buffer != null);
679 // Write as much as possible. 680 // Write as much as possible.
680 offset += socket._write(buffer, offset, buffer.length - offset); 681 offset += socket._write(buffer, offset, buffer.length - offset);
681 if (offset < buffer.length) { 682 if (offset < buffer.length) {
682 if (!paused) { 683 if (!paused) {
683 paused = true; 684 paused = true;
684 // TODO(ajohnsen): It would be nice to avoid this check. 685 // TODO(ajohnsen): It would be nice to avoid this check.
685 // Some info: socket._write can emit an event, if it fails to write. 686 // Some info: socket._write can emit an event, if it fails to write.
686 // If the user closes the socket in that event, stop() will be called 687 // If the user closes the socket in that event, stop() will be called
687 // before we get a change to pause. 688 // before we get a change to pause.
688 if (subscription == null) return; 689 if (subscription == null) return;
689 subscription.pause(); 690 subscription.pause();
690 } 691 }
691 socket._enableWriteEvent(); 692 socket._enableWriteEvent();
692 } else { 693 } else {
693 buffer = null; 694 buffer = null;
694 if (paused) { 695 if (paused) {
695 paused = false; 696 paused = false;
696 subscription.resume(); 697 subscription.resume();
697 } 698 }
698 } 699 }
699 } catch (e) { 700 } catch (e) {
701 stop();
700 socket._consumerDone(e); 702 socket._consumerDone(e);
701 } 703 }
702 } 704 }
703 705
704 void stop() { 706 void stop() {
705 if (subscription == null) return; 707 if (subscription == null) return;
706 subscription.cancel(); 708 subscription.cancel();
707 subscription = null; 709 subscription = null;
708 socket._disableWriteEvent(); 710 socket._disableWriteEvent();
709 } 711 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 _raw.onBadCertificate = callback; 916 _raw.onBadCertificate = callback;
915 } 917 }
916 918
917 X509Certificate get peerCertificate { 919 X509Certificate get peerCertificate {
918 if (_raw == null) { 920 if (_raw == null) {
919 throw new StateError("peerCertificate called on destroyed SecureSocket"); 921 throw new StateError("peerCertificate called on destroyed SecureSocket");
920 } 922 }
921 return _raw.peerCertificate; 923 return _raw.peerCertificate;
922 } 924 }
923 } 925 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698