Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1164)

Side by Side Diff: mojo/system/local_message_pipe_endpoint.cc

Issue 68993005: Mojo: More plumbing to support sending handles over MessagePipes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/system/local_message_pipe_endpoint.h ('k') | mojo/system/message_pipe.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_in_transit.h" 10 #include "mojo/system/message_in_transit.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 if (new_satisfied_flags != old_satisfied_flags || 45 if (new_satisfied_flags != old_satisfied_flags ||
46 new_satisfiable_flags != old_satisfiable_flags) { 46 new_satisfiable_flags != old_satisfiable_flags) {
47 waiter_list_.AwakeWaitersForStateChange(new_satisfied_flags, 47 waiter_list_.AwakeWaitersForStateChange(new_satisfied_flags,
48 new_satisfiable_flags); 48 new_satisfiable_flags);
49 } 49 }
50 50
51 return true; 51 return true;
52 } 52 }
53 53
54 MojoResult LocalMessagePipeEndpoint::EnqueueMessage(MessageInTransit* message) { 54 MojoResult LocalMessagePipeEndpoint::EnqueueMessage(
55 MessageInTransit* message,
56 const std::vector<Dispatcher*>* dispatchers) {
55 DCHECK(is_open_); 57 DCHECK(is_open_);
56 DCHECK(is_peer_open_); 58 DCHECK(is_peer_open_);
57 59
60 // TODO(vtl)
61 if (dispatchers) {
62 message->Destroy();
63 return MOJO_RESULT_UNIMPLEMENTED;
64 }
65
58 bool was_empty = message_queue_.empty(); 66 bool was_empty = message_queue_.empty();
59 message_queue_.push_back(message); 67 message_queue_.push_back(message);
60 if (was_empty) { 68 if (was_empty) {
61 waiter_list_.AwakeWaitersForStateChange(SatisfiedFlags(), 69 waiter_list_.AwakeWaitersForStateChange(SatisfiedFlags(),
62 SatisfiableFlags()); 70 SatisfiableFlags());
63 } 71 }
64 72
65 return MOJO_RESULT_OK; 73 return MOJO_RESULT_OK;
66 } 74 }
67 75
68 void LocalMessagePipeEndpoint::CancelAllWaiters() { 76 void LocalMessagePipeEndpoint::CancelAllWaiters() {
69 DCHECK(is_open_); 77 DCHECK(is_open_);
70 waiter_list_.CancelAllWaiters(); 78 waiter_list_.CancelAllWaiters();
71 } 79 }
72 80
81 // TODO(vtl): Support receiving handles.
73 MojoResult LocalMessagePipeEndpoint::ReadMessage( 82 MojoResult LocalMessagePipeEndpoint::ReadMessage(
74 void* bytes, uint32_t* num_bytes, 83 void* bytes, uint32_t* num_bytes,
75 MojoHandle* handles, uint32_t* num_handles, 84 uint32_t max_num_dispatchers,
85 std::vector<scoped_refptr<Dispatcher> >* dispatchers,
76 MojoReadMessageFlags flags) { 86 MojoReadMessageFlags flags) {
77 DCHECK(is_open_); 87 DCHECK(is_open_);
78 88
79 const uint32_t max_bytes = num_bytes ? *num_bytes : 0; 89 const uint32_t max_bytes = num_bytes ? *num_bytes : 0;
80 // TODO(vtl): We'll need this later: 90 // TODO(vtl): We'll need this later:
81 // const uint32_t max_handles = num_handles ? *num_handles : 0; 91 // const uint32_t max_handles = num_handles ? *num_handles : 0;
82 92
83 if (message_queue_.empty()) { 93 if (message_queue_.empty()) {
84 return is_peer_open_ ? MOJO_RESULT_NOT_FOUND : 94 return is_peer_open_ ? MOJO_RESULT_NOT_FOUND :
85 MOJO_RESULT_FAILED_PRECONDITION; 95 MOJO_RESULT_FAILED_PRECONDITION;
86 } 96 }
87 97
88 // TODO(vtl): If |flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD|, we could pop 98 // TODO(vtl): If |flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD|, we could pop
89 // and release the lock immediately. 99 // and release the lock immediately.
90 bool not_enough_space = false; 100 bool not_enough_space = false;
91 MessageInTransit* const message = message_queue_.front(); 101 MessageInTransit* const message = message_queue_.front();
92 if (num_bytes) 102 if (num_bytes)
93 *num_bytes = message->data_size(); 103 *num_bytes = message->data_size();
94 if (message->data_size() <= max_bytes) 104 if (message->data_size() <= max_bytes)
95 memcpy(bytes, message->data(), message->data_size()); 105 memcpy(bytes, message->data(), message->data_size());
96 else 106 else
97 not_enough_space = true; 107 not_enough_space = true;
98 108
99 // TODO(vtl): Support receiving handles.
100 if (num_handles)
101 *num_handles = 0;
102
103 if (!not_enough_space || (flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)) { 109 if (!not_enough_space || (flags & MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)) {
104 message_queue_.pop_front(); 110 message_queue_.pop_front();
105 message->Destroy(); 111 message->Destroy();
106 112
107 // Now it's empty, thus no longer readable. 113 // Now it's empty, thus no longer readable.
108 if (message_queue_.empty()) { 114 if (message_queue_.empty()) {
109 // It's currently not possible to wait for non-readability, but we should 115 // It's currently not possible to wait for non-readability, but we should
110 // do the state change anyway. 116 // do the state change anyway.
111 waiter_list_.AwakeWaitersForStateChange(SatisfiedFlags(), 117 waiter_list_.AwakeWaitersForStateChange(SatisfiedFlags(),
112 SatisfiableFlags()); 118 SatisfiableFlags());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 MojoWaitFlags satisfiable_flags = 0; 157 MojoWaitFlags satisfiable_flags = 0;
152 if (!message_queue_.empty() || is_peer_open_) 158 if (!message_queue_.empty() || is_peer_open_)
153 satisfiable_flags |= MOJO_WAIT_FLAG_READABLE; 159 satisfiable_flags |= MOJO_WAIT_FLAG_READABLE;
154 if (is_peer_open_) 160 if (is_peer_open_)
155 satisfiable_flags |= MOJO_WAIT_FLAG_WRITABLE; 161 satisfiable_flags |= MOJO_WAIT_FLAG_WRITABLE;
156 return satisfiable_flags; 162 return satisfiable_flags;
157 } 163 }
158 164
159 } // namespace system 165 } // namespace system
160 } // namespace mojo 166 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/local_message_pipe_endpoint.h ('k') | mojo/system/message_pipe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698