| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/edk/system/message_pipe_dispatcher.h" | 5 #include "mojo/edk/system/message_pipe_dispatcher.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "mojo/edk/embedder/embedder_internal.h" | 12 #include "mojo/edk/embedder/embedder_internal.h" |
| 13 #include "mojo/edk/system/core.h" | 13 #include "mojo/edk/system/core.h" |
| 14 #include "mojo/edk/system/node_controller.h" | 14 #include "mojo/edk/system/node_controller.h" |
| 15 #include "mojo/edk/system/ports_message.h" | 15 #include "mojo/edk/system/ports_message.h" |
| 16 #include "mojo/edk/system/request_context.h" |
| 16 #include "mojo/public/c/system/macros.h" | 17 #include "mojo/public/c/system/macros.h" |
| 17 | 18 |
| 18 namespace mojo { | 19 namespace mojo { |
| 19 namespace edk { | 20 namespace edk { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Header attached to every message sent over a message pipe. | 24 // Header attached to every message sent over a message pipe. |
| 24 struct MOJO_ALIGNAS(8) MessageHeader { | 25 struct MOJO_ALIGNAS(8) MessageHeader { |
| 25 // The number of serialized dispatchers included in this header. | 26 // The number of serialized dispatchers included in this header. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 return Type::MESSAGE_PIPE; | 91 return Type::MESSAGE_PIPE; |
| 91 } | 92 } |
| 92 | 93 |
| 93 MojoResult MessagePipeDispatcher::Close() { | 94 MojoResult MessagePipeDispatcher::Close() { |
| 94 base::AutoLock lock(signal_lock_); | 95 base::AutoLock lock(signal_lock_); |
| 95 DVLOG(1) << "Closing message pipe " << pipe_id_ << " endpoint " << endpoint_ | 96 DVLOG(1) << "Closing message pipe " << pipe_id_ << " endpoint " << endpoint_ |
| 96 << " [port=" << port_.name() << "]"; | 97 << " [port=" << port_.name() << "]"; |
| 97 return CloseNoLock(); | 98 return CloseNoLock(); |
| 98 } | 99 } |
| 99 | 100 |
| 101 MojoResult MessagePipeDispatcher::Watch(MojoHandleSignals signals, |
| 102 const Watcher::WatchCallback& callback, |
| 103 uintptr_t context) { |
| 104 base::AutoLock lock(signal_lock_); |
| 105 |
| 106 if (port_closed_ || in_transit_) |
| 107 return MOJO_RESULT_INVALID_ARGUMENT; |
| 108 |
| 109 return awakables_.AddWatcher( |
| 110 signals, callback, context, GetHandleSignalsStateNoLock()); |
| 111 } |
| 112 |
| 113 MojoResult MessagePipeDispatcher::CancelWatch(uintptr_t context) { |
| 114 base::AutoLock lock(signal_lock_); |
| 115 |
| 116 if (port_closed_ || in_transit_) |
| 117 return MOJO_RESULT_INVALID_ARGUMENT; |
| 118 |
| 119 return awakables_.RemoveWatcher(context); |
| 120 } |
| 121 |
| 100 MojoResult MessagePipeDispatcher::WriteMessage( | 122 MojoResult MessagePipeDispatcher::WriteMessage( |
| 101 const void* bytes, | 123 const void* bytes, |
| 102 uint32_t num_bytes, | 124 uint32_t num_bytes, |
| 103 const DispatcherInTransit* dispatchers, | 125 const DispatcherInTransit* dispatchers, |
| 104 uint32_t num_dispatchers, | 126 uint32_t num_dispatchers, |
| 105 MojoWriteMessageFlags flags) { | 127 MojoWriteMessageFlags flags) { |
| 106 | 128 |
| 107 { | 129 { |
| 108 base::AutoLock lock(signal_lock_); | 130 base::AutoLock lock(signal_lock_); |
| 109 if (port_closed_ || in_transit_) | 131 if (port_closed_ || in_transit_) |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; | 594 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; |
| 573 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 595 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
| 574 } else { | 596 } else { |
| 575 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 597 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 576 } | 598 } |
| 577 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 599 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 578 return rv; | 600 return rv; |
| 579 } | 601 } |
| 580 | 602 |
| 581 void MessagePipeDispatcher::OnPortStatusChanged() { | 603 void MessagePipeDispatcher::OnPortStatusChanged() { |
| 604 RequestContext request_context; |
| 605 |
| 582 base::AutoLock lock(signal_lock_); | 606 base::AutoLock lock(signal_lock_); |
| 583 | 607 |
| 584 // We stop observing our port as soon as it's transferred, but this can race | 608 // We stop observing our port as soon as it's transferred, but this can race |
| 585 // with events which are raised right before that happens. This is fine to | 609 // with events which are raised right before that happens. This is fine to |
| 586 // ignore. | 610 // ignore. |
| 587 if (port_transferred_) | 611 if (port_transferred_) |
| 588 return; | 612 return; |
| 589 | 613 |
| 590 #if !defined(NDEBUG) | 614 #if !defined(NDEBUG) |
| 591 ports::PortStatus port_status; | 615 ports::PortStatus port_status; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 606 DVLOG(1) << "Peer closure detected on message pipe " << pipe_id_ | 630 DVLOG(1) << "Peer closure detected on message pipe " << pipe_id_ |
| 607 << " endpoint " << endpoint_ << " [port=" << port_.name() << "]"; | 631 << " endpoint " << endpoint_ << " [port=" << port_.name() << "]"; |
| 608 } | 632 } |
| 609 #endif | 633 #endif |
| 610 | 634 |
| 611 awakables_.AwakeForStateChange(GetHandleSignalsStateNoLock()); | 635 awakables_.AwakeForStateChange(GetHandleSignalsStateNoLock()); |
| 612 } | 636 } |
| 613 | 637 |
| 614 } // namespace edk | 638 } // namespace edk |
| 615 } // namespace mojo | 639 } // namespace mojo |
| OLD | NEW |