| Index: runtime/bin/process_impl.dart
|
| diff --git a/runtime/bin/process_impl.dart b/runtime/bin/process_impl.dart
|
| index 0e0b6957399b98d2cf57b6598ab0f8da525a4eda..98d72b4811ffc2f630c5209f487e6439854508dc 100644
|
| --- a/runtime/bin/process_impl.dart
|
| +++ b/runtime/bin/process_impl.dart
|
| @@ -38,9 +38,37 @@ class _Process implements Process {
|
| throw new ProcessException(status._errorMessage, status._errorCode);
|
| }
|
| _started = true;
|
| - if (_exitHandlerCallback !== null) {
|
| - setExitHandler(_exitHandlerCallback);
|
| - }
|
| +
|
| + // Setup an exit handler to handle internal cleanup and possible
|
| + // callback when a process terminates.
|
| + _exitHandler.setDataHandler(() {
|
| + List<int> buffer = new List<int>(8);
|
| + SocketInputStream input = _exitHandler.inputStream;
|
| +
|
| + int exitCode(List<int> ints) {
|
| + return ints[4] + (ints[5] << 8) + (ints[6] << 16) + (ints[7] << 24);
|
| + }
|
| +
|
| + int exitPid(List<int> ints) {
|
| + return ints[0] + (ints[1] << 8) + (ints[2] << 16) + (ints[3] << 24);
|
| + }
|
| +
|
| + void handleExit() {
|
| + _processExit(exitPid(buffer));
|
| + if (_exitHandlerCallback != null) {
|
| + _exitHandlerCallback(exitCode(buffer));
|
| + }
|
| + }
|
| +
|
| + void readData() {
|
| + handleExit();
|
| + }
|
| +
|
| + bool result = input.read(buffer, 0, 8, readData);
|
| + if (result) {
|
| + handleExit();
|
| + }
|
| + });
|
| }
|
|
|
| bool _start(String path,
|
| @@ -51,6 +79,8 @@ class _Process implements Process {
|
| Socket exitHandler,
|
| _ProcessStartStatus status) native "Process_Start";
|
|
|
| + void _processExit(int pid) native "Process_Exit";
|
| +
|
| InputStream get stdoutStream() {
|
| if (_closed) {
|
| throw new ProcessException("Process closed");
|
| @@ -106,48 +136,18 @@ class _Process implements Process {
|
| if (_killed) {
|
| throw new ProcessException("Process killed");
|
| }
|
| - if (_started) {
|
| - _exitHandler.setDataHandler(() {
|
| - List<int> buffer = new List<int>(4);
|
| - SocketInputStream input = _exitHandler.inputStream;
|
| -
|
| - int getExitValue(List<int> ints) {
|
| - return ints[0] + (ints[1] << 8) + (ints[2] << 16) + (ints[3] << 24);
|
| - }
|
| -
|
| - void readData() {
|
| - callback(getExitValue(buffer));
|
| - }
|
| -
|
| - bool result = input.read(buffer, 0, 4, readData);
|
| - if (result) {
|
| - callback(getExitValue(buffer));
|
| - }
|
| - });
|
| - } else {
|
| - _exitHandlerCallback = callback;
|
| - }
|
| + _exitHandlerCallback = callback;
|
| }
|
|
|
| String _path;
|
| -
|
| ObjectArray<String> _arguments;
|
| -
|
| Socket _in;
|
| -
|
| Socket _out;
|
| -
|
| Socket _err;
|
| -
|
| Socket _exitHandler;
|
| -
|
| int _pid;
|
| -
|
| bool _closed;
|
| -
|
| bool _killed;
|
| -
|
| bool _started;
|
| -
|
| var _exitHandlerCallback;
|
| }
|
|
|