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 683 matching lines...) Loading... |
694 if (socket != null) _controller.add(new _RawSocket(socket)); | 694 if (socket != null) _controller.add(new _RawSocket(socket)); |
695 }, | 695 }, |
696 error: (e) { | 696 error: (e) { |
697 _controller.addError(e); | 697 _controller.addError(e); |
698 _controller.close(); | 698 _controller.close(); |
699 } | 699 } |
700 ); | 700 ); |
701 } | 701 } |
702 | 702 |
703 StreamSubscription<RawSocket> listen(void onData(RawSocket event), | 703 StreamSubscription<RawSocket> listen(void onData(RawSocket event), |
704 {void onError(Object error), | 704 {Function onError, |
705 void onDone(), | 705 void onDone(), |
706 bool cancelOnError}) { | 706 bool cancelOnError}) { |
707 return _controller.stream.listen( | 707 return _controller.stream.listen( |
708 onData, | 708 onData, |
709 onError: onError, | 709 onError: onError, |
710 onDone: onDone, | 710 onDone: onDone, |
711 cancelOnError: cancelOnError); | 711 cancelOnError: cancelOnError); |
712 } | 712 } |
713 | 713 |
714 int get port => _socket.port; | 714 int get port => _socket.port; |
(...skipping 79 matching lines...) Loading... |
794 native.isClosedWrite = true; | 794 native.isClosedWrite = true; |
795 if (fd != null) _getStdioHandle(native, fd); | 795 if (fd != null) _getStdioHandle(native, fd); |
796 var result = new _RawSocket(native); | 796 var result = new _RawSocket(native); |
797 result._isMacOSTerminalInput = | 797 result._isMacOSTerminalInput = |
798 Platform.isMacOS && | 798 Platform.isMacOS && |
799 _StdIOUtils._socketType(result._socket) == _STDIO_HANDLE_TYPE_TERMINAL; | 799 _StdIOUtils._socketType(result._socket) == _STDIO_HANDLE_TYPE_TERMINAL; |
800 return result; | 800 return result; |
801 } | 801 } |
802 | 802 |
803 StreamSubscription<RawSocketEvent> listen(void onData(RawSocketEvent event), | 803 StreamSubscription<RawSocketEvent> listen(void onData(RawSocketEvent event), |
804 {void onError(Object error), | 804 {Function onError, |
805 void onDone(), | 805 void onDone(), |
806 bool cancelOnError}) { | 806 bool cancelOnError}) { |
807 return _controller.stream.listen( | 807 return _controller.stream.listen( |
808 onData, | 808 onData, |
809 onError: onError, | 809 onError: onError, |
810 onDone: onDone, | 810 onDone: onDone, |
811 cancelOnError: cancelOnError); | 811 cancelOnError: cancelOnError); |
812 } | 812 } |
813 | 813 |
814 int available() => _socket.available(); | 814 int available() => _socket.available(); |
(...skipping 91 matching lines...) Loading... |
906 int port, | 906 int port, |
907 int backlog, | 907 int backlog, |
908 bool v6Only) { | 908 bool v6Only) { |
909 return _RawServerSocket.bind(address, port, backlog, v6Only) | 909 return _RawServerSocket.bind(address, port, backlog, v6Only) |
910 .then((socket) => new _ServerSocket(socket)); | 910 .then((socket) => new _ServerSocket(socket)); |
911 } | 911 } |
912 | 912 |
913 _ServerSocket(this._socket); | 913 _ServerSocket(this._socket); |
914 | 914 |
915 StreamSubscription<Socket> listen(void onData(Socket event), | 915 StreamSubscription<Socket> listen(void onData(Socket event), |
916 {void onError(error), | 916 {Function onError, |
917 void onDone(), | 917 void onDone(), |
918 bool cancelOnError}) { | 918 bool cancelOnError}) { |
919 return _socket.map((rawSocket) => new _Socket(rawSocket)).listen( | 919 return _socket.map((rawSocket) => new _Socket(rawSocket)).listen( |
920 onData, | 920 onData, |
921 onError: onError, | 921 onError: onError, |
922 onDone: onDone, | 922 onDone: onDone, |
923 cancelOnError: cancelOnError); | 923 cancelOnError: cancelOnError); |
924 } | 924 } |
925 | 925 |
926 int get port => _socket.port; | 926 int get port => _socket.port; |
(...skipping 27 matching lines...) Loading... |
954 streamCompleter = new Completer<Socket>(); | 954 streamCompleter = new Completer<Socket>(); |
955 if (socket._raw != null) { | 955 if (socket._raw != null) { |
956 subscription = stream.listen( | 956 subscription = stream.listen( |
957 (data) { | 957 (data) { |
958 assert(!paused); | 958 assert(!paused); |
959 assert(buffer == null); | 959 assert(buffer == null); |
960 buffer = data; | 960 buffer = data; |
961 offset = 0; | 961 offset = 0; |
962 write(); | 962 write(); |
963 }, | 963 }, |
964 onError: (error) { | 964 onError: (error, [stackTrace]) { |
965 socket._consumerDone(); | 965 socket._consumerDone(); |
966 done(error); | 966 done(error, stackTrace); |
967 }, | 967 }, |
968 onDone: () { | 968 onDone: () { |
969 done(); | 969 done(); |
970 }, | 970 }, |
971 cancelOnError: true); | 971 cancelOnError: true); |
972 } | 972 } |
973 return streamCompleter.future; | 973 return streamCompleter.future; |
974 } | 974 } |
975 | 975 |
976 Future<Socket> close() { | 976 Future<Socket> close() { |
(...skipping 20 matching lines...) Loading... |
997 subscription.resume(); | 997 subscription.resume(); |
998 } | 998 } |
999 } | 999 } |
1000 } catch (e) { | 1000 } catch (e) { |
1001 stop(); | 1001 stop(); |
1002 socket._consumerDone(); | 1002 socket._consumerDone(); |
1003 done(e); | 1003 done(e); |
1004 } | 1004 } |
1005 } | 1005 } |
1006 | 1006 |
1007 void done([error]) { | 1007 void done([error, stackTrace]) { |
1008 if (streamCompleter != null) { | 1008 if (streamCompleter != null) { |
1009 if (error != null) { | 1009 if (error != null) { |
1010 streamCompleter.completeError(error); | 1010 streamCompleter.completeError(error, stackTrace); |
1011 } else { | 1011 } else { |
1012 streamCompleter.complete(socket); | 1012 streamCompleter.complete(socket); |
1013 } | 1013 } |
1014 streamCompleter = null; | 1014 streamCompleter = null; |
1015 } | 1015 } |
1016 } | 1016 } |
1017 | 1017 |
1018 void stop() { | 1018 void stop() { |
1019 if (subscription == null) return; | 1019 if (subscription == null) return; |
1020 subscription.cancel(); | 1020 subscription.cancel(); |
(...skipping 34 matching lines...) Loading... |
1055 return new _Socket(new _RawSocket._writePipe(fd)); | 1055 return new _Socket(new _RawSocket._writePipe(fd)); |
1056 } | 1056 } |
1057 | 1057 |
1058 factory _Socket._readPipe([int fd]) { | 1058 factory _Socket._readPipe([int fd]) { |
1059 return new _Socket(new _RawSocket._readPipe(fd)); | 1059 return new _Socket(new _RawSocket._readPipe(fd)); |
1060 } | 1060 } |
1061 | 1061 |
1062 _NativeSocket get _nativeSocket => _raw._socket; | 1062 _NativeSocket get _nativeSocket => _raw._socket; |
1063 | 1063 |
1064 StreamSubscription<List<int>> listen(void onData(List<int> event), | 1064 StreamSubscription<List<int>> listen(void onData(List<int> event), |
1065 {void onError(error), | 1065 {Function onError, |
1066 void onDone(), | 1066 void onDone(), |
1067 bool cancelOnError}) { | 1067 bool cancelOnError}) { |
1068 return _controller.stream.listen( | 1068 return _controller.stream.listen( |
1069 onData, | 1069 onData, |
1070 onError: onError, | 1070 onError: onError, |
1071 onDone: onDone, | 1071 onDone: onDone, |
1072 cancelOnError: cancelOnError); | 1072 cancelOnError: cancelOnError); |
1073 } | 1073 } |
1074 | 1074 |
1075 Encoding get encoding => _sink.encoding; | 1075 Encoding get encoding => _sink.encoding; |
(...skipping 106 matching lines...) Loading... |
1182 } | 1182 } |
1183 | 1183 |
1184 void _onDone() { | 1184 void _onDone() { |
1185 if (!_controllerClosed) { | 1185 if (!_controllerClosed) { |
1186 _controllerClosed = true; | 1186 _controllerClosed = true; |
1187 _controller.close(); | 1187 _controller.close(); |
1188 } | 1188 } |
1189 _consumer.done(); | 1189 _consumer.done(); |
1190 } | 1190 } |
1191 | 1191 |
1192 void _onError(error) { | 1192 void _onError(error, stackTrace) { |
1193 if (!_controllerClosed) { | 1193 if (!_controllerClosed) { |
1194 _controllerClosed = true; | 1194 _controllerClosed = true; |
1195 _controller.addError(error); | 1195 _controller.addError(error, stackTrace); |
1196 _controller.close(); | 1196 _controller.close(); |
1197 } | 1197 } |
1198 _consumer.done(error); | 1198 _consumer.done(error, stackTrace); |
1199 } | 1199 } |
1200 | 1200 |
1201 int _write(List<int> data, int offset, int length) => | 1201 int _write(List<int> data, int offset, int length) => |
1202 _raw.write(data, offset, length); | 1202 _raw.write(data, offset, length); |
1203 | 1203 |
1204 void _enableWriteEvent() { | 1204 void _enableWriteEvent() { |
1205 _raw.writeEventsEnabled = true; | 1205 _raw.writeEventsEnabled = true; |
1206 } | 1206 } |
1207 | 1207 |
1208 void _disableWriteEvent() { | 1208 void _disableWriteEvent() { |
1209 if (_raw != null) { | 1209 if (_raw != null) { |
1210 _raw.writeEventsEnabled = false; | 1210 _raw.writeEventsEnabled = false; |
1211 } | 1211 } |
1212 } | 1212 } |
1213 | 1213 |
1214 void _consumerDone() { | 1214 void _consumerDone() { |
1215 if (_detachReady != null) { | 1215 if (_detachReady != null) { |
1216 _detachReady.complete(null); | 1216 _detachReady.complete(null); |
1217 } else { | 1217 } else { |
1218 if (_raw != null) { | 1218 if (_raw != null) { |
1219 _raw.shutdown(SocketDirection.SEND); | 1219 _raw.shutdown(SocketDirection.SEND); |
1220 _disableWriteEvent(); | 1220 _disableWriteEvent(); |
1221 } | 1221 } |
1222 } | 1222 } |
1223 } | 1223 } |
1224 } | 1224 } |
OLD | NEW |