Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(755)

Side by Side Diff: base/memory/shared_memory_handle_posix.cc

Issue 2843113002: make base::SharedMemoryHandle a class on POSIX. (Closed)
Patch Set: Comments from thakis. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/shared_memory_handle.h"
6
7 #include <unistd.h>
8
9 #include "base/logging.h"
10 #include "base/posix/eintr_wrapper.h"
11
12 namespace base {
13
14 SharedMemoryHandle::SharedMemoryHandle() = default;
15
16 SharedMemoryHandle::SharedMemoryHandle(
17 const base::FileDescriptor& file_descriptor)
18 : file_descriptor(file_descriptor) {}
19
20 // static
21 SharedMemoryHandle SharedMemoryHandle::ImportHandle(int fd) {
22 SharedMemoryHandle handle;
23 handle.file_descriptor.fd = fd;
24 handle.file_descriptor.auto_close = true;
25 return handle;
26 }
27
28 int SharedMemoryHandle::GetHandle() const {
29 return file_descriptor.fd;
30 }
31
32 bool SharedMemoryHandle::IsValid() const {
33 return file_descriptor.fd >= 0;
34 }
35
36 void SharedMemoryHandle::Close() const {
37 if (IGNORE_EINTR(close(file_descriptor.fd)) < 0)
38 PLOG(ERROR) << "close";
39 }
40
41 int SharedMemoryHandle::Release() {
42 int old_fd = file_descriptor.fd;
43 file_descriptor.fd = -1;
44 return old_fd;
45 }
46
47 SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
48 if (!IsValid())
49 return SharedMemoryHandle();
50
51 int duped_handle = HANDLE_EINTR(dup(file_descriptor.fd));
52 if (duped_handle < 0)
53 return SharedMemoryHandle();
54 return SharedMemoryHandle(FileDescriptor(duped_handle, true));
55 }
56
57 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698