Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1336)

Side by Side Diff: runtime/bin/process_impl.dart

Issue 10545134: Give Process.kill an optional argument to specify which signal to send. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class _ProcessStartStatus { 5 class _ProcessStartStatus {
6 int _errorCode; // Set to OS error code if process start failed. 6 int _errorCode; // Set to OS error code if process start failed.
7 String _errorMessage; // Set to OS error message if process start failed. 7 String _errorMessage; // Set to OS error message if process start failed.
8 } 8 }
9 9
10 10
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 _exitHandler.inputStream.onData = () { 171 _exitHandler.inputStream.onData = () {
172 172
173 int exitCode(List<int> ints) { 173 int exitCode(List<int> ints) {
174 var code = _intFromBytes(ints, 0); 174 var code = _intFromBytes(ints, 0);
175 var negative = _intFromBytes(ints, 4); 175 var negative = _intFromBytes(ints, 4);
176 assert(negative == 0 || negative == 1); 176 assert(negative == 0 || negative == 1);
177 return (negative == 0) ? code : -code; 177 return (negative == 0) ? code : -code;
178 } 178 }
179 179
180 void handleExit() { 180 void handleExit() {
181 _killed = true;
181 if (_onExit !== null) { 182 if (_onExit !== null) {
182 _onExit(exitCode(exitDataBuffer)); 183 _onExit(exitCode(exitDataBuffer));
183 } 184 }
184 } 185 }
185 186
186 exitDataRead += _exitHandler.inputStream.readInto( 187 exitDataRead += _exitHandler.inputStream.readInto(
187 exitDataBuffer, exitDataRead, EXIT_DATA_SIZE - exitDataRead); 188 exitDataBuffer, exitDataRead, EXIT_DATA_SIZE - exitDataRead);
188 if (exitDataRead == EXIT_DATA_SIZE) handleExit(); 189 if (exitDataRead == EXIT_DATA_SIZE) handleExit();
189 }; 190 };
190 191
(...skipping 26 matching lines...) Expand all
217 return _err.inputStream; 218 return _err.inputStream;
218 } 219 }
219 220
220 OutputStream get stdin() { 221 OutputStream get stdin() {
221 if (_closed) { 222 if (_closed) {
222 throw new ProcessException("Process closed"); 223 throw new ProcessException("Process closed");
223 } 224 }
224 return _out.outputStream; 225 return _out.outputStream;
225 } 226 }
226 227
227 void kill() { 228 void kill([ProcessSignal signal = ProcessSignal.SIGTERM]) {
229 if (signal is! ProcessSignal) {
230 throw new IllegalArgumentException(
231 "Argument 'force' must be a ProcessSignal");
Mads Ager (google) 2012/06/12 09:13:44 'force' -> 'signal'
Anders Johnsen 2012/06/12 09:21:04 Done.
232 }
228 if (_closed && _pid === null) { 233 if (_closed && _pid === null) {
229 _reportError(new ProcessException("Process closed")); 234 _reportError(new ProcessException("Process closed"));
230 return; 235 return;
231 } 236 }
232 if (_killed) { 237 if (_killed) {
233 return; 238 return;
234 } 239 }
235 // TODO(ager): Make the actual kill operation asynchronous. 240 // TODO(ager): Make the actual kill operation asynchronous.
236 if (_kill(_pid)) { 241 if (_kill(_pid, signal._signalNumber)) {
237 _killed = true;
238 return; 242 return;
239 } 243 }
240 _reportError(new ProcessException("Could not kill process")); 244 _reportError(new ProcessException("Could not kill process"));
241 return; 245 return;
242 } 246 }
243 247
244 void _kill(int pid) native "Process_Kill"; 248 void _kill(int pid, int signal) native "Process_Kill";
245 249
246 void close() { 250 void close() {
247 if (_closed) { 251 if (_closed) {
248 throw new ProcessException("Process closed"); 252 throw new ProcessException("Process closed");
249 } 253 }
250 _in.close(); 254 _in.close();
251 _out.close(); 255 _out.close();
252 _err.close(); 256 _err.close();
253 _exitHandler.close(); 257 _exitHandler.close();
254 _closed = true; 258 _closed = true;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 394
391 class _ProcessResult implements ProcessResult { 395 class _ProcessResult implements ProcessResult {
392 const _ProcessResult(int this.exitCode, 396 const _ProcessResult(int this.exitCode,
393 String this.stdout, 397 String this.stdout,
394 String this.stderr); 398 String this.stderr);
395 399
396 final int exitCode; 400 final int exitCode;
397 final String stdout; 401 final String stdout;
398 final String stderr; 402 final String stderr;
399 } 403 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698