| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/public/bindings/lib/connector.h" | 5 #include "mojo/public/bindings/lib/connector.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 break; | 88 break; |
| 89 } | 89 } |
| 90 | 90 |
| 91 Message message; | 91 Message message; |
| 92 message.data = static_cast<MessageData*>(malloc(num_bytes)); | 92 message.data = static_cast<MessageData*>(malloc(num_bytes)); |
| 93 message.handles.resize(num_handles); | 93 message.handles.resize(num_handles); |
| 94 | 94 |
| 95 rv = ReadMessage(message_pipe_, | 95 rv = ReadMessage(message_pipe_, |
| 96 message.data, | 96 message.data, |
| 97 &num_bytes, | 97 &num_bytes, |
| 98 &message.handles[0], | 98 message.handles.empty() ? NULL : &message.handles[0], |
| 99 &num_handles, | 99 &num_handles, |
| 100 MOJO_READ_MESSAGE_FLAG_NONE); | 100 MOJO_READ_MESSAGE_FLAG_NONE); |
| 101 if (rv != MOJO_RESULT_OK) { | 101 if (rv != MOJO_RESULT_OK) { |
| 102 error_ = true; | 102 error_ = true; |
| 103 break; | 103 break; |
| 104 } | 104 } |
| 105 | 105 |
| 106 incoming_receiver_->Accept(&message); | 106 incoming_receiver_->Accept(&message); |
| 107 } | 107 } |
| 108 } | 108 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 void Connector::WriteOne(Message* message, bool* wait_to_write) { | 123 void Connector::WriteOne(Message* message, bool* wait_to_write) { |
| 124 // TODO(darin): WriteMessage will eventually start generating an error that | 124 // TODO(darin): WriteMessage will eventually start generating an error that |
| 125 // it cannot accept more data. In that case, we'll need to wait on the pipe | 125 // it cannot accept more data. In that case, we'll need to wait on the pipe |
| 126 // to determine when we can try writing again. This flag will be set to true | 126 // to determine when we can try writing again. This flag will be set to true |
| 127 // in that case. | 127 // in that case. |
| 128 *wait_to_write = false; | 128 *wait_to_write = false; |
| 129 | 129 |
| 130 MojoResult rv = WriteMessage(message_pipe_, | 130 MojoResult rv = WriteMessage( |
| 131 message->data, | 131 message_pipe_, |
| 132 message->data->header.num_bytes, | 132 message->data, |
| 133 &message->handles[0], | 133 message->data->header.num_bytes, |
| 134 static_cast<uint32_t>(message->handles.size()), | 134 message->handles.empty() ? NULL : &message->handles[0], |
| 135 MOJO_WRITE_MESSAGE_FLAG_NONE); | 135 static_cast<uint32_t>(message->handles.size()), |
| 136 MOJO_WRITE_MESSAGE_FLAG_NONE); |
| 136 if (rv == MOJO_RESULT_OK) { | 137 if (rv == MOJO_RESULT_OK) { |
| 137 // The handles were successfully transferred, so we don't need the message | 138 // The handles were successfully transferred, so we don't need the message |
| 138 // to track their lifetime any longer. | 139 // to track their lifetime any longer. |
| 139 message->handles.clear(); | 140 message->handles.clear(); |
| 140 } else { | 141 } else { |
| 141 error_ = true; | 142 error_ = true; |
| 142 } | 143 } |
| 143 } | 144 } |
| 144 | 145 |
| 145 // ---------------------------------------------------------------------------- | 146 // ---------------------------------------------------------------------------- |
| (...skipping 18 matching lines...) Expand all Loading... |
| 164 } | 165 } |
| 165 | 166 |
| 166 void Connector::Callback::OnHandleReady(MojoResult result) { | 167 void Connector::Callback::OnHandleReady(MojoResult result) { |
| 167 assert(owner_); | 168 assert(owner_); |
| 168 Connector* owner = NULL; | 169 Connector* owner = NULL; |
| 169 std::swap(owner, owner_); | 170 std::swap(owner, owner_); |
| 170 owner->OnHandleReady(this, result); | 171 owner->OnHandleReady(this, result); |
| 171 } | 172 } |
| 172 | 173 |
| 173 } // namespace mojo | 174 } // namespace mojo |
| OLD | NEW |