| 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 13 matching lines...) Expand all Loading... |
| 24 } | 24 } |
| 25 | 25 |
| 26 MessagePipeEndpoint::Type LocalMessagePipeEndpoint::GetType() const { | 26 MessagePipeEndpoint::Type LocalMessagePipeEndpoint::GetType() const { |
| 27 return kTypeLocal; | 27 return kTypeLocal; |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool LocalMessagePipeEndpoint::OnPeerClose() { | 30 bool LocalMessagePipeEndpoint::OnPeerClose() { |
| 31 DCHECK(is_open_); | 31 DCHECK(is_open_); |
| 32 DCHECK(is_peer_open_); | 32 DCHECK(is_peer_open_); |
| 33 | 33 |
| 34 WaitFlagsState old_state = GetWaitFlagsState(); | 34 HandleSignalsState old_state = GetHandleSignalsState(); |
| 35 is_peer_open_ = false; | 35 is_peer_open_ = false; |
| 36 WaitFlagsState new_state = GetWaitFlagsState(); | 36 HandleSignalsState new_state = GetHandleSignalsState(); |
| 37 | 37 |
| 38 if (!new_state.equals(old_state)) | 38 if (!new_state.equals(old_state)) |
| 39 waiter_list_.AwakeWaitersForStateChange(new_state); | 39 waiter_list_.AwakeWaitersForStateChange(new_state); |
| 40 | 40 |
| 41 return true; | 41 return true; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void LocalMessagePipeEndpoint::EnqueueMessage( | 44 void LocalMessagePipeEndpoint::EnqueueMessage( |
| 45 scoped_ptr<MessageInTransit> message) { | 45 scoped_ptr<MessageInTransit> message) { |
| 46 DCHECK(is_open_); | 46 DCHECK(is_open_); |
| 47 DCHECK(is_peer_open_); | 47 DCHECK(is_peer_open_); |
| 48 | 48 |
| 49 bool was_empty = message_queue_.IsEmpty(); | 49 bool was_empty = message_queue_.IsEmpty(); |
| 50 message_queue_.AddMessage(message.Pass()); | 50 message_queue_.AddMessage(message.Pass()); |
| 51 if (was_empty) | 51 if (was_empty) |
| 52 waiter_list_.AwakeWaitersForStateChange(GetWaitFlagsState()); | 52 waiter_list_.AwakeWaitersForStateChange(GetHandleSignalsState()); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void LocalMessagePipeEndpoint::Close() { | 55 void LocalMessagePipeEndpoint::Close() { |
| 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_); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 message = NULL; | 111 message = NULL; |
| 112 | 112 |
| 113 if (enough_space || (flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)) { | 113 if (enough_space || (flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)) { |
| 114 message_queue_.DiscardMessage(); | 114 message_queue_.DiscardMessage(); |
| 115 | 115 |
| 116 // Now it's empty, thus no longer readable. | 116 // Now it's empty, thus no longer readable. |
| 117 if (message_queue_.IsEmpty()) { | 117 if (message_queue_.IsEmpty()) { |
| 118 // It's currently not possible to wait for non-readability, but we should | 118 // It's currently not possible to wait for non-readability, but we should |
| 119 // do the state change anyway. | 119 // do the state change anyway. |
| 120 waiter_list_.AwakeWaitersForStateChange(GetWaitFlagsState()); | 120 waiter_list_.AwakeWaitersForStateChange(GetHandleSignalsState()); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 if (!enough_space) | 124 if (!enough_space) |
| 125 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 125 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 126 | 126 |
| 127 return MOJO_RESULT_OK; | 127 return MOJO_RESULT_OK; |
| 128 } | 128 } |
| 129 | 129 |
| 130 MojoResult LocalMessagePipeEndpoint::AddWaiter(Waiter* waiter, | 130 MojoResult LocalMessagePipeEndpoint::AddWaiter(Waiter* waiter, |
| 131 MojoHandleSignals signals, | 131 MojoHandleSignals signals, |
| 132 uint32_t context) { | 132 uint32_t context) { |
| 133 DCHECK(is_open_); | 133 DCHECK(is_open_); |
| 134 | 134 |
| 135 WaitFlagsState state = GetWaitFlagsState(); | 135 HandleSignalsState state = GetHandleSignalsState(); |
| 136 if (state.satisfies(signals)) | 136 if (state.satisfies(signals)) |
| 137 return MOJO_RESULT_ALREADY_EXISTS; | 137 return MOJO_RESULT_ALREADY_EXISTS; |
| 138 if (!state.can_satisfy(signals)) | 138 if (!state.can_satisfy(signals)) |
| 139 return MOJO_RESULT_FAILED_PRECONDITION; | 139 return MOJO_RESULT_FAILED_PRECONDITION; |
| 140 | 140 |
| 141 waiter_list_.AddWaiter(waiter, signals, context); | 141 waiter_list_.AddWaiter(waiter, signals, context); |
| 142 return MOJO_RESULT_OK; | 142 return MOJO_RESULT_OK; |
| 143 } | 143 } |
| 144 | 144 |
| 145 void LocalMessagePipeEndpoint::RemoveWaiter(Waiter* waiter) { | 145 void LocalMessagePipeEndpoint::RemoveWaiter(Waiter* waiter) { |
| 146 DCHECK(is_open_); | 146 DCHECK(is_open_); |
| 147 waiter_list_.RemoveWaiter(waiter); | 147 waiter_list_.RemoveWaiter(waiter); |
| 148 } | 148 } |
| 149 | 149 |
| 150 WaitFlagsState LocalMessagePipeEndpoint::GetWaitFlagsState() { | 150 HandleSignalsState LocalMessagePipeEndpoint::GetHandleSignalsState() { |
| 151 WaitFlagsState rv; | 151 HandleSignalsState rv; |
| 152 if (!message_queue_.IsEmpty()) { | 152 if (!message_queue_.IsEmpty()) { |
| 153 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 153 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
| 154 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 154 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
| 155 } | 155 } |
| 156 if (is_peer_open_) { | 156 if (is_peer_open_) { |
| 157 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; | 157 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; |
| 158 rv.satisfiable_signals |= | 158 rv.satisfiable_signals |= |
| 159 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE; | 159 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE; |
| 160 } | 160 } |
| 161 return rv; | 161 return rv; |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace system | 164 } // namespace system |
| 165 } // namespace mojo | 165 } // namespace mojo |
| OLD | NEW |