Chromium Code Reviews| 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 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 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 offset = 0; | 683 offset = 0; |
| 684 write(); | 684 write(); |
| 685 }, | 685 }, |
| 686 onDone: () { | 686 onDone: () { |
| 687 socket._consumerDone(); | 687 socket._consumerDone(); |
| 688 }); | 688 }); |
| 689 return socket._doneFuture; | 689 return socket._doneFuture; |
| 690 } | 690 } |
| 691 | 691 |
| 692 void write() { | 692 void write() { |
| 693 if (subscription == null) return; | 693 try { |
| 694 assert(buffer != null); | 694 if (subscription == null) return; |
| 695 // Write as much as possible. | 695 assert(buffer != null); |
| 696 offset += socket._write(buffer, offset, buffer.length - offset); | 696 // Write as much as possible. |
| 697 if (offset < buffer.length) { | 697 offset += socket._write(buffer, offset, buffer.length - offset); |
|
Mads Ager (google)
2013/01/31 07:53:30
Accidental indentation change?
Søren Gjesse
2013/01/31 12:12:01
Done.
| |
| 698 if (!paused) { | 698 if (offset < buffer.length) { |
| 699 paused = true; | 699 if (!paused) { |
| 700 // TODO(ajohnsen): It would be nice to avoid this check. | 700 paused = true; |
| 701 // Some info: socket._write can emit an event, if it fails to write. | 701 // TODO(ajohnsen): It would be nice to avoid this check. |
| 702 // If the user closes the socket in that event, stop() will be called | 702 // Some info: socket._write can emit an event, if it fails to write. |
| 703 // before we get a change to pause. | 703 // If the user closes the socket in that event, stop() will be called |
| 704 if (subscription == null) return; | 704 // before we get a change to pause. |
| 705 subscription.pause(); | 705 if (subscription == null) return; |
| 706 subscription.pause(); | |
| 707 } | |
| 708 socket._enableWriteEvent(); | |
| 709 } else { | |
| 710 buffer = null; | |
| 711 if (paused) { | |
| 712 paused = false; | |
| 713 subscription.resume(); | |
| 714 } | |
| 706 } | 715 } |
| 707 socket._enableWriteEvent(); | 716 } catch (e) { |
| 708 } else { | 717 socket._consumerDone(e); |
| 709 buffer = null; | |
| 710 if (paused) { | |
| 711 paused = false; | |
| 712 subscription.resume(); | |
| 713 } | |
| 714 } | 718 } |
| 715 } | 719 } |
| 716 | 720 |
| 717 void stop() { | 721 void stop() { |
| 718 if (subscription == null) return; | 722 if (subscription == null) return; |
| 719 subscription.cancel(); | 723 subscription.cancel(); |
| 720 subscription = null; | 724 subscription = null; |
| 721 socket._disableWriteEvent(); | 725 socket._disableWriteEvent(); |
| 722 } | 726 } |
| 723 } | 727 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 899 void _enableWriteEvent() { | 903 void _enableWriteEvent() { |
| 900 _raw.writeEventsEnabled = true; | 904 _raw.writeEventsEnabled = true; |
| 901 } | 905 } |
| 902 | 906 |
| 903 void _disableWriteEvent() { | 907 void _disableWriteEvent() { |
| 904 if (_raw != null) { | 908 if (_raw != null) { |
| 905 _raw.writeEventsEnabled = false; | 909 _raw.writeEventsEnabled = false; |
| 906 } | 910 } |
| 907 } | 911 } |
| 908 | 912 |
| 909 void _consumerDone() { | 913 void _consumerDone([error]) { |
| 910 if (_raw != null) { | 914 if (_raw != null) { |
| 911 _raw.shutdown(SocketDirection.SEND); | 915 _raw.shutdown(SocketDirection.SEND); |
| 912 _disableWriteEvent(); | 916 _disableWriteEvent(); |
| 913 } | 917 } |
| 914 _done(); | 918 _done(error); |
| 915 } | 919 } |
| 916 } | 920 } |
| 917 | 921 |
| 918 | 922 |
| 919 class _SecureSocket extends _Socket implements SecureSocket { | 923 class _SecureSocket extends _Socket implements SecureSocket { |
| 920 _SecureSocket(RawSecureSocket raw) : super(raw); | 924 _SecureSocket(RawSecureSocket raw) : super(raw); |
| 921 | 925 |
| 922 void set onBadCertificate(bool callback(X509Certificate certificate)) { | 926 void set onBadCertificate(bool callback(X509Certificate certificate)) { |
| 923 if (_raw == null) { | 927 if (_raw == null) { |
| 924 throw new StateError("onBadCertificate called on destroyed SecureSocket"); | 928 throw new StateError("onBadCertificate called on destroyed SecureSocket"); |
| 925 } | 929 } |
| 926 _raw.onBadCertificate = callback; | 930 _raw.onBadCertificate = callback; |
| 927 } | 931 } |
| 928 | 932 |
| 929 X509Certificate get peerCertificate { | 933 X509Certificate get peerCertificate { |
| 930 if (_raw == null) { | 934 if (_raw == null) { |
| 931 throw new StateError("peerCertificate called on destroyed SecureSocket"); | 935 throw new StateError("peerCertificate called on destroyed SecureSocket"); |
| 932 } | 936 } |
| 933 return _raw.peerCertificate; | 937 return _raw.peerCertificate; |
| 934 } | 938 } |
| 935 } | 939 } |
| OLD | NEW |