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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 class IPC_EXPORT ChannelPosix : public Channel, | 53 class IPC_EXPORT ChannelPosix : public Channel, |
54 public internal::ChannelReader, | 54 public internal::ChannelReader, |
55 public base::MessageLoopForIO::Watcher { | 55 public base::MessageLoopForIO::Watcher { |
56 public: | 56 public: |
57 ChannelPosix(const IPC::ChannelHandle& channel_handle, Mode mode, | 57 ChannelPosix(const IPC::ChannelHandle& channel_handle, Mode mode, |
58 Listener* listener); | 58 Listener* listener); |
59 virtual ~ChannelPosix(); | 59 virtual ~ChannelPosix(); |
60 | 60 |
61 // Channel implementation | 61 // Channel implementation |
62 virtual bool Connect() OVERRIDE; | 62 virtual bool Connect() override; |
63 virtual void Close() OVERRIDE; | 63 virtual void Close() override; |
64 virtual bool Send(Message* message) OVERRIDE; | 64 virtual bool Send(Message* message) override; |
65 virtual base::ProcessId GetPeerPID() const OVERRIDE; | 65 virtual base::ProcessId GetPeerPID() const override; |
66 virtual base::ProcessId GetSelfPID() const OVERRIDE; | 66 virtual base::ProcessId GetSelfPID() const override; |
67 virtual int GetClientFileDescriptor() const OVERRIDE; | 67 virtual int GetClientFileDescriptor() const override; |
68 virtual int TakeClientFileDescriptor() OVERRIDE; | 68 virtual int TakeClientFileDescriptor() override; |
69 | 69 |
70 // Returns true if the channel supports listening for connections. | 70 // Returns true if the channel supports listening for connections. |
71 bool AcceptsConnections() const; | 71 bool AcceptsConnections() const; |
72 | 72 |
73 // Returns true if the channel supports listening for connections and is | 73 // Returns true if the channel supports listening for connections and is |
74 // currently connected. | 74 // currently connected. |
75 bool HasAcceptedConnection() const; | 75 bool HasAcceptedConnection() const; |
76 | 76 |
77 // Closes any currently connected socket, and returns to a listening state | 77 // Closes any currently connected socket, and returns to a listening state |
78 // for more connections. | 78 // for more connections. |
(...skipping 18 matching lines...) Expand all Loading... |
97 bool AcceptConnection(); | 97 bool AcceptConnection(); |
98 void ClosePipeOnError(); | 98 void ClosePipeOnError(); |
99 int GetHelloMessageProcId() const; | 99 int GetHelloMessageProcId() const; |
100 void QueueHelloMessage(); | 100 void QueueHelloMessage(); |
101 void CloseFileDescriptors(Message* msg); | 101 void CloseFileDescriptors(Message* msg); |
102 void QueueCloseFDMessage(int fd, int hops); | 102 void QueueCloseFDMessage(int fd, int hops); |
103 | 103 |
104 // ChannelReader implementation. | 104 // ChannelReader implementation. |
105 virtual ReadState ReadData(char* buffer, | 105 virtual ReadState ReadData(char* buffer, |
106 int buffer_len, | 106 int buffer_len, |
107 int* bytes_read) OVERRIDE; | 107 int* bytes_read) override; |
108 virtual bool WillDispatchInputMessage(Message* msg) OVERRIDE; | 108 virtual bool WillDispatchInputMessage(Message* msg) override; |
109 virtual bool DidEmptyInputBuffers() OVERRIDE; | 109 virtual bool DidEmptyInputBuffers() override; |
110 virtual void HandleInternalMessage(const Message& msg) OVERRIDE; | 110 virtual void HandleInternalMessage(const Message& msg) override; |
111 | 111 |
112 #if defined(IPC_USES_READWRITE) | 112 #if defined(IPC_USES_READWRITE) |
113 // Reads the next message from the fd_pipe_ and appends them to the | 113 // Reads the next message from the fd_pipe_ and appends them to the |
114 // input_fds_ queue. Returns false if there was a message receiving error. | 114 // input_fds_ queue. Returns false if there was a message receiving error. |
115 // True means there was a message and it was processed properly, or there was | 115 // True means there was a message and it was processed properly, or there was |
116 // no messages. | 116 // no messages. |
117 bool ReadFileDescriptorsFromFDPipe(); | 117 bool ReadFileDescriptorsFromFDPipe(); |
118 #endif | 118 #endif |
119 | 119 |
120 // Finds the set of file descriptors in the given message. On success, | 120 // Finds the set of file descriptors in the given message. On success, |
121 // appends the descriptors to the input_fds_ member and returns true | 121 // appends the descriptors to the input_fds_ member and returns true |
122 // | 122 // |
123 // Returns false if the message was truncated. In this case, any handles that | 123 // Returns false if the message was truncated. In this case, any handles that |
124 // were sent will be closed. | 124 // were sent will be closed. |
125 bool ExtractFileDescriptorsFromMsghdr(msghdr* msg); | 125 bool ExtractFileDescriptorsFromMsghdr(msghdr* msg); |
126 | 126 |
127 // Closes all handles in the input_fds_ list and clears the list. This is | 127 // Closes all handles in the input_fds_ list and clears the list. This is |
128 // used to clean up handles in error conditions to avoid leaking the handles. | 128 // used to clean up handles in error conditions to avoid leaking the handles. |
129 void ClearInputFDs(); | 129 void ClearInputFDs(); |
130 | 130 |
131 // MessageLoopForIO::Watcher implementation. | 131 // MessageLoopForIO::Watcher implementation. |
132 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | 132 virtual void OnFileCanReadWithoutBlocking(int fd) override; |
133 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | 133 virtual void OnFileCanWriteWithoutBlocking(int fd) override; |
134 | 134 |
135 Mode mode_; | 135 Mode mode_; |
136 | 136 |
137 base::ProcessId peer_pid_; | 137 base::ProcessId peer_pid_; |
138 | 138 |
139 // After accepting one client connection on our server socket we want to | 139 // After accepting one client connection on our server socket we want to |
140 // stop listening. | 140 // stop listening. |
141 base::MessageLoopForIO::FileDescriptorWatcher | 141 base::MessageLoopForIO::FileDescriptorWatcher |
142 server_listen_connection_watcher_; | 142 server_listen_connection_watcher_; |
143 base::MessageLoopForIO::FileDescriptorWatcher read_watcher_; | 143 base::MessageLoopForIO::FileDescriptorWatcher read_watcher_; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // If non-zero, overrides the process ID sent in the hello message. | 218 // If non-zero, overrides the process ID sent in the hello message. |
219 static int global_pid_; | 219 static int global_pid_; |
220 #endif // OS_LINUX | 220 #endif // OS_LINUX |
221 | 221 |
222 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); | 222 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); |
223 }; | 223 }; |
224 | 224 |
225 } // namespace IPC | 225 } // namespace IPC |
226 | 226 |
227 #endif // IPC_IPC_CHANNEL_POSIX_H_ | 227 #endif // IPC_IPC_CHANNEL_POSIX_H_ |
OLD | NEW |