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

Side by Side Diff: runtime/bin/process.cc

Issue 21816002: Add Process.runSync for running processe synchronously. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed Mac OS issue Created 7 years, 4 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) 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 #include "bin/dartutils.h" 5 #include "bin/dartutils.h"
6 #include "bin/io_buffer.h" 6 #include "bin/io_buffer.h"
7 #include "bin/process.h" 7 #include "bin/process.h"
8 #include "bin/socket.h" 8 #include "bin/socket.h"
9 9
10 #include "include/dart_api.h" 10 #include "include/dart_api.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 DartUtils::SetStringField( 152 DartUtils::SetStringField(
153 status_handle, "_errorMessage", os_error_message); 153 status_handle, "_errorMessage", os_error_message);
154 } 154 }
155 delete[] string_args; 155 delete[] string_args;
156 delete[] string_environment; 156 delete[] string_environment;
157 free(os_error_message); 157 free(os_error_message);
158 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); 158 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0));
159 } 159 }
160 160
161 161
162 void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) {
163 Dart_EnterScope();
164 Dart_Handle process = Dart_GetNativeArgument(args, 0);
165 Dart_Handle stdin_handle = Dart_GetNativeArgument(args, 1);
166 Dart_Handle stdout_handle = Dart_GetNativeArgument(args, 2);
167 Dart_Handle stderr_handle = Dart_GetNativeArgument(args, 3);
168 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 4);
169 intptr_t process_stdin;
170 intptr_t process_stdout;
171 intptr_t process_stderr;
172 intptr_t exit_event;
173 Socket::GetSocketIdNativeField(stdin_handle, &process_stdin);
174 Socket::GetSocketIdNativeField(stdout_handle, &process_stdout);
175 Socket::GetSocketIdNativeField(stderr_handle, &process_stderr);
176 Socket::GetSocketIdNativeField(exit_handle, &exit_event);
177 ProcessResult result;
178 intptr_t pid;
179 Process::GetProcessIdNativeField(process, &pid);
180 if (Process::Wait(pid,
181 process_stdin,
182 process_stdout,
183 process_stderr,
184 exit_event,
185 &result)) {
186 Dart_Handle out =
187 IOBuffer::Create(result.stdout_data(), result.stdout_length());
188 Dart_Handle err =
189 IOBuffer::Create(result.stderr_data(), result.stderr_length());
190 Dart_Handle list = Dart_NewList(4);
191 Dart_ListSetAt(list, 0, Dart_NewInteger(pid));
192 Dart_ListSetAt(list, 1, Dart_NewInteger(result.exit_code()));
193 Dart_ListSetAt(list, 2, out);
194 Dart_ListSetAt(list, 3, err);
195 Dart_SetReturnValue(args, list);
196 } else {
197 Process::Kill(pid, 9);
198 Dart_ThrowException(DartUtils::NewDartOSError());
199 }
200 Dart_ExitScope();
201 }
202
203
162 void FUNCTION_NAME(Process_Kill)(Dart_NativeArguments args) { 204 void FUNCTION_NAME(Process_Kill)(Dart_NativeArguments args) {
163 Dart_Handle process = Dart_GetNativeArgument(args, 1); 205 Dart_Handle process = Dart_GetNativeArgument(args, 1);
164 intptr_t pid = -1; 206 intptr_t pid = -1;
165 Process::GetProcessIdNativeField(process, &pid); 207 Process::GetProcessIdNativeField(process, &pid);
166 int signal = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); 208 int signal = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
167 bool success = Process::Kill(pid, signal); 209 bool success = Process::Kill(pid, signal);
168 Dart_SetReturnValue(args, Dart_NewBoolean(success)); 210 Dart_SetReturnValue(args, Dart_NewBoolean(success));
169 } 211 }
170 212
171 213
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 int external_length = strlen(system_string); 286 int external_length = strlen(system_string);
245 uint8_t* buffer = NULL; 287 uint8_t* buffer = NULL;
246 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); 288 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer);
247 memmove(buffer, system_string, external_length); 289 memmove(buffer, system_string, external_length);
248 if (utf8 != system_string) free(const_cast<char*>(system_string)); 290 if (utf8 != system_string) free(const_cast<char*>(system_string));
249 Dart_SetReturnValue(args, external_array); 291 Dart_SetReturnValue(args, external_array);
250 } 292 }
251 293
252 } // namespace bin 294 } // namespace bin
253 } // namespace dart 295 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698