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; | |
845 subscription.pause(); | 840 subscription.pause(); |
846 } | 841 } |
847 socket._enableWriteEvent(); | 842 socket._enableWriteEvent(); |
848 } else { | 843 } else { |
849 buffer = null; | 844 buffer = null; |
850 if (paused) { | 845 if (paused) { |
851 paused = false; | 846 paused = false; |
852 subscription.resume(); | 847 subscription.resume(); |
853 } | 848 } |
854 } | 849 } |
(...skipping 12 matching lines...) Expand all Loading... |
867 streamCompleter.complete(socket); | 862 streamCompleter.complete(socket); |
868 } | 863 } |
869 streamCompleter = null; | 864 streamCompleter = null; |
870 } | 865 } |
871 } | 866 } |
872 | 867 |
873 void stop() { | 868 void stop() { |
874 if (subscription == null) return; | 869 if (subscription == null) return; |
875 subscription.cancel(); | 870 subscription.cancel(); |
876 subscription = null; | 871 subscription = null; |
| 872 paused = false; |
877 socket._disableWriteEvent(); | 873 socket._disableWriteEvent(); |
878 } | 874 } |
879 } | 875 } |
880 | 876 |
881 | 877 |
882 class _Socket extends Stream<List<int>> implements Socket { | 878 class _Socket extends Stream<List<int>> implements Socket { |
883 RawSocket _raw; // Set to null when the raw socket is closed. | 879 RawSocket _raw; // Set to null when the raw socket is closed. |
884 bool _closed = false; // Set to true when the raw socket is closed. | 880 bool _closed = false; // Set to true when the raw socket is closed. |
885 StreamController _controller; | 881 StreamController _controller; |
886 bool _controllerClosed = false; | 882 bool _controllerClosed = false; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 if (_detachReady != null) { | 1065 if (_detachReady != null) { |
1070 _detachReady.complete(null); | 1066 _detachReady.complete(null); |
1071 } else { | 1067 } else { |
1072 if (_raw != null) { | 1068 if (_raw != null) { |
1073 _raw.shutdown(SocketDirection.SEND); | 1069 _raw.shutdown(SocketDirection.SEND); |
1074 _disableWriteEvent(); | 1070 _disableWriteEvent(); |
1075 } | 1071 } |
1076 } | 1072 } |
1077 } | 1073 } |
1078 } | 1074 } |
OLD | NEW |