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 #ifndef IPC_IPC_CHANNEL_POSIX_H_ | 5 #ifndef IPC_IPC_CHANNEL_POSIX_H_ |
6 #define IPC_IPC_CHANNEL_POSIX_H_ | 6 #define IPC_IPC_CHANNEL_POSIX_H_ |
7 | 7 |
8 #include "ipc/ipc_channel.h" | 8 #include "ipc/ipc_channel.h" |
9 | 9 |
10 #include <sys/socket.h> // for CMSG macros | 10 #include <sys/socket.h> // for CMSG macros |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 // needs to send file descriptors in later messages. | 46 // needs to send file descriptors in later messages. |
47 #define IPC_USES_READWRITE 1 | 47 #define IPC_USES_READWRITE 1 |
48 #endif | 48 #endif |
49 | 49 |
50 namespace IPC { | 50 namespace IPC { |
51 | 51 |
52 class ChannelPosix : public Channel, | 52 class ChannelPosix : public Channel, |
53 public internal::ChannelReader, | 53 public internal::ChannelReader, |
54 public base::MessageLoopForIO::Watcher { | 54 public base::MessageLoopForIO::Watcher { |
55 public: | 55 public: |
56 // Mirror methods of Channel, see ipc_channel.h for description. | 56 // Implementation of IPC::Channel::Create() |
57 ChannelPosix(const IPC::ChannelHandle& channel_handle, Mode mode, | 57 static scoped_ptr<ChannelPosix> Create( |
jam
2014/06/05 20:45:32
I dont think a factory method for IPC::ChannelPosi
gmorrita
2014/06/05 22:05:25
OK, removed the Create() and use the ctor directly
| |
58 Listener* listener); | 58 const IPC::ChannelHandle& channel_handle, Mode mode, |
59 Listener* listener); | |
60 | |
59 virtual ~ChannelPosix(); | 61 virtual ~ChannelPosix(); |
60 | 62 |
61 // Channel implementation | 63 // Channel implementation |
62 virtual bool Connect() OVERRIDE; | 64 virtual bool Connect() OVERRIDE; |
63 virtual void Close() OVERRIDE; | 65 virtual void Close() OVERRIDE; |
64 virtual bool Send(Message* message) OVERRIDE; | 66 virtual bool Send(Message* message) OVERRIDE; |
65 virtual base::ProcessId GetPeerPID() const OVERRIDE; | 67 virtual base::ProcessId GetPeerPID() const OVERRIDE; |
66 virtual int GetClientFileDescriptor() const OVERRIDE; | 68 virtual int GetClientFileDescriptor() const OVERRIDE; |
67 virtual int TakeClientFileDescriptor() OVERRIDE; | 69 virtual int TakeClientFileDescriptor() OVERRIDE; |
68 virtual bool AcceptsConnections() const OVERRIDE; | 70 |
69 virtual bool HasAcceptedConnection() const OVERRIDE; | 71 // Returns true if the channel supports listening for connections. |
70 virtual bool GetPeerEuid(uid_t* peer_euid) const OVERRIDE; | 72 bool AcceptsConnections() const; |
71 virtual void ResetToAcceptingConnectionState() OVERRIDE; | 73 |
74 // Returns true if the channel supports listening for connections and is | |
75 // currently connected. | |
76 bool HasAcceptedConnection() const; | |
77 | |
78 // Closes any currently connected socket, and returns to a listening state | |
79 // for more connections. | |
80 void ResetToAcceptingConnectionState(); | |
81 | |
82 // Returns true if the peer process' effective user id can be determined, in | |
83 // which case the supplied peer_euid is updated with it. | |
84 bool GetPeerEuid(uid_t* peer_euid) const; | |
72 | 85 |
73 void CloseClientFileDescriptor(); | 86 void CloseClientFileDescriptor(); |
74 | 87 |
75 static bool IsNamedServerInitialized(const std::string& channel_id); | 88 static bool IsNamedServerInitialized(const std::string& channel_id); |
76 #if defined(OS_LINUX) | 89 #if defined(OS_LINUX) |
77 static void SetGlobalPid(int pid); | 90 static void SetGlobalPid(int pid); |
78 #endif // OS_LINUX | 91 #endif // OS_LINUX |
79 | 92 |
80 private: | 93 private: |
94 ChannelPosix(const IPC::ChannelHandle& channel_handle, Mode mode, | |
95 Listener* listener); | |
96 | |
81 bool CreatePipe(const IPC::ChannelHandle& channel_handle); | 97 bool CreatePipe(const IPC::ChannelHandle& channel_handle); |
82 | 98 |
83 bool ProcessOutgoingMessages(); | 99 bool ProcessOutgoingMessages(); |
84 | 100 |
85 bool AcceptConnection(); | 101 bool AcceptConnection(); |
86 void ClosePipeOnError(); | 102 void ClosePipeOnError(); |
87 int GetHelloMessageProcId(); | 103 int GetHelloMessageProcId(); |
88 void QueueHelloMessage(); | 104 void QueueHelloMessage(); |
89 void CloseFileDescriptors(Message* msg); | 105 void CloseFileDescriptors(Message* msg); |
90 void QueueCloseFDMessage(int fd, int hops); | 106 void QueueCloseFDMessage(int fd, int hops); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 // If non-zero, overrides the process ID sent in the hello message. | 222 // If non-zero, overrides the process ID sent in the hello message. |
207 static int global_pid_; | 223 static int global_pid_; |
208 #endif // OS_LINUX | 224 #endif // OS_LINUX |
209 | 225 |
210 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); | 226 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); |
211 }; | 227 }; |
212 | 228 |
213 } // namespace IPC | 229 } // namespace IPC |
214 | 230 |
215 #endif // IPC_IPC_CHANNEL_POSIX_H_ | 231 #endif // IPC_IPC_CHANNEL_POSIX_H_ |
OLD | NEW |