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" |
11 #include "mojo/system/message_in_transit.h" | 11 #include "mojo/system/message_in_transit.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 namespace system { | 14 namespace system { |
15 | 15 |
16 LocalMessagePipeEndpoint::LocalMessagePipeEndpoint() | 16 LocalMessagePipeEndpoint::LocalMessagePipeEndpoint() |
17 : is_open_(true), | 17 : is_open_(true), |
18 is_peer_open_(true) { | 18 is_peer_open_(true) { |
19 } | 19 } |
20 | 20 |
21 LocalMessagePipeEndpoint::~LocalMessagePipeEndpoint() { | 21 LocalMessagePipeEndpoint::~LocalMessagePipeEndpoint() { |
22 DCHECK(!is_open_); | 22 DCHECK(!is_open_); |
23 DCHECK(message_queue_.IsEmpty()); // Should be implied by not being open. | 23 DCHECK(message_queue_.IsEmpty()); // Should be implied by not being open. |
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 void LocalMessagePipeEndpoint::Close() { | 30 bool LocalMessagePipeEndpoint::OnPeerClose() { |
31 DCHECK(is_open_); | |
32 is_open_ = false; | |
33 message_queue_.Clear(); | |
34 } | |
35 | |
36 void LocalMessagePipeEndpoint::OnPeerClose() { | |
37 DCHECK(is_open_); | 31 DCHECK(is_open_); |
38 DCHECK(is_peer_open_); | 32 DCHECK(is_peer_open_); |
39 | 33 |
40 MojoWaitFlags old_satisfied_flags = SatisfiedFlags(); | 34 MojoWaitFlags old_satisfied_flags = SatisfiedFlags(); |
41 MojoWaitFlags old_satisfiable_flags = SatisfiableFlags(); | 35 MojoWaitFlags old_satisfiable_flags = SatisfiableFlags(); |
42 is_peer_open_ = false; | 36 is_peer_open_ = false; |
43 MojoWaitFlags new_satisfied_flags = SatisfiedFlags(); | 37 MojoWaitFlags new_satisfied_flags = SatisfiedFlags(); |
44 MojoWaitFlags new_satisfiable_flags = SatisfiableFlags(); | 38 MojoWaitFlags new_satisfiable_flags = SatisfiableFlags(); |
45 | 39 |
46 if (new_satisfied_flags != old_satisfied_flags || | 40 if (new_satisfied_flags != old_satisfied_flags || |
47 new_satisfiable_flags != old_satisfiable_flags) { | 41 new_satisfiable_flags != old_satisfiable_flags) { |
48 waiter_list_.AwakeWaitersForStateChange(new_satisfied_flags, | 42 waiter_list_.AwakeWaitersForStateChange(new_satisfied_flags, |
49 new_satisfiable_flags); | 43 new_satisfiable_flags); |
50 } | 44 } |
| 45 |
| 46 return true; |
51 } | 47 } |
52 | 48 |
53 void LocalMessagePipeEndpoint::EnqueueMessage( | 49 void LocalMessagePipeEndpoint::EnqueueMessage( |
54 scoped_ptr<MessageInTransit> message) { | 50 scoped_ptr<MessageInTransit> message) { |
55 DCHECK(is_open_); | 51 DCHECK(is_open_); |
56 DCHECK(is_peer_open_); | 52 DCHECK(is_peer_open_); |
57 | 53 |
58 bool was_empty = message_queue_.IsEmpty(); | 54 bool was_empty = message_queue_.IsEmpty(); |
59 message_queue_.AddMessage(message.Pass()); | 55 message_queue_.AddMessage(message.Pass()); |
60 if (was_empty) { | 56 if (was_empty) { |
61 waiter_list_.AwakeWaitersForStateChange(SatisfiedFlags(), | 57 waiter_list_.AwakeWaitersForStateChange(SatisfiedFlags(), |
62 SatisfiableFlags()); | 58 SatisfiableFlags()); |
63 } | 59 } |
64 } | 60 } |
65 | 61 |
| 62 void LocalMessagePipeEndpoint::Close() { |
| 63 DCHECK(is_open_); |
| 64 is_open_ = false; |
| 65 message_queue_.Clear(); |
| 66 } |
| 67 |
66 void LocalMessagePipeEndpoint::CancelAllWaiters() { | 68 void LocalMessagePipeEndpoint::CancelAllWaiters() { |
67 DCHECK(is_open_); | 69 DCHECK(is_open_); |
68 waiter_list_.CancelAllWaiters(); | 70 waiter_list_.CancelAllWaiters(); |
69 } | 71 } |
70 | 72 |
71 MojoResult LocalMessagePipeEndpoint::ReadMessage( | 73 MojoResult LocalMessagePipeEndpoint::ReadMessage( |
72 void* bytes, uint32_t* num_bytes, | 74 void* bytes, uint32_t* num_bytes, |
73 std::vector<scoped_refptr<Dispatcher> >* dispatchers, | 75 std::vector<scoped_refptr<Dispatcher> >* dispatchers, |
74 uint32_t* num_dispatchers, | 76 uint32_t* num_dispatchers, |
75 MojoReadMessageFlags flags) { | 77 MojoReadMessageFlags flags) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 MojoWaitFlags satisfiable_flags = 0; | 168 MojoWaitFlags satisfiable_flags = 0; |
167 if (!message_queue_.IsEmpty() || is_peer_open_) | 169 if (!message_queue_.IsEmpty() || is_peer_open_) |
168 satisfiable_flags |= MOJO_WAIT_FLAG_READABLE; | 170 satisfiable_flags |= MOJO_WAIT_FLAG_READABLE; |
169 if (is_peer_open_) | 171 if (is_peer_open_) |
170 satisfiable_flags |= MOJO_WAIT_FLAG_WRITABLE; | 172 satisfiable_flags |= MOJO_WAIT_FLAG_WRITABLE; |
171 return satisfiable_flags; | 173 return satisfiable_flags; |
172 } | 174 } |
173 | 175 |
174 } // namespace system | 176 } // namespace system |
175 } // namespace mojo | 177 } // namespace mojo |
OLD | NEW |