OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ports/node.h" | 5 #include "mojo/edk/system/ports/node.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 CHECK(false) << "Oops: " << message; | 23 CHECK(false) << "Oops: " << message; |
24 return error_code; | 24 return error_code; |
25 } | 25 } |
26 | 26 |
27 #define OOPS(x) DebugError(#x, x) | 27 #define OOPS(x) DebugError(#x, x) |
28 | 28 |
29 bool CanAcceptMoreMessages(const Port* port) { | 29 bool CanAcceptMoreMessages(const Port* port) { |
30 // Have we already doled out the last message (i.e., do we expect to NOT | 30 // Have we already doled out the last message (i.e., do we expect to NOT |
31 // receive further messages)? | 31 // receive further messages)? |
32 uint64_t next_sequence_num = port->message_queue.next_sequence_num(); | 32 uint64_t next_sequence_num = port->message_queue.next_sequence_num(); |
| 33 if (port->state == Port::kClosed) |
| 34 return false; |
33 if (port->peer_closed || port->remove_proxy_on_last_message) { | 35 if (port->peer_closed || port->remove_proxy_on_last_message) { |
34 if (port->last_sequence_num_to_receive == next_sequence_num - 1) | 36 if (port->last_sequence_num_to_receive == next_sequence_num - 1) |
35 return false; | 37 return false; |
36 } | 38 } |
37 return true; | 39 return true; |
38 } | 40 } |
39 | 41 |
40 } // namespace | 42 } // namespace |
41 | 43 |
42 Node::Node(const NodeName& name, NodeDelegate* delegate) | 44 Node::Node(const NodeName& name, NodeDelegate* delegate) |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 const scoped_refptr<Port>& port) { | 816 const scoped_refptr<Port>& port) { |
815 base::AutoLock lock(ports_lock_); | 817 base::AutoLock lock(ports_lock_); |
816 | 818 |
817 if (!ports_.insert(std::make_pair(port_name, port)).second) | 819 if (!ports_.insert(std::make_pair(port_name, port)).second) |
818 return OOPS(ERROR_PORT_EXISTS); // Suggests a bad UUID generator. | 820 return OOPS(ERROR_PORT_EXISTS); // Suggests a bad UUID generator. |
819 | 821 |
820 DVLOG(2) << "Created port " << port_name << "@" << name_; | 822 DVLOG(2) << "Created port " << port_name << "@" << name_; |
821 return OK; | 823 return OK; |
822 } | 824 } |
823 | 825 |
824 void Node::ErasePort(const PortName& port_name) { | |
825 base::AutoLock lock(ports_lock_); | |
826 return ErasePort_Locked(port_name); | |
827 } | |
828 | |
829 void Node::ErasePort_Locked(const PortName& port_name) { | 826 void Node::ErasePort_Locked(const PortName& port_name) { |
830 ports_lock_.AssertAcquired(); | 827 ports_lock_.AssertAcquired(); |
831 ports_.erase(port_name); | 828 ports_.erase(port_name); |
832 DVLOG(2) << "Deleted port " << port_name << "@" << name_; | 829 DVLOG(2) << "Deleted port " << port_name << "@" << name_; |
833 } | 830 } |
834 | 831 |
835 scoped_refptr<Port> Node::GetPort(const PortName& port_name) { | 832 scoped_refptr<Port> Node::GetPort(const PortName& port_name) { |
836 base::AutoLock lock(ports_lock_); | 833 base::AutoLock lock(ports_lock_); |
837 return GetPort_Locked(port_name); | 834 return GetPort_Locked(port_name); |
838 } | 835 } |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 | 1237 |
1241 if (num_data_bytes) | 1238 if (num_data_bytes) |
1242 memcpy(header + 1, data, num_data_bytes); | 1239 memcpy(header + 1, data, num_data_bytes); |
1243 | 1240 |
1244 return message; | 1241 return message; |
1245 } | 1242 } |
1246 | 1243 |
1247 } // namespace ports | 1244 } // namespace ports |
1248 } // namespace edk | 1245 } // namespace edk |
1249 } // namespace mojo | 1246 } // namespace mojo |
OLD | NEW |