OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ipc/ipc_channel_posix.h" | 5 #include "ipc/ipc_channel_posix.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // connects. Once the client connects, the server will close the original | 87 // connects. Once the client connects, the server will close the original |
88 // copy of the client socket and remove the mapping. Thus, when the client | 88 // copy of the client socket and remove the mapping. Thus, when the client |
89 // object closes, it will close the only remaining copy of the client socket | 89 // object closes, it will close the only remaining copy of the client socket |
90 // in the fd table and the server will see EOF on its side. | 90 // in the fd table and the server will see EOF on its side. |
91 // | 91 // |
92 // TODO(port): a client process cannot connect to multiple IPC channels with | 92 // TODO(port): a client process cannot connect to multiple IPC channels with |
93 // this scheme. | 93 // this scheme. |
94 | 94 |
95 class PipeMap { | 95 class PipeMap { |
96 public: | 96 public: |
97 static PipeMap* GetInstance() { | 97 static PipeMap* GetInstance() { return base::Singleton<PipeMap>::get(); } |
98 return Singleton<PipeMap>::get(); | |
99 } | |
100 | 98 |
101 ~PipeMap() { | 99 ~PipeMap() { |
102 // Shouldn't have left over pipes. | 100 // Shouldn't have left over pipes. |
103 DCHECK(map_.empty()); | 101 DCHECK(map_.empty()); |
104 } | 102 } |
105 | 103 |
106 // Lookup a given channel id. Return -1 if not found. | 104 // Lookup a given channel id. Return -1 if not found. |
107 int Lookup(const std::string& channel_id) { | 105 int Lookup(const std::string& channel_id) { |
108 base::AutoLock locked(lock_); | 106 base::AutoLock locked(lock_); |
109 | 107 |
(...skipping 21 matching lines...) Expand all Loading... |
131 << "for '" << channel_id << "' while first " | 129 << "for '" << channel_id << "' while first " |
132 << "(fd " << i->second << ") still exists"; | 130 << "(fd " << i->second << ") still exists"; |
133 map_[channel_id] = fd; | 131 map_[channel_id] = fd; |
134 } | 132 } |
135 | 133 |
136 private: | 134 private: |
137 base::Lock lock_; | 135 base::Lock lock_; |
138 typedef std::map<std::string, int> ChannelToFDMap; | 136 typedef std::map<std::string, int> ChannelToFDMap; |
139 ChannelToFDMap map_; | 137 ChannelToFDMap map_; |
140 | 138 |
141 friend struct DefaultSingletonTraits<PipeMap>; | 139 friend struct base::DefaultSingletonTraits<PipeMap>; |
142 #if defined(OS_ANDROID) | 140 #if defined(OS_ANDROID) |
143 friend void ::IPC::Channel::NotifyProcessForkedForTesting(); | 141 friend void ::IPC::Channel::NotifyProcessForkedForTesting(); |
144 #endif | 142 #endif |
145 }; | 143 }; |
146 | 144 |
147 //------------------------------------------------------------------------------ | 145 //------------------------------------------------------------------------------ |
148 | 146 |
149 bool SocketWriteErrorIsRecoverable() { | 147 bool SocketWriteErrorIsRecoverable() { |
150 #if defined(OS_MACOSX) | 148 #if defined(OS_MACOSX) |
151 // On OS X if sendmsg() is trying to send fds between processes and there | 149 // On OS X if sendmsg() is trying to send fds between processes and there |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 } | 1043 } |
1046 | 1044 |
1047 #if defined(OS_LINUX) | 1045 #if defined(OS_LINUX) |
1048 // static | 1046 // static |
1049 void Channel::SetGlobalPid(int pid) { | 1047 void Channel::SetGlobalPid(int pid) { |
1050 ChannelPosix::SetGlobalPid(pid); | 1048 ChannelPosix::SetGlobalPid(pid); |
1051 } | 1049 } |
1052 #endif // OS_LINUX | 1050 #endif // OS_LINUX |
1053 | 1051 |
1054 } // namespace IPC | 1052 } // namespace IPC |
OLD | NEW |