| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 DCHECK(is_open_); | 56 DCHECK(is_open_); |
| 57 is_open_ = false; | 57 is_open_ = false; |
| 58 message_queue_.Clear(); | 58 message_queue_.Clear(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void LocalMessagePipeEndpoint::CancelAllWaiters() { | 61 void LocalMessagePipeEndpoint::CancelAllWaiters() { |
| 62 DCHECK(is_open_); | 62 DCHECK(is_open_); |
| 63 waiter_list_.CancelAllWaiters(); | 63 waiter_list_.CancelAllWaiters(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 MojoResult LocalMessagePipeEndpoint::ReadMessage(void* bytes, | 66 MojoResult LocalMessagePipeEndpoint::ReadMessage( |
| 67 uint32_t* num_bytes, | 67 UserPointer<void> bytes, |
| 68 DispatcherVector* dispatchers, | 68 UserPointer<uint32_t> num_bytes, |
| 69 uint32_t* num_dispatchers, | 69 DispatcherVector* dispatchers, |
| 70 MojoReadMessageFlags flags) { | 70 uint32_t* num_dispatchers, |
| 71 MojoReadMessageFlags flags) { |
| 71 DCHECK(is_open_); | 72 DCHECK(is_open_); |
| 72 DCHECK(!dispatchers || dispatchers->empty()); | 73 DCHECK(!dispatchers || dispatchers->empty()); |
| 73 | 74 |
| 74 const uint32_t max_bytes = num_bytes ? *num_bytes : 0; | 75 const uint32_t max_bytes = num_bytes.IsNull() ? 0 : num_bytes.Get(); |
| 75 const uint32_t max_num_dispatchers = num_dispatchers ? *num_dispatchers : 0; | 76 const uint32_t max_num_dispatchers = num_dispatchers ? *num_dispatchers : 0; |
| 76 | 77 |
| 77 if (message_queue_.IsEmpty()) { | 78 if (message_queue_.IsEmpty()) { |
| 78 return is_peer_open_ ? MOJO_RESULT_SHOULD_WAIT : | 79 return is_peer_open_ ? MOJO_RESULT_SHOULD_WAIT : |
| 79 MOJO_RESULT_FAILED_PRECONDITION; | 80 MOJO_RESULT_FAILED_PRECONDITION; |
| 80 } | 81 } |
| 81 | 82 |
| 82 // TODO(vtl): If |flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD|, we could pop | 83 // TODO(vtl): If |flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD|, we could pop |
| 83 // and release the lock immediately. | 84 // and release the lock immediately. |
| 84 bool enough_space = true; | 85 bool enough_space = true; |
| 85 MessageInTransit* message = message_queue_.PeekMessage(); | 86 MessageInTransit* message = message_queue_.PeekMessage(); |
| 86 if (num_bytes) | 87 if (!num_bytes.IsNull()) |
| 87 *num_bytes = message->num_bytes(); | 88 num_bytes.Put(message->num_bytes()); |
| 88 if (message->num_bytes() <= max_bytes) | 89 if (message->num_bytes() <= max_bytes) |
| 89 memcpy(bytes, message->bytes(), message->num_bytes()); | 90 bytes.PutArray(message->bytes(), message->num_bytes()); |
| 90 else | 91 else |
| 91 enough_space = false; | 92 enough_space = false; |
| 92 | 93 |
| 93 if (DispatcherVector* queued_dispatchers = message->dispatchers()) { | 94 if (DispatcherVector* queued_dispatchers = message->dispatchers()) { |
| 94 if (num_dispatchers) | 95 if (num_dispatchers) |
| 95 *num_dispatchers = static_cast<uint32_t>(queued_dispatchers->size()); | 96 *num_dispatchers = static_cast<uint32_t>(queued_dispatchers->size()); |
| 96 if (enough_space) { | 97 if (enough_space) { |
| 97 if (queued_dispatchers->empty()) { | 98 if (queued_dispatchers->empty()) { |
| 98 // Nothing to do. | 99 // Nothing to do. |
| 99 } else if (queued_dispatchers->size() <= max_num_dispatchers) { | 100 } else if (queued_dispatchers->size() <= max_num_dispatchers) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (is_peer_open_) { | 157 if (is_peer_open_) { |
| 157 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; | 158 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; |
| 158 rv.satisfiable_signals |= | 159 rv.satisfiable_signals |= |
| 159 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE; | 160 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE; |
| 160 } | 161 } |
| 161 return rv; | 162 return rv; |
| 162 } | 163 } |
| 163 | 164 |
| 164 } // namespace system | 165 } // namespace system |
| 165 } // namespace mojo | 166 } // namespace mojo |
| OLD | NEW |