blob: df6e8e394c054de21b51d11d642f2cc0c806130b [file] [log] [blame]
[email protected]e7f009d2011-06-14 19:35:101// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]cb6037d2009-11-16 22:55:172// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef IPC_IPC_PLATFORM_FILE_H_
6#define IPC_IPC_PLATFORM_FILE_H_
7
[email protected]141bcc52014-01-27 21:36:008#include "base/files/file.h"
[email protected]e66ef602013-07-24 05:15:249#include "base/process/process.h"
[email protected]7c854372011-08-15 20:41:4610#include "ipc/ipc_export.h"
[email protected]cb6037d2009-11-16 22:55:1711
12#if defined(OS_POSIX)
13#include "base/file_descriptor_posix.h"
14#endif
15
16namespace IPC {
17
18#if defined(OS_WIN)
19typedef base::PlatformFile PlatformFileForTransit;
20#elif defined(OS_POSIX)
21typedef base::FileDescriptor PlatformFileForTransit;
22#endif
23
[email protected]a784b842009-12-18 00:23:0524inline PlatformFileForTransit InvalidPlatformFileForTransit() {
25#if defined(OS_WIN)
[email protected]dd7a8a42014-06-10 12:58:2926 return INVALID_HANDLE_VALUE;
[email protected]a784b842009-12-18 00:23:0527#elif defined(OS_POSIX)
28 return base::FileDescriptor();
29#endif
30}
31
[email protected]cb6037d2009-11-16 22:55:1732inline base::PlatformFile PlatformFileForTransitToPlatformFile(
33 const PlatformFileForTransit& transit) {
34#if defined(OS_WIN)
35 return transit;
36#elif defined(OS_POSIX)
37 return transit.fd;
38#endif
39}
40
[email protected]008e3b32014-03-25 06:01:4841inline base::File PlatformFileForTransitToFile(
42 const PlatformFileForTransit& transit) {
43#if defined(OS_WIN)
44 return base::File(transit);
45#elif defined(OS_POSIX)
46 return base::File(transit.fd);
47#endif
48}
49
[email protected]e7f009d2011-06-14 19:35:1050// Returns a file handle equivalent to |file| that can be used in |process|.
[email protected]7c854372011-08-15 20:41:4651IPC_EXPORT PlatformFileForTransit GetFileHandleForProcess(
52 base::PlatformFile file,
53 base::ProcessHandle process,
54 bool close_source_handle);
[email protected]e7f009d2011-06-14 19:35:1055
[email protected]8880e702014-03-05 20:13:4956// Returns a file handle equivalent to |file| that can be used in |process|.
57// Note that this function takes ownership of |file|.
58IPC_EXPORT PlatformFileForTransit TakeFileHandleForProcess(
59 base::File file,
60 base::ProcessHandle process);
61
[email protected]cb6037d2009-11-16 22:55:1762} // namespace IPC
63
64#endif // IPC_IPC_PLATFORM_FILE_H_