| OLD | NEW |
| 1 // Copyright (c) 2011, 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 |
| 11 class _Process implements Process { | 11 class _Process implements Process { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 // Make sure to activate socket handlers now that the file | 80 // Make sure to activate socket handlers now that the file |
| 81 // descriptors have been set. | 81 // descriptors have been set. |
| 82 _in._activateHandlers(); | 82 _in._activateHandlers(); |
| 83 _out._activateHandlers(); | 83 _out._activateHandlers(); |
| 84 _err._activateHandlers(); | 84 _err._activateHandlers(); |
| 85 | 85 |
| 86 // Setup an exit handler to handle internal cleanup and possible | 86 // Setup an exit handler to handle internal cleanup and possible |
| 87 // callback when a process terminates. | 87 // callback when a process terminates. |
| 88 _exitHandler.inputStream.dataHandler = () { | 88 _exitHandler.inputStream.dataHandler = () { |
| 89 final int EXIT_DATA_SIZE = 12; | 89 final int EXIT_DATA_SIZE = 8; |
| 90 List<int> exitDataBuffer = new List<int>(EXIT_DATA_SIZE); | 90 List<int> exitDataBuffer = new List<int>(EXIT_DATA_SIZE); |
| 91 int exitDataRead = 0; | 91 int exitDataRead = 0; |
| 92 | 92 |
| 93 int exitCode(List<int> ints) { | 93 int exitCode(List<int> ints) { |
| 94 var code = _intFromBytes(ints, 4); | 94 var code = _intFromBytes(ints, 0); |
| 95 var negative = _intFromBytes(ints, 8); | 95 var negative = _intFromBytes(ints, 4); |
| 96 assert(negative == 0 || negative == 1); | 96 assert(negative == 0 || negative == 1); |
| 97 return (negative == 0) ? code : -code; | 97 return (negative == 0) ? code : -code; |
| 98 } | 98 } |
| 99 | 99 |
| 100 int exitPid(List<int> ints) { | |
| 101 return _intFromBytes(ints, 0); | |
| 102 } | |
| 103 | |
| 104 void handleExit() { | 100 void handleExit() { |
| 105 _processExit(exitPid(exitDataBuffer)); | |
| 106 if (_exitHandlerCallback !== null) { | 101 if (_exitHandlerCallback !== null) { |
| 107 _exitHandlerCallback(exitCode(exitDataBuffer)); | 102 _exitHandlerCallback(exitCode(exitDataBuffer)); |
| 108 } | 103 } |
| 109 } | 104 } |
| 110 | 105 |
| 111 exitDataRead += _exitHandler.inputStream.readInto( | 106 exitDataRead += _exitHandler.inputStream.readInto( |
| 112 exitDataBuffer, exitDataRead, EXIT_DATA_SIZE - exitDataRead); | 107 exitDataBuffer, exitDataRead, EXIT_DATA_SIZE - exitDataRead); |
| 113 if (exitDataRead == EXIT_DATA_SIZE) handleExit(); | 108 if (exitDataRead == EXIT_DATA_SIZE) handleExit(); |
| 114 }; | 109 }; |
| 115 | 110 |
| 116 if (_startHandler !== null) { | 111 if (_startHandler !== null) { |
| 117 _startHandler(); | 112 _startHandler(); |
| 118 } | 113 } |
| 119 } | 114 } |
| 120 | 115 |
| 121 bool _start(String path, | 116 bool _start(String path, |
| 122 List<String> arguments, | 117 List<String> arguments, |
| 123 String workingDirectory, | 118 String workingDirectory, |
| 124 Socket input, | 119 Socket input, |
| 125 Socket output, | 120 Socket output, |
| 126 Socket error, | 121 Socket error, |
| 127 Socket exitHandler, | 122 Socket exitHandler, |
| 128 _ProcessStartStatus status) native "Process_Start"; | 123 _ProcessStartStatus status) native "Process_Start"; |
| 129 | 124 |
| 130 void _processExit(int pid) native "Process_Exit"; | |
| 131 | |
| 132 InputStream get stdout() { | 125 InputStream get stdout() { |
| 133 if (_closed) { | 126 if (_closed) { |
| 134 throw new ProcessException("Process closed"); | 127 throw new ProcessException("Process closed"); |
| 135 } | 128 } |
| 136 return _in.inputStream; | 129 return _in.inputStream; |
| 137 } | 130 } |
| 138 | 131 |
| 139 InputStream get stderr() { | 132 InputStream get stderr() { |
| 140 if (_closed) { | 133 if (_closed) { |
| 141 throw new ProcessException("Process closed"); | 134 throw new ProcessException("Process closed"); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 Socket _err; | 203 Socket _err; |
| 211 Socket _exitHandler; | 204 Socket _exitHandler; |
| 212 int _pid; | 205 int _pid; |
| 213 bool _closed; | 206 bool _closed; |
| 214 bool _killed; | 207 bool _killed; |
| 215 bool _started; | 208 bool _started; |
| 216 Function _exitHandlerCallback; | 209 Function _exitHandlerCallback; |
| 217 Function _errorHandler; | 210 Function _errorHandler; |
| 218 Function _startHandler; | 211 Function _startHandler; |
| 219 } | 212 } |
| OLD | NEW |