Chromium Code Reviews| 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 #ifndef MOJO_PUBLIC_SYSTEM_CORE_H_ | 5 #ifndef MOJO_PUBLIC_SYSTEM_CORE_H_ |
| 6 #define MOJO_PUBLIC_SYSTEM_CORE_H_ | 6 #define MOJO_PUBLIC_SYSTEM_CORE_H_ |
| 7 | 7 |
| 8 // Note: This header should be compilable as C. | 8 // Note: This header should be compilable as C. |
| 9 | 9 |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 inline MojoResult ReadMessage(Handle handle, | 303 inline MojoResult ReadMessage(Handle handle, |
| 304 void* bytes, uint32_t* num_bytes, | 304 void* bytes, uint32_t* num_bytes, |
| 305 Handle* handles, uint32_t* num_handles, | 305 Handle* handles, uint32_t* num_handles, |
| 306 MojoReadMessageFlags flags) { | 306 MojoReadMessageFlags flags) { |
| 307 return MojoReadMessage(handle.value, | 307 return MojoReadMessage(handle.value, |
| 308 bytes, num_bytes, | 308 bytes, num_bytes, |
| 309 &handles[0].value, num_handles, | 309 &handles[0].value, num_handles, |
| 310 flags); | 310 flags); |
| 311 } | 311 } |
| 312 | 312 |
| 313 // Closes handle_ when deleted. | |
|
darin (slow to review)
2013/11/01 21:48:52
nit: how about breaking this out into its own head
| |
| 314 // This probably wants tons of improvements, but those can be made as needed. | |
| 315 class ScopedHandle { | |
| 316 public: | |
| 317 ScopedHandle(Handle handle) : handle_(handle) { | |
| 318 } | |
| 319 | |
| 320 ~ScopedHandle() { | |
| 321 if (handle_.value == kInvalidHandle.value) | |
| 322 return; | |
| 323 Close(handle_); | |
| 324 release(); | |
| 325 } | |
| 326 | |
| 327 Handle get() const { return handle_; } | |
| 328 Handle release() { | |
| 329 Handle temp = handle_; | |
| 330 handle_ = kInvalidHandle; | |
| 331 return temp; | |
| 332 } | |
| 333 | |
| 334 private: | |
| 335 Handle handle_; | |
| 336 }; | |
| 337 | |
| 313 } // namespace mojo | 338 } // namespace mojo |
| 314 #endif | 339 #endif |
| 315 | 340 |
| 316 #endif // MOJO_PUBLIC_SYSTEM_CORE_H_ | 341 #endif // MOJO_PUBLIC_SYSTEM_CORE_H_ |
| OLD | NEW |