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 #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_WINDOWS) | 8 #if defined(TARGET_OS_WINDOWS) |
9 | 9 |
10 #include "bin/process.h" | 10 #include "bin/process.h" |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 707 |
708 | 708 |
709 class BufferList : public BufferListBase { | 709 class BufferList : public BufferListBase { |
710 public: | 710 public: |
711 BufferList() : read_pending_(true) {} | 711 BufferList() : read_pending_(true) {} |
712 | 712 |
713 // Indicate that data has been read into the buffer provided to | 713 // Indicate that data has been read into the buffer provided to |
714 // overlapped read. | 714 // overlapped read. |
715 void DataIsRead(intptr_t size) { | 715 void DataIsRead(intptr_t size) { |
716 ASSERT(read_pending_ == true); | 716 ASSERT(read_pending_ == true); |
717 data_size_ += size; | 717 set_data_size(data_size() + size); |
718 free_size_ -= size; | 718 set_free_size(free_size() - size); |
719 ASSERT(free_size_ >= 0); | 719 ASSERT(free_size() >= 0); |
720 read_pending_ = false; | 720 read_pending_ = false; |
721 } | 721 } |
722 | 722 |
723 // The access to the read buffer for overlapped read. | 723 // The access to the read buffer for overlapped read. |
724 void GetReadBuffer(uint8_t** buffer, intptr_t* size) { | 724 bool GetReadBuffer(uint8_t** buffer, intptr_t* size) { |
725 ASSERT(!read_pending_); | 725 ASSERT(!read_pending_); |
726 if (free_size_ == 0) { | 726 if (free_size() == 0) { |
727 Allocate(); | 727 if (!Allocate()) { |
| 728 return false; |
| 729 } |
728 } | 730 } |
729 ASSERT(free_size_ > 0); | 731 ASSERT(free_size() > 0); |
730 ASSERT(free_size_ <= kBufferSize); | 732 ASSERT(free_size() <= kBufferSize); |
731 *buffer = FreeSpaceAddress(); | 733 *buffer = FreeSpaceAddress(); |
732 *size = free_size_; | 734 *size = free_size(); |
733 read_pending_ = true; | 735 read_pending_ = true; |
| 736 return true; |
734 } | 737 } |
735 | 738 |
736 intptr_t GetDataSize() { return data_size_; } | 739 intptr_t GetDataSize() { return data_size(); } |
737 | 740 |
738 uint8_t* GetFirstDataBuffer() { | 741 uint8_t* GetFirstDataBuffer() { |
739 ASSERT(head_ != NULL); | 742 ASSERT(head() != NULL); |
740 ASSERT(head_ == tail_); | 743 ASSERT(head() == tail()); |
741 ASSERT(data_size_ <= kBufferSize); | 744 ASSERT(data_size() <= kBufferSize); |
742 return head_->data_; | 745 return head()->data(); |
743 } | 746 } |
744 | 747 |
745 void FreeDataBuffer() { Free(); } | 748 void FreeDataBuffer() { Free(); } |
746 | 749 |
747 private: | 750 private: |
748 bool read_pending_; | 751 bool read_pending_; |
749 | 752 |
750 DISALLOW_COPY_AND_ASSIGN(BufferList); | 753 DISALLOW_COPY_AND_ASSIGN(BufferList); |
751 }; | 754 }; |
752 | 755 |
(...skipping 16 matching lines...) Expand all Loading... |
769 buffer_.DataIsRead(overlapped_.InternalHigh); | 772 buffer_.DataIsRead(overlapped_.InternalHigh); |
770 } else { | 773 } else { |
771 buffer_.DataIsRead(0); | 774 buffer_.DataIsRead(0); |
772 } | 775 } |
773 | 776 |
774 // Keep reading until error or pending operation. | 777 // Keep reading until error or pending operation. |
775 while (true) { | 778 while (true) { |
776 ClearOverlapped(); | 779 ClearOverlapped(); |
777 uint8_t* buffer; | 780 uint8_t* buffer; |
778 intptr_t buffer_size; | 781 intptr_t buffer_size; |
779 buffer_.GetReadBuffer(&buffer, &buffer_size); | 782 if (!buffer_.GetReadBuffer(&buffer, &buffer_size)) { |
| 783 return false; |
| 784 } |
780 BOOL ok = ReadFile(handle_, buffer, buffer_size, NULL, &overlapped_); | 785 BOOL ok = ReadFile(handle_, buffer, buffer_size, NULL, &overlapped_); |
781 if (!ok) { | 786 if (!ok) { |
782 return (GetLastError() == ERROR_IO_PENDING); | 787 return (GetLastError() == ERROR_IO_PENDING); |
783 } | 788 } |
784 buffer_.DataIsRead(overlapped_.InternalHigh); | 789 buffer_.DataIsRead(overlapped_.InternalHigh); |
785 } | 790 } |
786 } | 791 } |
787 | 792 |
788 Dart_Handle GetData() { return buffer_.GetData(); } | 793 Dart_Handle GetData() { return buffer_.GetData(); } |
789 | 794 |
790 intptr_t GetDataSize() { return buffer_.GetDataSize(); } | 795 intptr_t GetDataSize() { return buffer_.GetDataSize(); } |
791 | 796 |
792 uint8_t* GetFirstDataBuffer() { return buffer_.GetFirstDataBuffer(); } | 797 uint8_t* GetFirstDataBuffer() { return buffer_.GetFirstDataBuffer(); } |
793 | 798 |
794 void FreeDataBuffer() { return buffer_.FreeDataBuffer(); } | 799 void FreeDataBuffer() { return buffer_.FreeDataBuffer(); } |
795 | 800 |
| 801 #if defined(DEBUG) |
| 802 bool IsEmpty() const { return buffer_.IsEmpty(); } |
| 803 #endif |
| 804 |
796 void Close() { | 805 void Close() { |
797 CloseHandle(handle_); | 806 CloseHandle(handle_); |
798 CloseHandle(event_); | 807 CloseHandle(event_); |
799 handle_ = INVALID_HANDLE_VALUE; | 808 handle_ = INVALID_HANDLE_VALUE; |
800 overlapped_.hEvent = INVALID_HANDLE_VALUE; | 809 overlapped_.hEvent = INVALID_HANDLE_VALUE; |
801 } | 810 } |
802 | 811 |
803 private: | 812 private: |
804 void ClearOverlapped() { | 813 void ClearOverlapped() { |
805 memset(&overlapped_, 0, sizeof(overlapped_)); | 814 memset(&overlapped_, 0, sizeof(overlapped_)); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 } | 884 } |
876 } | 885 } |
877 break; | 886 break; |
878 } | 887 } |
879 } | 888 } |
880 } | 889 } |
881 | 890 |
882 // All handles closed and all data read. | 891 // All handles closed and all data read. |
883 result->set_stdout_data(oh[0].GetData()); | 892 result->set_stdout_data(oh[0].GetData()); |
884 result->set_stderr_data(oh[1].GetData()); | 893 result->set_stderr_data(oh[1].GetData()); |
| 894 DEBUG_ASSERT(oh[0].IsEmpty()); |
| 895 DEBUG_ASSERT(oh[1].IsEmpty()); |
885 | 896 |
886 // Calculate the exit code. | 897 // Calculate the exit code. |
887 ASSERT(oh[2].GetDataSize() == 8); | 898 ASSERT(oh[2].GetDataSize() == 8); |
888 uint32_t exit_codes[2]; | 899 uint32_t exit_codes[2]; |
889 memmove(&exit_codes, oh[2].GetFirstDataBuffer(), sizeof(exit_codes)); | 900 memmove(&exit_codes, oh[2].GetFirstDataBuffer(), sizeof(exit_codes)); |
890 oh[2].FreeDataBuffer(); | 901 oh[2].FreeDataBuffer(); |
891 intptr_t exit_code = exit_codes[0]; | 902 intptr_t exit_code = exit_codes[0]; |
892 intptr_t negative = exit_codes[1]; | 903 intptr_t negative = exit_codes[1]; |
893 if (negative != 0) { | 904 if (negative != 0) { |
894 exit_code = -exit_code; | 905 exit_code = -exit_code; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 } | 1041 } |
1031 delete handler; | 1042 delete handler; |
1032 } | 1043 } |
1033 | 1044 |
1034 } // namespace bin | 1045 } // namespace bin |
1035 } // namespace dart | 1046 } // namespace dart |
1036 | 1047 |
1037 #endif // defined(TARGET_OS_WINDOWS) | 1048 #endif // defined(TARGET_OS_WINDOWS) |
1038 | 1049 |
1039 #endif // !defined(DART_IO_DISABLED) | 1050 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |