| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #endif | 49 #endif |
| 50 | 50 |
| 51 namespace IPC { | 51 namespace IPC { |
| 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 ~ChannelPosix() override; |
| 60 | 60 |
| 61 // Channel implementation | 61 // Channel implementation |
| 62 virtual bool Connect() override; | 62 bool Connect() override; |
| 63 virtual void Close() override; | 63 void Close() override; |
| 64 virtual bool Send(Message* message) override; | 64 bool Send(Message* message) override; |
| 65 virtual base::ProcessId GetPeerPID() const override; | 65 base::ProcessId GetPeerPID() const override; |
| 66 virtual base::ProcessId GetSelfPID() const override; | 66 base::ProcessId GetSelfPID() const override; |
| 67 virtual int GetClientFileDescriptor() const override; | 67 int GetClientFileDescriptor() const override; |
| 68 virtual base::ScopedFD TakeClientFileDescriptor() override; | 68 base::ScopedFD 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 16 matching lines...) Expand all Loading... |
| 95 bool ProcessOutgoingMessages(); | 95 bool ProcessOutgoingMessages(); |
| 96 | 96 |
| 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 ReadState ReadData(char* buffer, int buffer_len, int* bytes_read) override; |
| 106 int buffer_len, | 106 bool WillDispatchInputMessage(Message* msg) override; |
| 107 int* bytes_read) override; | 107 bool DidEmptyInputBuffers() override; |
| 108 virtual bool WillDispatchInputMessage(Message* msg) override; | 108 void HandleInternalMessage(const Message& msg) override; |
| 109 virtual bool DidEmptyInputBuffers() override; | |
| 110 virtual void HandleInternalMessage(const Message& msg) override; | |
| 111 | 109 |
| 112 #if defined(IPC_USES_READWRITE) | 110 #if defined(IPC_USES_READWRITE) |
| 113 // Reads the next message from the fd_pipe_ and appends them to the | 111 // 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. | 112 // 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 | 113 // True means there was a message and it was processed properly, or there was |
| 116 // no messages. | 114 // no messages. |
| 117 bool ReadFileDescriptorsFromFDPipe(); | 115 bool ReadFileDescriptorsFromFDPipe(); |
| 118 #endif | 116 #endif |
| 119 | 117 |
| 120 // Finds the set of file descriptors in the given message. On success, | 118 // Finds the set of file descriptors in the given message. On success, |
| 121 // appends the descriptors to the input_fds_ member and returns true | 119 // appends the descriptors to the input_fds_ member and returns true |
| 122 // | 120 // |
| 123 // Returns false if the message was truncated. In this case, any handles that | 121 // Returns false if the message was truncated. In this case, any handles that |
| 124 // were sent will be closed. | 122 // were sent will be closed. |
| 125 bool ExtractFileDescriptorsFromMsghdr(msghdr* msg); | 123 bool ExtractFileDescriptorsFromMsghdr(msghdr* msg); |
| 126 | 124 |
| 127 // Closes all handles in the input_fds_ list and clears the list. This is | 125 // 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. | 126 // used to clean up handles in error conditions to avoid leaking the handles. |
| 129 void ClearInputFDs(); | 127 void ClearInputFDs(); |
| 130 | 128 |
| 131 // MessageLoopForIO::Watcher implementation. | 129 // MessageLoopForIO::Watcher implementation. |
| 132 virtual void OnFileCanReadWithoutBlocking(int fd) override; | 130 void OnFileCanReadWithoutBlocking(int fd) override; |
| 133 virtual void OnFileCanWriteWithoutBlocking(int fd) override; | 131 void OnFileCanWriteWithoutBlocking(int fd) override; |
| 134 | 132 |
| 135 Mode mode_; | 133 Mode mode_; |
| 136 | 134 |
| 137 base::ProcessId peer_pid_; | 135 base::ProcessId peer_pid_; |
| 138 | 136 |
| 139 // After accepting one client connection on our server socket we want to | 137 // After accepting one client connection on our server socket we want to |
| 140 // stop listening. | 138 // stop listening. |
| 141 base::MessageLoopForIO::FileDescriptorWatcher | 139 base::MessageLoopForIO::FileDescriptorWatcher |
| 142 server_listen_connection_watcher_; | 140 server_listen_connection_watcher_; |
| 143 base::MessageLoopForIO::FileDescriptorWatcher read_watcher_; | 141 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. | 216 // If non-zero, overrides the process ID sent in the hello message. |
| 219 static int global_pid_; | 217 static int global_pid_; |
| 220 #endif // OS_LINUX | 218 #endif // OS_LINUX |
| 221 | 219 |
| 222 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); | 220 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); |
| 223 }; | 221 }; |
| 224 | 222 |
| 225 } // namespace IPC | 223 } // namespace IPC |
| 226 | 224 |
| 227 #endif // IPC_IPC_CHANNEL_POSIX_H_ | 225 #endif // IPC_IPC_CHANNEL_POSIX_H_ |
| OLD | NEW |