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

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

Issue 8318009: Update the streams interfaces (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fixes Created 9 years, 2 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 24 matching lines...) Expand all
35 _path, _arguments, _in, _out, _err, _exitHandler, status); 35 _path, _arguments, _in, _out, _err, _exitHandler, status);
36 if (!success) { 36 if (!success) {
37 close(); 37 close();
38 throw new ProcessException(status._errorMessage, status._errorCode); 38 throw new ProcessException(status._errorMessage, status._errorCode);
39 } 39 }
40 _started = true; 40 _started = true;
41 41
42 // Setup an exit handler to handle internal cleanup and possible 42 // Setup an exit handler to handle internal cleanup and possible
43 // callback when a process terminates. 43 // callback when a process terminates.
44 _exitHandler.setDataHandler(() { 44 _exitHandler.setDataHandler(() {
45 List<int> buffer = new List<int>(8); 45 final int EXIT_DATA_SIZE = 8;
46 SocketInputStream input = _exitHandler.inputStream; 46 List<int> exitDataBuffer = new List<int>(EXIT_DATA_SIZE);
47 InputStream input = _exitHandler.inputStream;
48 int exitDataRead = 0;
47 49
48 int exitCode(List<int> ints) { 50 int exitCode(List<int> ints) {
49 return ints[4] + (ints[5] << 8) + (ints[6] << 16) + (ints[7] << 24); 51 return ints[4] + (ints[5] << 8) + (ints[6] << 16) + (ints[7] << 24);
50 } 52 }
51 53
52 int exitPid(List<int> ints) { 54 int exitPid(List<int> ints) {
53 return ints[0] + (ints[1] << 8) + (ints[2] << 16) + (ints[3] << 24); 55 return ints[0] + (ints[1] << 8) + (ints[2] << 16) + (ints[3] << 24);
54 } 56 }
55 57
56 void handleExit() { 58 void handleExit() {
57 _processExit(exitPid(buffer)); 59 _processExit(exitPid(exitDataBuffer));
58 if (_exitHandlerCallback != null) { 60 if (_exitHandlerCallback != null) {
59 _exitHandlerCallback(exitCode(buffer)); 61 _exitHandlerCallback(exitCode(exitDataBuffer));
60 } 62 }
61 } 63 }
62 64
63 void readData() { 65 void exitData() {
64 handleExit(); 66 exitDataRead += input.readInto(
67 exitDataBuffer, exitDataRead, EXIT_DATA_SIZE - exitDataRead);
68 if (exitDataRead == EXIT_DATA_SIZE) handleExit();
65 } 69 }
66 70
67 bool result = input.read(buffer, 0, 8, readData); 71 input.dataHandler = exitData;
68 if (result) {
69 handleExit();
70 }
71 }); 72 });
72 } 73 }
73 74
74 bool _start(String path, 75 bool _start(String path,
75 List<String> arguments, 76 List<String> arguments,
76 Socket input, 77 Socket input,
77 Socket output, 78 Socket output,
78 Socket error, 79 Socket error,
79 Socket exitHandler, 80 Socket exitHandler,
80 _ProcessStartStatus status) native "Process_Start"; 81 _ProcessStartStatus status) native "Process_Start";
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 Socket _in; 145 Socket _in;
145 Socket _out; 146 Socket _out;
146 Socket _err; 147 Socket _err;
147 Socket _exitHandler; 148 Socket _exitHandler;
148 int _pid; 149 int _pid;
149 bool _closed; 150 bool _closed;
150 bool _killed; 151 bool _killed;
151 bool _started; 152 bool _started;
152 var _exitHandlerCallback; 153 var _exitHandlerCallback;
153 } 154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698