OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
6 | 6 |
7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
8 #if defined(TARGET_OS_FUCHSIA) | 8 #if defined(TARGET_OS_FUCHSIA) |
9 | 9 |
10 #include "bin/process.h" | 10 #include "bin/process.h" |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 int e = errno; | 434 int e = errno; |
435 VOID_NO_RETRY_EXPECTED(close(out)); | 435 VOID_NO_RETRY_EXPECTED(close(out)); |
436 VOID_NO_RETRY_EXPECTED(close(err)); | 436 VOID_NO_RETRY_EXPECTED(close(err)); |
437 VOID_NO_RETRY_EXPECTED(close(exit_event)); | 437 VOID_NO_RETRY_EXPECTED(close(exit_event)); |
438 VOID_NO_RETRY_EXPECTED(close(epoll_fd)); | 438 VOID_NO_RETRY_EXPECTED(close(epoll_fd)); |
439 errno = e; | 439 errno = e; |
440 return false; | 440 return false; |
441 } | 441 } |
442 | 442 |
443 | 443 |
444 class BufferList : public BufferListBase { | |
445 public: | |
446 BufferList() {} | |
447 | |
448 bool Read(int fd, intptr_t available) { | |
449 // Read all available bytes. | |
450 while (available > 0) { | |
451 if (free_size_ == 0) { | |
452 Allocate(); | |
453 } | |
454 ASSERT(free_size_ > 0); | |
455 ASSERT(free_size_ <= kBufferSize); | |
456 intptr_t block_size = dart::Utils::Minimum(free_size_, available); | |
457 intptr_t bytes = NO_RETRY_EXPECTED( | |
458 read(fd, reinterpret_cast<void*>(FreeSpaceAddress()), block_size)); | |
459 if (bytes < 0) { | |
460 return false; | |
461 } | |
462 data_size_ += bytes; | |
463 free_size_ -= bytes; | |
464 available -= bytes; | |
465 } | |
466 return true; | |
467 } | |
468 | |
469 private: | |
470 DISALLOW_COPY_AND_ASSIGN(BufferList); | |
471 }; | |
472 | |
473 | |
474 bool Process::Wait(intptr_t pid, | 444 bool Process::Wait(intptr_t pid, |
475 intptr_t in, | 445 intptr_t in, |
476 intptr_t out, | 446 intptr_t out, |
477 intptr_t err, | 447 intptr_t err, |
478 intptr_t exit_event, | 448 intptr_t exit_event, |
479 ProcessResult* result) { | 449 ProcessResult* result) { |
480 VOID_NO_RETRY_EXPECTED(close(in)); | 450 VOID_NO_RETRY_EXPECTED(close(in)); |
481 | 451 |
482 // There is no return from this function using Dart_PropagateError | 452 // There is no return from this function using Dart_PropagateError |
483 // as memory used by the buffer lists is freed through their | 453 // as memory used by the buffer lists is freed through their |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 VOID_NO_RETRY_EXPECTED( | 533 VOID_NO_RETRY_EXPECTED( |
564 epoll_ctl(epoll_fd, EPOLL_CTL_DEL, events[i].data.fd, NULL)); | 534 epoll_ctl(epoll_fd, EPOLL_CTL_DEL, events[i].data.fd, NULL)); |
565 } | 535 } |
566 } | 536 } |
567 } | 537 } |
568 VOID_NO_RETRY_EXPECTED(close(epoll_fd)); | 538 VOID_NO_RETRY_EXPECTED(close(epoll_fd)); |
569 | 539 |
570 // All handles closed and all data read. | 540 // All handles closed and all data read. |
571 result->set_stdout_data(out_data.GetData()); | 541 result->set_stdout_data(out_data.GetData()); |
572 result->set_stderr_data(err_data.GetData()); | 542 result->set_stderr_data(err_data.GetData()); |
| 543 DEBUG_ASSERT(out_data.IsEmpty()); |
| 544 DEBUG_ASSERT(err_data.IsEmpty()); |
573 | 545 |
574 // Calculate the exit code. | 546 // Calculate the exit code. |
575 intptr_t exit_code = exit_code_data.ints[0]; | 547 intptr_t exit_code = exit_code_data.ints[0]; |
576 intptr_t negative = exit_code_data.ints[1]; | 548 intptr_t negative = exit_code_data.ints[1]; |
577 if (negative != 0) { | 549 if (negative != 0) { |
578 exit_code = -exit_code; | 550 exit_code = -exit_code; |
579 } | 551 } |
580 result->set_exit_code(exit_code); | 552 result->set_exit_code(exit_code); |
581 | 553 |
582 return true; | 554 return true; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 void Process::ClearSignalHandler(intptr_t signal) { | 812 void Process::ClearSignalHandler(intptr_t signal) { |
841 UNIMPLEMENTED(); | 813 UNIMPLEMENTED(); |
842 } | 814 } |
843 | 815 |
844 } // namespace bin | 816 } // namespace bin |
845 } // namespace dart | 817 } // namespace dart |
846 | 818 |
847 #endif // defined(TARGET_OS_FUCHSIA) | 819 #endif // defined(TARGET_OS_FUCHSIA) |
848 | 820 |
849 #endif // !defined(DART_IO_DISABLED) | 821 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |