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(address, | 6 /* patch */ static Future<RawServerSocket> bind(address, |
7 int port, | 7 int port, |
8 {int backlog: 0, | 8 {int backlog: 0, |
9 bool v6Only: false}) { | 9 bool v6Only: false}) { |
10 return _RawServerSocket.bind(address, port, backlog, v6Only); | 10 return _RawServerSocket.bind(address, port, backlog, v6Only); |
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 | 830 |
831 void write() { | 831 void write() { |
832 try { | 832 try { |
833 if (subscription == null) return; | 833 if (subscription == null) return; |
834 assert(buffer != null); | 834 assert(buffer != null); |
835 // Write as much as possible. | 835 // Write as much as possible. |
836 offset += socket._write(buffer, offset, buffer.length - offset); | 836 offset += socket._write(buffer, offset, buffer.length - offset); |
837 if (offset < buffer.length) { | 837 if (offset < buffer.length) { |
838 if (!paused) { | 838 if (!paused) { |
839 paused = true; | 839 paused = true; |
| 840 // TODO(ajohnsen): It would be nice to avoid this check. |
| 841 // Some info: socket._write can emit an event, if it fails to write. |
| 842 // If the user closes the socket in that event, stop() will be called |
| 843 // before we get a change to pause. |
| 844 if (subscription == null) return; |
840 subscription.pause(); | 845 subscription.pause(); |
841 } | 846 } |
842 socket._enableWriteEvent(); | 847 socket._enableWriteEvent(); |
843 } else { | 848 } else { |
844 buffer = null; | 849 buffer = null; |
845 if (paused) { | 850 if (paused) { |
846 paused = false; | 851 paused = false; |
847 subscription.resume(); | 852 subscription.resume(); |
848 } | 853 } |
849 } | 854 } |
(...skipping 12 matching lines...) Expand all Loading... |
862 streamCompleter.complete(socket); | 867 streamCompleter.complete(socket); |
863 } | 868 } |
864 streamCompleter = null; | 869 streamCompleter = null; |
865 } | 870 } |
866 } | 871 } |
867 | 872 |
868 void stop() { | 873 void stop() { |
869 if (subscription == null) return; | 874 if (subscription == null) return; |
870 subscription.cancel(); | 875 subscription.cancel(); |
871 subscription = null; | 876 subscription = null; |
872 paused = false; | |
873 socket._disableWriteEvent(); | 877 socket._disableWriteEvent(); |
874 } | 878 } |
875 } | 879 } |
876 | 880 |
877 | 881 |
878 class _Socket extends Stream<List<int>> implements Socket { | 882 class _Socket extends Stream<List<int>> implements Socket { |
879 RawSocket _raw; // Set to null when the raw socket is closed. | 883 RawSocket _raw; // Set to null when the raw socket is closed. |
880 bool _closed = false; // Set to true when the raw socket is closed. | 884 bool _closed = false; // Set to true when the raw socket is closed. |
881 StreamController _controller; | 885 StreamController _controller; |
882 bool _controllerClosed = false; | 886 bool _controllerClosed = false; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 if (_detachReady != null) { | 1069 if (_detachReady != null) { |
1066 _detachReady.complete(null); | 1070 _detachReady.complete(null); |
1067 } else { | 1071 } else { |
1068 if (_raw != null) { | 1072 if (_raw != null) { |
1069 _raw.shutdown(SocketDirection.SEND); | 1073 _raw.shutdown(SocketDirection.SEND); |
1070 _disableWriteEvent(); | 1074 _disableWriteEvent(); |
1071 } | 1075 } |
1072 } | 1076 } |
1073 } | 1077 } |
1074 } | 1078 } |
OLD | NEW |