| 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 _WindowsCodePageDecoder { | 5 patch class _WindowsCodePageDecoder { |
| 6 /* patch */ static String _decodeBytes(List<int> bytes) | 6 /* patch */ static String _decodeBytes(List<int> bytes) |
| 7 native "SystemEncodingToString"; | 7 native "SystemEncodingToString"; |
| 8 } | 8 } |
| 9 | 9 |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 workingDirectory, | 64 workingDirectory, |
| 65 environment, | 65 environment, |
| 66 includeParentEnvironment, | 66 includeParentEnvironment, |
| 67 runInShell, | 67 runInShell, |
| 68 stdoutEncoding, | 68 stdoutEncoding, |
| 69 stderrEncoding); | 69 stderrEncoding); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 | 73 |
| 74 List<_SignalController> _signalControllers = new List(32); | |
| 75 | |
| 76 | |
| 77 class _SignalController { | |
| 78 final ProcessSignal signal; | |
| 79 | |
| 80 StreamController _controller; | |
| 81 var _id; | |
| 82 | |
| 83 _SignalController(this.signal) { | |
| 84 _controller = new StreamController.broadcast( | |
| 85 onListen: _listen, | |
| 86 onCancel: _cancel); | |
| 87 } | |
| 88 | |
| 89 Stream<ProcessSignal> get stream => _controller.stream; | |
| 90 | |
| 91 void _listen() { | |
| 92 var id = _setSignalHandler(signal._signalNumber); | |
| 93 if (id is! int) { | |
| 94 _controller.addError( | |
| 95 new SignalException("Failed to listen for $signal", id)); | |
| 96 return; | |
| 97 } | |
| 98 _id = id; | |
| 99 var socket = new _RawSocket(new _NativeSocket.watch(id)); | |
| 100 socket.listen((event) { | |
| 101 if (event == RawSocketEvent.READ) { | |
| 102 var bytes = socket.read(); | |
| 103 for (int i = 0; i < bytes.length; i++) { | |
| 104 _controller.add(signal); | |
| 105 } | |
| 106 } | |
| 107 }); | |
| 108 } | |
| 109 | |
| 110 void _cancel() { | |
| 111 if (_id != null) { | |
| 112 _clearSignalHandler(signal._signalNumber); | |
| 113 _id = null; | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 /* patch */ static int _setSignalHandler(int signal) | |
| 118 native "Process_SetSignalHandler"; | |
| 119 /* patch */ static int _clearSignalHandler(int signal) | |
| 120 native "Process_ClearSignalHandler"; | |
| 121 } | |
| 122 | |
| 123 | |
| 124 patch class _ProcessUtils { | 74 patch class _ProcessUtils { |
| 125 /* patch */ static void _exit(int status) native "Process_Exit"; | 75 /* patch */ static void _exit(int status) native "Process_Exit"; |
| 126 /* patch */ static void _setExitCode(int status) | 76 /* patch */ static void _setExitCode(int status) |
| 127 native "Process_SetExitCode"; | 77 native "Process_SetExitCode"; |
| 128 /* patch */ static void _sleep(int millis) native "Process_Sleep"; | 78 /* patch */ static void _sleep(int millis) native "Process_Sleep"; |
| 129 /* patch */ static int _pid(Process process) native "Process_Pid"; | 79 /* patch */ static int _pid(Process process) native "Process_Pid"; |
| 130 /* patch */ static Stream<ProcessSignal> _watchSignal(ProcessSignal signal) { | |
| 131 if (signal != ProcessSignal.SIGHUP && | |
| 132 signal != ProcessSignal.SIGINT && | |
| 133 (Platform.isWindows || | |
| 134 (signal != ProcessSignal.SIGUSR1 && | |
| 135 signal != ProcessSignal.SIGUSR2 && | |
| 136 signal != ProcessSignal.SIGWINCH))) { | |
| 137 throw new SignalException( | |
| 138 "Listening for signal $signal is not supported"); | |
| 139 } | |
| 140 if (_signalControllers[signal._signalNumber] == null) { | |
| 141 _signalControllers[signal._signalNumber] = new _SignalController(signal); | |
| 142 } | |
| 143 return _signalControllers[signal._signalNumber].stream; | |
| 144 } | |
| 145 } | 80 } |
| 146 | 81 |
| 147 | 82 |
| 148 class _ProcessStartStatus { | 83 class _ProcessStartStatus { |
| 149 int _errorCode; // Set to OS error code if process start failed. | 84 int _errorCode; // Set to OS error code if process start failed. |
| 150 String _errorMessage; // Set to OS error message if process start failed. | 85 String _errorMessage; // Set to OS error message if process start failed. |
| 151 } | 86 } |
| 152 | 87 |
| 153 | 88 |
| 154 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process { | 89 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process { |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 const _ProcessResult(int this.pid, | 467 const _ProcessResult(int this.pid, |
| 533 int this.exitCode, | 468 int this.exitCode, |
| 534 this.stdout, | 469 this.stdout, |
| 535 this.stderr); | 470 this.stderr); |
| 536 | 471 |
| 537 final int pid; | 472 final int pid; |
| 538 final int exitCode; | 473 final int exitCode; |
| 539 final stdout; | 474 final stdout; |
| 540 final stderr; | 475 final stderr; |
| 541 } | 476 } |
| OLD | NEW |