| OLD | NEW |
| 1 // Copyright (c) 2012, 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 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
| 7 | 7 |
| 8 #include "bin/process.h" | 8 #include "bin/process.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 | 568 |
| 569 | 569 |
| 570 class BufferList: public BufferListBase { | 570 class BufferList: public BufferListBase { |
| 571 public: | 571 public: |
| 572 bool Read(int fd, intptr_t available) { | 572 bool Read(int fd, intptr_t available) { |
| 573 // Read all available bytes. | 573 // Read all available bytes. |
| 574 while (available > 0) { | 574 while (available > 0) { |
| 575 if (free_size_ == 0) Allocate(); | 575 if (free_size_ == 0) Allocate(); |
| 576 ASSERT(free_size_ > 0); | 576 ASSERT(free_size_ > 0); |
| 577 ASSERT(free_size_ <= kBufferSize); | 577 ASSERT(free_size_ <= kBufferSize); |
| 578 intptr_t block_size = dart::Utils::Minimum(free_size_, available); | 578 size_t block_size = dart::Utils::Minimum(free_size_, available); |
| 579 intptr_t bytes = TEMP_FAILURE_RETRY(read( | 579 ssize_t bytes = TEMP_FAILURE_RETRY(read( |
| 580 fd, | 580 fd, |
| 581 reinterpret_cast<void*>(FreeSpaceAddress()), | 581 reinterpret_cast<void*>(FreeSpaceAddress()), |
| 582 block_size)); | 582 block_size)); |
| 583 if (bytes < 0) return false; | 583 if (bytes < 0) return false; |
| 584 data_size_ += bytes; | 584 data_size_ += bytes; |
| 585 free_size_ -= bytes; | 585 free_size_ -= bytes; |
| 586 available -= bytes; | 586 available -= bytes; |
| 587 } | 587 } |
| 588 return true; | 588 return true; |
| 589 } | 589 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 } | 629 } |
| 630 | 630 |
| 631 int alive = 3; | 631 int alive = 3; |
| 632 while (alive > 0) { | 632 while (alive > 0) { |
| 633 // Blocking call waiting for events from the child process. | 633 // Blocking call waiting for events from the child process. |
| 634 if (TEMP_FAILURE_RETRY(poll(fds, alive, -1)) <= 0) { | 634 if (TEMP_FAILURE_RETRY(poll(fds, alive, -1)) <= 0) { |
| 635 return CloseProcessBuffers(fds); | 635 return CloseProcessBuffers(fds); |
| 636 } | 636 } |
| 637 | 637 |
| 638 // Process incoming data. | 638 // Process incoming data. |
| 639 for (int i = 0; i < alive; i++) { | 639 int current_alive = alive; |
| 640 for (int i = 0; i < current_alive; i++) { |
| 641 intptr_t avail; |
| 640 if (fds[i].revents & POLLIN) { | 642 if (fds[i].revents & POLLIN) { |
| 641 intptr_t avail = FDUtils::AvailableBytes(fds[i].fd); | 643 avail = FDUtils::AvailableBytes(fds[i].fd); |
| 642 // On Mac OS POLLIN can be set with zero available | 644 // On Mac OS POLLIN can be set with zero available |
| 643 // bytes. POLLHUP is most likely also set in this case. | 645 // bytes. POLLHUP is most likely also set in this case. |
| 644 if (avail > 0) { | 646 if (avail > 0) { |
| 645 if (fds[i].fd == out) { | 647 if (fds[i].fd == out) { |
| 646 if (!out_data.Read(out, avail)) { | 648 if (!out_data.Read(out, avail)) { |
| 647 return CloseProcessBuffers(fds); | 649 return CloseProcessBuffers(fds); |
| 648 } | 650 } |
| 649 } else if (fds[i].fd == err) { | 651 } else if (fds[i].fd == err) { |
| 650 if (!err_data.Read(err, avail)) { | 652 if (!err_data.Read(err, avail)) { |
| 651 return CloseProcessBuffers(fds); | 653 return CloseProcessBuffers(fds); |
| 652 } | 654 } |
| 653 } else if (fds[i].fd == exit_event) { | 655 } else if (fds[i].fd == exit_event) { |
| 654 if (avail == 8) { | 656 if (avail == 8) { |
| 655 intptr_t b = TEMP_FAILURE_RETRY(read(fds[i].fd, | 657 intptr_t b = TEMP_FAILURE_RETRY(read(fds[i].fd, |
| 656 exit_code_data.bytes, 8)); | 658 exit_code_data.bytes, 8)); |
| 657 if (b != 8) { | 659 if (b != 8) { |
| 658 return CloseProcessBuffers(fds); | 660 return CloseProcessBuffers(fds); |
| 659 } | 661 } |
| 660 } | 662 } |
| 661 } else { | 663 } else { |
| 662 UNREACHABLE(); | 664 UNREACHABLE(); |
| 663 } | 665 } |
| 664 } | 666 } |
| 665 } | 667 } |
| 666 } | 668 if (fds[i].revents & POLLHUP || |
| 667 | 669 ((fds[i].revents & POLLIN) && avail == 0)) { |
| 668 // Process closed. | |
| 669 for (int i = 0; i < alive; i++) { | |
| 670 if (fds[i].revents & POLLHUP) { | |
| 671 VOID_TEMP_FAILURE_RETRY(close(fds[i].fd)); | 670 VOID_TEMP_FAILURE_RETRY(close(fds[i].fd)); |
| 672 alive--; | 671 alive--; |
| 673 if (i < alive) { | 672 if (i < alive) { |
| 674 fds[i] = fds[alive]; | 673 fds[i] = fds[alive]; |
| 675 } | 674 } |
| 676 } | 675 } |
| 677 } | 676 } |
| 678 } | 677 } |
| 679 | 678 |
| 680 // All handles closed and all data read. | 679 // All handles closed and all data read. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 702 | 701 |
| 703 | 702 |
| 704 intptr_t Process::CurrentProcessId() { | 703 intptr_t Process::CurrentProcessId() { |
| 705 return static_cast<intptr_t>(getpid()); | 704 return static_cast<intptr_t>(getpid()); |
| 706 } | 705 } |
| 707 | 706 |
| 708 } // namespace bin | 707 } // namespace bin |
| 709 } // namespace dart | 708 } // namespace dart |
| 710 | 709 |
| 711 #endif // defined(TARGET_OS_MACOS) | 710 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |