| 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/message_pipe.h" | 5 #include "mojo/system/message_pipe.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/system/channel.h" | 8 #include "mojo/system/channel.h" |
| 9 #include "mojo/system/local_message_pipe_endpoint.h" | 9 #include "mojo/system/local_message_pipe_endpoint.h" |
| 10 #include "mojo/system/message_in_transit.h" | 10 #include "mojo/system/message_in_transit.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 | 66 |
| 67 // TODO(vtl): Handle flags. | 67 // TODO(vtl): Handle flags. |
| 68 MojoResult MessagePipe::WriteMessage( | 68 MojoResult MessagePipe::WriteMessage( |
| 69 unsigned port, | 69 unsigned port, |
| 70 const void* bytes, | 70 const void* bytes, |
| 71 uint32_t num_bytes, | 71 uint32_t num_bytes, |
| 72 std::vector<DispatcherTransport>* transports, | 72 std::vector<DispatcherTransport>* transports, |
| 73 MojoWriteMessageFlags flags) { | 73 MojoWriteMessageFlags flags) { |
| 74 DCHECK(port == 0 || port == 1); | 74 DCHECK(port == 0 || port == 1); |
| 75 uint32_t num_handles = | |
| 76 transports ? static_cast<uint32_t>(transports->size()) : 0; | |
| 77 return EnqueueMessageInternal( | 75 return EnqueueMessageInternal( |
| 78 GetPeerPort(port), | 76 GetPeerPort(port), |
| 79 make_scoped_ptr(new MessageInTransit( | 77 make_scoped_ptr(new MessageInTransit( |
| 80 MessageInTransit::kTypeMessagePipeEndpoint, | 78 MessageInTransit::kTypeMessagePipeEndpoint, |
| 81 MessageInTransit::kSubtypeMessagePipeEndpointData, | 79 MessageInTransit::kSubtypeMessagePipeEndpointData, |
| 82 num_bytes, num_handles, bytes)), | 80 num_bytes, |
| 81 bytes)), |
| 83 transports); | 82 transports); |
| 84 } | 83 } |
| 85 | 84 |
| 86 MojoResult MessagePipe::ReadMessage( | 85 MojoResult MessagePipe::ReadMessage( |
| 87 unsigned port, | 86 unsigned port, |
| 88 void* bytes, | 87 void* bytes, |
| 89 uint32_t* num_bytes, | 88 uint32_t* num_bytes, |
| 90 std::vector<scoped_refptr<Dispatcher> >* dispatchers, | 89 std::vector<scoped_refptr<Dispatcher> >* dispatchers, |
| 91 uint32_t* num_dispatchers, | 90 uint32_t* num_dispatchers, |
| 92 MojoReadMessageFlags flags) { | 91 MojoReadMessageFlags flags) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 // The destination port need not be open, unlike the source port. | 218 // The destination port need not be open, unlike the source port. |
| 220 if (!endpoints_[port].get()) | 219 if (!endpoints_[port].get()) |
| 221 return MOJO_RESULT_FAILED_PRECONDITION; | 220 return MOJO_RESULT_FAILED_PRECONDITION; |
| 222 | 221 |
| 223 if (transports) { | 222 if (transports) { |
| 224 MojoResult result = AttachTransportsNoLock(port, message.get(), transports); | 223 MojoResult result = AttachTransportsNoLock(port, message.get(), transports); |
| 225 if (result != MOJO_RESULT_OK) | 224 if (result != MOJO_RESULT_OK) |
| 226 return result; | 225 return result; |
| 227 } | 226 } |
| 228 | 227 |
| 229 if (message->has_dispatchers()) | |
| 230 DCHECK_EQ(message->dispatchers()->size(), message->num_handles()); | |
| 231 | |
| 232 // The endpoint's |EnqueueMessage()| may not report failure. | 228 // The endpoint's |EnqueueMessage()| may not report failure. |
| 233 endpoints_[port]->EnqueueMessage(message.Pass()); | 229 endpoints_[port]->EnqueueMessage(message.Pass()); |
| 234 return MOJO_RESULT_OK; | 230 return MOJO_RESULT_OK; |
| 235 } | 231 } |
| 236 | 232 |
| 237 MojoResult MessagePipe::AttachTransportsNoLock( | 233 MojoResult MessagePipe::AttachTransportsNoLock( |
| 238 unsigned port, | 234 unsigned port, |
| 239 MessageInTransit* message, | 235 MessageInTransit* message, |
| 240 std::vector<DispatcherTransport>* transports) { | 236 std::vector<DispatcherTransport>* transports) { |
| 241 DCHECK(!message->has_dispatchers()); | 237 DCHECK(!message->has_dispatchers()); |
| 242 DCHECK_EQ(transports->size(), message->num_handles()); | |
| 243 | 238 |
| 244 // You're not allowed to send either handle to a message pipe over the message | 239 // You're not allowed to send either handle to a message pipe over the message |
| 245 // pipe, so check for this. (The case of trying to write a handle to itself is | 240 // pipe, so check for this. (The case of trying to write a handle to itself is |
| 246 // taken care of by |Core|. That case kind of makes sense, but leads to | 241 // taken care of by |Core|. That case kind of makes sense, but leads to |
| 247 // complications if, e.g., both sides try to do the same thing with their | 242 // complications if, e.g., both sides try to do the same thing with their |
| 248 // respective handles simultaneously. The other case, of trying to write the | 243 // respective handles simultaneously. The other case, of trying to write the |
| 249 // peer handle to a handle, doesn't make sense -- since no handle will be | 244 // peer handle to a handle, doesn't make sense -- since no handle will be |
| 250 // available to read the message from.) | 245 // available to read the message from.) |
| 251 for (size_t i = 0; i < transports->size(); i++) { | 246 for (size_t i = 0; i < transports->size(); i++) { |
| 252 if (!(*transports)[i].is_valid()) | 247 if (!(*transports)[i].is_valid()) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 283 MojoResult MessagePipe::HandleControlMessage( | 278 MojoResult MessagePipe::HandleControlMessage( |
| 284 unsigned /*port*/, | 279 unsigned /*port*/, |
| 285 scoped_ptr<MessageInTransit> message) { | 280 scoped_ptr<MessageInTransit> message) { |
| 286 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " | 281 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " |
| 287 << message->subtype(); | 282 << message->subtype(); |
| 288 return MOJO_RESULT_UNKNOWN; | 283 return MOJO_RESULT_UNKNOWN; |
| 289 } | 284 } |
| 290 | 285 |
| 291 } // namespace system | 286 } // namespace system |
| 292 } // namespace mojo | 287 } // namespace mojo |
| OLD | NEW |