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

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

Issue 9029001: Add close to input stream and cleanup socket and streams (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 12 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 _started = true; 64 _started = true;
65 65
66 // Make sure to activate socket handlers now that the file 66 // Make sure to activate socket handlers now that the file
67 // descriptors have been set. 67 // descriptors have been set.
68 _in._activateHandlers(); 68 _in._activateHandlers();
69 _out._activateHandlers(); 69 _out._activateHandlers();
70 _err._activateHandlers(); 70 _err._activateHandlers();
71 71
72 // Setup an exit handler to handle internal cleanup and possible 72 // Setup an exit handler to handle internal cleanup and possible
73 // callback when a process terminates. 73 // callback when a process terminates.
74 _exitHandler.dataHandler = () { 74 _exitHandler.inputStream.dataHandler = () {
75 final int EXIT_DATA_SIZE = 12; 75 final int EXIT_DATA_SIZE = 12;
76 List<int> exitDataBuffer = new List<int>(EXIT_DATA_SIZE); 76 List<int> exitDataBuffer = new List<int>(EXIT_DATA_SIZE);
77 InputStream input = _exitHandler.inputStream;
78 int exitDataRead = 0; 77 int exitDataRead = 0;
79 78
80 int exitCode(List<int> ints) { 79 int exitCode(List<int> ints) {
81 var code = _intFromBytes(ints, 4); 80 var code = _intFromBytes(ints, 4);
82 var negative = _intFromBytes(ints, 8); 81 var negative = _intFromBytes(ints, 8);
83 assert(negative == 0 || negative == 1); 82 assert(negative == 0 || negative == 1);
84 return (negative == 0) ? code : -code; 83 return (negative == 0) ? code : -code;
85 } 84 }
86 85
87 int exitPid(List<int> ints) { 86 int exitPid(List<int> ints) {
88 return _intFromBytes(ints, 0); 87 return _intFromBytes(ints, 0);
89 } 88 }
90 89
91 void handleExit() { 90 void handleExit() {
92 _processExit(exitPid(exitDataBuffer)); 91 _processExit(exitPid(exitDataBuffer));
93 if (_exitHandlerCallback !== null) { 92 if (_exitHandlerCallback !== null) {
94 _exitHandlerCallback(exitCode(exitDataBuffer)); 93 _exitHandlerCallback(exitCode(exitDataBuffer));
95 } 94 }
96 } 95 }
97 96
98 void exitData() { 97 exitDataRead += _exitHandler.inputStream.readInto(
99 exitDataRead += input.readInto( 98 exitDataBuffer, exitDataRead, EXIT_DATA_SIZE - exitDataRead);
100 exitDataBuffer, exitDataRead, EXIT_DATA_SIZE - exitDataRead); 99 if (exitDataRead == EXIT_DATA_SIZE) handleExit();
101 if (exitDataRead == EXIT_DATA_SIZE) handleExit();
102 }
103
104 input.dataHandler = exitData;
105 }; 100 };
106 101
107 if (_startHandler !== null) { 102 if (_startHandler !== null) {
108 _startHandler(); 103 _startHandler();
109 } 104 }
110 } 105 }
111 106
112 bool _start(String path, 107 bool _start(String path,
113 List<String> arguments, 108 List<String> arguments,
114 Socket input, 109 Socket input,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 Socket _err; 192 Socket _err;
198 Socket _exitHandler; 193 Socket _exitHandler;
199 int _pid; 194 int _pid;
200 bool _closed; 195 bool _closed;
201 bool _killed; 196 bool _killed;
202 bool _started; 197 bool _started;
203 Function _exitHandlerCallback; 198 Function _exitHandlerCallback;
204 Function _errorHandler; 199 Function _errorHandler;
205 Function _startHandler; 200 Function _startHandler;
206 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698