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

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

Issue 108003009: Signal handling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Nicer API and Android+Mac versions. Created 7 years 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
« no previous file with comments | « runtime/bin/process_macos.cc ('k') | runtime/bin/process_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
74 patch class _ProcessUtils { 124 patch class _ProcessUtils {
75 /* patch */ static void _exit(int status) native "Process_Exit"; 125 /* patch */ static void _exit(int status) native "Process_Exit";
76 /* patch */ static void _setExitCode(int status) 126 /* patch */ static void _setExitCode(int status)
77 native "Process_SetExitCode"; 127 native "Process_SetExitCode";
78 /* patch */ static void _sleep(int millis) native "Process_Sleep"; 128 /* patch */ static void _sleep(int millis) native "Process_Sleep";
79 /* patch */ static int _pid(Process process) native "Process_Pid"; 129 /* 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 }
80 } 145 }
81 146
82 147
83 class _ProcessStartStatus { 148 class _ProcessStartStatus {
84 int _errorCode; // Set to OS error code if process start failed. 149 int _errorCode; // Set to OS error code if process start failed.
85 String _errorMessage; // Set to OS error message if process start failed. 150 String _errorMessage; // Set to OS error message if process start failed.
86 } 151 }
87 152
88 153
89 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process { 154 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process {
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 const _ProcessResult(int this.pid, 532 const _ProcessResult(int this.pid,
468 int this.exitCode, 533 int this.exitCode,
469 this.stdout, 534 this.stdout,
470 this.stderr); 535 this.stderr);
471 536
472 final int pid; 537 final int pid;
473 final int exitCode; 538 final int exitCode;
474 final stdout; 539 final stdout;
475 final stderr; 540 final stderr;
476 } 541 }
OLDNEW
« no previous file with comments | « runtime/bin/process_macos.cc ('k') | runtime/bin/process_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698