diff options
author | Mark Mentovai <mark@chromium.org> | 2014-11-21 11:51:08 -0500 |
---|---|---|
committer | Mark Mentovai <mark@chromium.org> | 2014-11-21 16:52:32 +0000 |
commit | 34497e9a4083ca4c47ea50d715d4d7fe9c375aa7 (patch) | |
tree | d8cf2f887e3fb2d30ff573c5d0530c5a8846b817 /base/mac | |
parent | 574b801fe54f36919a49c9f5c90b11ce20e880f0 (diff) | |
download | chromium_src-34497e9a4083ca4c47ea50d715d4d7fe9c375aa7.zip chromium_src-34497e9a4083ca4c47ea50d715d4d7fe9c375aa7.tar.gz chromium_src-34497e9a4083ca4c47ea50d715d4d7fe9c375aa7.tar.bz2 |
Add base::mac::ScopedMachPortSet.
Contrary to its documentation, kqueue()'s EVFILT_MACHPORT doesn't work
with raw Mach receive rights, it only works with port sets. It's easy
enough to add a receive right to a port set, but we should have a scoper
to dispose of the port set.
R=rsesek@chromium.org
Review URL: https://codereview.chromium.org/749693002
Cr-Commit-Position: refs/heads/master@{#305228}
Diffstat (limited to 'base/mac')
-rw-r--r-- | base/mac/scoped_mach_port.cc | 8 | ||||
-rw-r--r-- | base/mac/scoped_mach_port.h | 21 |
2 files changed, 29 insertions, 0 deletions
diff --git a/base/mac/scoped_mach_port.cc b/base/mac/scoped_mach_port.cc index de94602..13307f2 100644 --- a/base/mac/scoped_mach_port.cc +++ b/base/mac/scoped_mach_port.cc @@ -25,6 +25,14 @@ void ReceiveRightTraits::Free(mach_port_t port) { << "ScopedMachReceiveRight mach_port_mod_refs"; } +// static +void PortSetTraits::Free(mach_port_t port) { + kern_return_t kr = + mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_PORT_SET, -1); + MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) + << "ScopedMachPortSet mach_port_mod_refs"; +} + } // namespace internal } // namespace mac } // namespace base diff --git a/base/mac/scoped_mach_port.h b/base/mac/scoped_mach_port.h index 36087c9..9ef90d6 100644 --- a/base/mac/scoped_mach_port.h +++ b/base/mac/scoped_mach_port.h @@ -31,6 +31,14 @@ struct BASE_EXPORT ReceiveRightTraits { static void Free(mach_port_t port); }; +struct PortSetTraits { + static mach_port_t InvalidValue() { + return MACH_PORT_NULL; + } + + static void Free(mach_port_t port); +}; + } // namespace internal // A scoper for handling a Mach port that names a send right. Send rights are @@ -59,6 +67,19 @@ class BASE_EXPORT ScopedMachReceiveRight : operator mach_port_t() const { return get(); } }; +// A scoper for handling a Mach port set. A port set can have only one +// reference. This takes ownership of that single reference on construction and +// destroys the port set on destruction. Destroying a port set does not destroy +// the receive rights that are members of the port set. +class BASE_EXPORT ScopedMachPortSet : + public ScopedGeneric<mach_port_t, internal::PortSetTraits> { + public: + explicit ScopedMachPortSet(mach_port_t port = traits_type::InvalidValue()) + : ScopedGeneric(port) {} + + operator mach_port_t() const { return get(); } +}; + } // namespace mac } // namespace base |