| 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/system/local_message_pipe_endpoint.h" | 5 #include "mojo/system/local_message_pipe_endpoint.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "mojo/system/dispatcher.h" | 10 #include "mojo/system/dispatcher.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 DCHECK(is_open_); | 63 DCHECK(is_open_); |
| 64 is_open_ = false; | 64 is_open_ = false; |
| 65 message_queue_.Clear(); | 65 message_queue_.Clear(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void LocalMessagePipeEndpoint::CancelAllWaiters() { | 68 void LocalMessagePipeEndpoint::CancelAllWaiters() { |
| 69 DCHECK(is_open_); | 69 DCHECK(is_open_); |
| 70 waiter_list_.CancelAllWaiters(); | 70 waiter_list_.CancelAllWaiters(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 MojoResult LocalMessagePipeEndpoint::ReadMessage( | 73 MojoResult LocalMessagePipeEndpoint::ReadMessage(void* bytes, |
| 74 void* bytes, uint32_t* num_bytes, | 74 uint32_t* num_bytes, |
| 75 std::vector<scoped_refptr<Dispatcher> >* dispatchers, | 75 DispatcherVector* dispatchers, |
| 76 uint32_t* num_dispatchers, | 76 uint32_t* num_dispatchers, |
| 77 MojoReadMessageFlags flags) { | 77 MojoReadMessageFlags flags) { |
| 78 DCHECK(is_open_); | 78 DCHECK(is_open_); |
| 79 DCHECK(!dispatchers || dispatchers->empty()); | 79 DCHECK(!dispatchers || dispatchers->empty()); |
| 80 | 80 |
| 81 const uint32_t max_bytes = num_bytes ? *num_bytes : 0; | 81 const uint32_t max_bytes = num_bytes ? *num_bytes : 0; |
| 82 const uint32_t max_num_dispatchers = num_dispatchers ? *num_dispatchers : 0; | 82 const uint32_t max_num_dispatchers = num_dispatchers ? *num_dispatchers : 0; |
| 83 | 83 |
| 84 if (message_queue_.IsEmpty()) { | 84 if (message_queue_.IsEmpty()) { |
| 85 return is_peer_open_ ? MOJO_RESULT_SHOULD_WAIT : | 85 return is_peer_open_ ? MOJO_RESULT_SHOULD_WAIT : |
| 86 MOJO_RESULT_FAILED_PRECONDITION; | 86 MOJO_RESULT_FAILED_PRECONDITION; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // TODO(vtl): If |flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD|, we could pop | 89 // TODO(vtl): If |flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD|, we could pop |
| 90 // and release the lock immediately. | 90 // and release the lock immediately. |
| 91 bool enough_space = true; | 91 bool enough_space = true; |
| 92 MessageInTransit* message = message_queue_.PeekMessage(); | 92 MessageInTransit* message = message_queue_.PeekMessage(); |
| 93 if (num_bytes) | 93 if (num_bytes) |
| 94 *num_bytes = message->num_bytes(); | 94 *num_bytes = message->num_bytes(); |
| 95 if (message->num_bytes() <= max_bytes) | 95 if (message->num_bytes() <= max_bytes) |
| 96 memcpy(bytes, message->bytes(), message->num_bytes()); | 96 memcpy(bytes, message->bytes(), message->num_bytes()); |
| 97 else | 97 else |
| 98 enough_space = false; | 98 enough_space = false; |
| 99 | 99 |
| 100 if (std::vector<scoped_refptr<Dispatcher> >* queued_dispatchers = | 100 if (DispatcherVector* queued_dispatchers = message->dispatchers()) { |
| 101 message->dispatchers()) { | |
| 102 if (num_dispatchers) | 101 if (num_dispatchers) |
| 103 *num_dispatchers = static_cast<uint32_t>(queued_dispatchers->size()); | 102 *num_dispatchers = static_cast<uint32_t>(queued_dispatchers->size()); |
| 104 if (enough_space) { | 103 if (enough_space) { |
| 105 if (queued_dispatchers->empty()) { | 104 if (queued_dispatchers->empty()) { |
| 106 // Nothing to do. | 105 // Nothing to do. |
| 107 } else if (queued_dispatchers->size() <= max_num_dispatchers) { | 106 } else if (queued_dispatchers->size() <= max_num_dispatchers) { |
| 108 DCHECK(dispatchers); | 107 DCHECK(dispatchers); |
| 109 dispatchers->swap(*queued_dispatchers); | 108 dispatchers->swap(*queued_dispatchers); |
| 110 } else { | 109 } else { |
| 111 enough_space = false; | 110 enough_space = false; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 MojoWaitFlags satisfiable_flags = 0; | 167 MojoWaitFlags satisfiable_flags = 0; |
| 169 if (!message_queue_.IsEmpty() || is_peer_open_) | 168 if (!message_queue_.IsEmpty() || is_peer_open_) |
| 170 satisfiable_flags |= MOJO_WAIT_FLAG_READABLE; | 169 satisfiable_flags |= MOJO_WAIT_FLAG_READABLE; |
| 171 if (is_peer_open_) | 170 if (is_peer_open_) |
| 172 satisfiable_flags |= MOJO_WAIT_FLAG_WRITABLE; | 171 satisfiable_flags |= MOJO_WAIT_FLAG_WRITABLE; |
| 173 return satisfiable_flags; | 172 return satisfiable_flags; |
| 174 } | 173 } |
| 175 | 174 |
| 176 } // namespace system | 175 } // namespace system |
| 177 } // namespace mojo | 176 } // namespace mojo |
| OLD | NEW |