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

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

Issue 2843113002: make base::SharedMemoryHandle a class on POSIX. (Closed)
Patch Set: Fixes for ChromeOS. Created 3 years, 8 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
Nico 2017/04/27 16:24:44 do you want to call Close() in the dtor if auto_cl
erikchen 2017/04/27 17:08:10 No, that's done in ipc_message_utils.cc. This CL
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";
Nico 2017/04/27 16:24:44 Should this then call Invalidate()? Closing but ke
erikchen 2017/04/27 17:08:10 It should, but it never has on any platform. I've
39 }
40
41 void SharedMemoryHandle::Invalidate() {
42 file_descriptor.fd = -1;
43 }
44
45 SharedMemoryHandle SharedMemoryHandle::Duplicate() const {
46 if (!IsValid())
47 return SharedMemoryHandle();
48
49 int duped_handle = HANDLE_EINTR(dup(file_descriptor.fd));
50 if (duped_handle < 0)
51 return SharedMemoryHandle();
52 return SharedMemoryHandle(FileDescriptor(duped_handle, true));
53 }
54
55 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698