| 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 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 if (socket._raw != null) { | 661 if (socket._raw != null) { |
| 662 subscription = stream.listen((data) { | 662 subscription = stream.listen( |
| 663 assert(!paused); | 663 (data) { |
| 664 assert(buffer == null); | 664 assert(!paused); |
| 665 buffer = data; | 665 assert(buffer == null); |
| 666 offset = 0; | 666 buffer = data; |
| 667 write(); | 667 offset = 0; |
| 668 }, | 668 write(); |
| 669 onError: (error) { | 669 }, |
| 670 socket._consumerDone(error); | 670 onError: (error) { |
| 671 }, | 671 socket._consumerDone(error); |
| 672 onDone: () { | 672 }, |
| 673 socket._consumerDone(); | 673 onDone: () { |
| 674 }); | 674 socket._consumerDone(); |
| 675 }, |
| 676 unsubscribeOnError: true); |
| 675 } | 677 } |
| 676 return socket._doneFuture; | 678 return socket._doneFuture; |
| 677 } | 679 } |
| 678 | 680 |
| 679 void write() { | 681 void write() { |
| 680 try { | 682 try { |
| 681 if (subscription == null) return; | 683 if (subscription == null) return; |
| 682 assert(buffer != null); | 684 assert(buffer != null); |
| 683 // Write as much as possible. | 685 // Write as much as possible. |
| 684 offset += socket._write(buffer, offset, buffer.length - offset); | 686 offset += socket._write(buffer, offset, buffer.length - offset); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 _raw.onBadCertificate = callback; | 921 _raw.onBadCertificate = callback; |
| 920 } | 922 } |
| 921 | 923 |
| 922 X509Certificate get peerCertificate { | 924 X509Certificate get peerCertificate { |
| 923 if (_raw == null) { | 925 if (_raw == null) { |
| 924 throw new StateError("peerCertificate called on destroyed SecureSocket"); | 926 throw new StateError("peerCertificate called on destroyed SecureSocket"); |
| 925 } | 927 } |
| 926 return _raw.peerCertificate; | 928 return _raw.peerCertificate; |
| 927 } | 929 } |
| 928 } | 930 } |
| OLD | NEW |