| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/common/data_pipe_utils.h" | 5 #include "mojo/common/data_pipe_utils.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 MojoResult result = | 85 MojoResult result = |
| 86 BeginWriteDataRaw(destination.get(), &buffer, &buffer_num_bytes, | 86 BeginWriteDataRaw(destination.get(), &buffer, &buffer_num_bytes, |
| 87 MOJO_WRITE_DATA_FLAG_NONE); | 87 MOJO_WRITE_DATA_FLAG_NONE); |
| 88 if (result == MOJO_RESULT_OK) { | 88 if (result == MOJO_RESULT_OK) { |
| 89 char* char_buffer = static_cast<char*>(buffer); | 89 char* char_buffer = static_cast<char*>(buffer); |
| 90 uint32_t byte_index = 0; | 90 uint32_t byte_index = 0; |
| 91 while (it != source.end() && byte_index < buffer_num_bytes) { | 91 while (it != source.end() && byte_index < buffer_num_bytes) { |
| 92 char_buffer[byte_index++] = *it++; | 92 char_buffer[byte_index++] = *it++; |
| 93 } | 93 } |
| 94 EndWriteDataRaw(destination.get(), byte_index); | 94 EndWriteDataRaw(destination.get(), byte_index); |
| 95 if (it == source.end()) |
| 96 return true; |
| 95 } else if (result == MOJO_RESULT_SHOULD_WAIT) { | 97 } else if (result == MOJO_RESULT_SHOULD_WAIT) { |
| 96 result = Wait(destination.get(), MOJO_HANDLE_SIGNAL_WRITABLE, | 98 result = Wait(destination.get(), MOJO_HANDLE_SIGNAL_WRITABLE, |
| 97 MOJO_DEADLINE_INDEFINITE, nullptr); | 99 MOJO_DEADLINE_INDEFINITE, nullptr); |
| 98 if (result != MOJO_RESULT_OK) { | 100 if (result != MOJO_RESULT_OK) { |
| 99 // If the consumer handle was closed, then treat as EOF. | 101 // If the consumer handle was closed, then treat as EOF. |
| 100 return result == MOJO_RESULT_FAILED_PRECONDITION; | 102 return result == MOJO_RESULT_FAILED_PRECONDITION; |
| 101 } | 103 } |
| 102 } else { | 104 } else { |
| 103 // If the consumer handle was closed, then treat as EOF. | 105 // If the consumer handle was closed, then treat as EOF. |
| 104 return result == MOJO_RESULT_FAILED_PRECONDITION; | 106 return result == MOJO_RESULT_FAILED_PRECONDITION; |
| 105 } | 107 } |
| 106 } | 108 } |
| 107 } | 109 } |
| 108 | 110 |
| 109 } // namespace common | 111 } // namespace common |
| 110 } // namespace mojo | 112 } // namespace mojo |
| OLD | NEW |