OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 IPC_IPC_CHANNEL_HANDLE_H_ | 5 #ifndef IPC_IPC_CHANNEL_HANDLE_H_ |
6 #define IPC_IPC_CHANNEL_HANDLE_H_ | 6 #define IPC_IPC_CHANNEL_HANDLE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 | 12 |
13 #if defined(OS_WIN) | |
14 #include "base/win/scoped_handle.h" | |
15 #endif | |
13 #if defined(OS_POSIX) | 16 #if defined(OS_POSIX) |
14 #include "base/file_descriptor_posix.h" | 17 #include "base/file_descriptor_posix.h" |
15 #endif | 18 #endif |
16 | 19 |
17 // On Windows, any process can create an IPC channel and others can fetch | 20 // 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. | 21 // it by name. We pass around the channel names over IPC. |
19 // On POSIX, we instead pass around handles to channel endpoints via IPC. | 22 // On POSIX, we instead pass around handles to channel endpoints via IPC. |
cpu_(ooo_6.6-7.5)
2012/01/19 20:56:05
With this change we change the behavior significan
| |
20 // When it's time to IPC a new channel endpoint around, we send both the | 23 // 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 | 24 // 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. | 25 // type that knows how to copy a socket endpoint over IPC. |
23 // | 26 // |
24 // In sum, when passing a handle to a channel over IPC, use this data structure | 27 // In sum, when passing a handle to a channel over IPC, use this data structure |
25 // to work on both Windows and POSIX. | 28 // to work on both Windows and POSIX. |
26 | 29 |
27 namespace IPC { | 30 namespace IPC { |
28 | 31 |
29 struct ChannelHandle { | 32 struct ChannelHandle { |
30 // Note that serialization for this object is defined in the ParamTraits | 33 // Note that serialization for this object is defined in the ParamTraits |
31 // template specialization in ipc_message_utils.h. | 34 // template specialization in ipc_message_utils.h. |
32 ChannelHandle() {} | 35 ChannelHandle() {} |
33 // The name that is passed in should be an absolute path for Posix. | 36 // The name that is passed in should be an absolute path for Posix. |
34 // Otherwise there may be a problem in IPC communication between | 37 // Otherwise there may be a problem in IPC communication between |
35 // processes with different working directories. | 38 // processes with different working directories. |
36 ChannelHandle(const std::string& n) : name(n) {} | 39 ChannelHandle(const std::string& n) : name(n) {} |
37 ChannelHandle(const char* n) : name(n) {} | 40 ChannelHandle(const char* n) : name(n) {} |
41 #if defined(OS_WIN) | |
42 ChannelHandle(HANDLE h) : pipe(h) {} | |
43 ChannelHandle(const ChannelHandle& other) { | |
44 Assign(other); | |
45 } | |
46 ChannelHandle& operator=(const ChannelHandle& other) { | |
47 Assign(other); | |
48 return *this; | |
49 } | |
50 void Assign(const ChannelHandle& other) { | |
51 name = other.name; | |
52 HANDLE copy = NULL; | |
53 DuplicateHandle(GetCurrentProcess(), other.pipe, GetCurrentProcess(), | |
54 ©, 0, FALSE, DUPLICATE_SAME_ACCESS); | |
55 pipe.Set(copy); | |
56 } | |
57 #endif | |
38 #if defined(OS_POSIX) | 58 #if defined(OS_POSIX) |
39 ChannelHandle(const std::string& n, const base::FileDescriptor& s) | 59 ChannelHandle(const std::string& n, const base::FileDescriptor& s) |
40 : name(n), socket(s) {} | 60 : name(n), socket(s) {} |
41 #endif // defined(OS_POSIX) | 61 #endif // defined(OS_POSIX) |
42 | 62 |
43 std::string name; | 63 std::string name; |
44 #if defined(OS_POSIX) | 64 #if defined(OS_POSIX) |
45 base::FileDescriptor socket; | 65 base::FileDescriptor socket; |
46 #endif // defined(OS_POSIX) | 66 #endif // defined(OS_POSIX) |
67 #if defined(OS_WIN) | |
68 base::win::ScopedHandle pipe; | |
cpu_(ooo_6.6-7.5)
2012/01/19 20:56:05
so base::FileDescriptor does not close the descrip
| |
69 #endif | |
47 | 70 |
48 }; | 71 }; |
49 | 72 |
50 } // namespace IPC | 73 } // namespace IPC |
51 | 74 |
52 #endif // IPC_IPC_CHANNEL_HANDLE_H_ | 75 #endif // IPC_IPC_CHANNEL_HANDLE_H_ |
OLD | NEW |