[email protected] | 84818e9 | 2011-06-24 18:57:24 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | d2e884d | 2009-06-22 20:37:52 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 5 | #ifndef IPC_IPC_CHANNEL_HANDLE_H_ |
6 | #define IPC_IPC_CHANNEL_HANDLE_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | d2e884d | 2009-06-22 20:37:52 | [diff] [blame] | 8 | |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 9 | #include <string> |
10 | |||||
[email protected] | d2e884d | 2009-06-22 20:37:52 | [diff] [blame] | 11 | #include "build/build_config.h" |
12 | |||||
13 | #if defined(OS_POSIX) | ||||
14 | #include "base/file_descriptor_posix.h" | ||||
15 | #endif | ||||
16 | |||||
17 | // On Windows, any process can create an IPC channel and others can fetch | ||||
18 | // it by name. We pass around the channel names over IPC. | ||||
19 | // On POSIX, we instead pass around handles to channel endpoints via IPC. | ||||
20 | // When it's time to IPC a new channel endpoint around, we send both the | ||||
21 | // channel name as well as a base::FileDescriptor, which is itself a special | ||||
22 | // type that knows how to copy a socket endpoint over IPC. | ||||
23 | // | ||||
24 | // In sum, when passing a handle to a channel over IPC, use this data structure | ||||
25 | // to work on both Windows and POSIX. | ||||
26 | |||||
27 | namespace IPC { | ||||
28 | |||||
29 | struct ChannelHandle { | ||||
30 | // Note that serialization for this object is defined in the ParamTraits | ||||
31 | // template specialization in ipc_message_utils.h. | ||||
[email protected] | d2e884d | 2009-06-22 20:37:52 | [diff] [blame] | 32 | ChannelHandle() {} |
[email protected] | 84818e9 | 2011-06-24 18:57:24 | [diff] [blame^] | 33 | // The name that is passed in should be an absolute path for Posix. |
34 | // Otherwise there may be a problem in IPC communication between | ||||
35 | // processes with different working directories. | ||||
[email protected] | 42ce94e | 2010-12-08 19:28:09 | [diff] [blame] | 36 | ChannelHandle(const std::string& n) : name(n) {} |
37 | ChannelHandle(const char* n) : name(n) {} | ||||
[email protected] | d2e884d | 2009-06-22 20:37:52 | [diff] [blame] | 38 | #if defined(OS_POSIX) |
39 | ChannelHandle(const std::string& n, const base::FileDescriptor& s) | ||||
40 | : name(n), socket(s) {} | ||||
[email protected] | 42ce94e | 2010-12-08 19:28:09 | [diff] [blame] | 41 | #endif // defined(OS_POSIX) |
42 | |||||
43 | std::string name; | ||||
44 | #if defined(OS_POSIX) | ||||
45 | base::FileDescriptor socket; | ||||
46 | #endif // defined(OS_POSIX) | ||||
47 | |||||
[email protected] | d2e884d | 2009-06-22 20:37:52 | [diff] [blame] | 48 | }; |
49 | |||||
50 | } // namespace IPC | ||||
51 | |||||
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 52 | #endif // IPC_IPC_CHANNEL_HANDLE_H_ |