Index: mojo/public/system/core.h |
diff --git a/mojo/public/system/core.h b/mojo/public/system/core.h |
index 88f2af5c9423a87672f80df577fd449be83bc472..c19ae734b315ffe067a82115195783398fa50bac 100644 |
--- a/mojo/public/system/core.h |
+++ b/mojo/public/system/core.h |
@@ -310,6 +310,31 @@ inline MojoResult ReadMessage(Handle handle, |
flags); |
} |
+// Closes handle_ when deleted. |
darin (slow to review)
2013/11/01 21:48:52
nit: how about breaking this out into its own head
|
+// This probably wants tons of improvements, but those can be made as needed. |
+class ScopedHandle { |
+ public: |
+ ScopedHandle(Handle handle) : handle_(handle) { |
+ } |
+ |
+ ~ScopedHandle() { |
+ if (handle_.value == kInvalidHandle.value) |
+ return; |
+ Close(handle_); |
+ release(); |
+ } |
+ |
+ Handle get() const { return handle_; } |
+ Handle release() { |
+ Handle temp = handle_; |
+ handle_ = kInvalidHandle; |
+ return temp; |
+ } |
+ |
+ private: |
+ Handle handle_; |
+}; |
+ |
} // namespace mojo |
#endif |