OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "ipc/ipc_channel.h" | 9 #include "ipc/ipc_channel.h" |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 // this switch 'on' on the Mac as well. | 33 // this switch 'on' on the Mac as well. |
34 | 34 |
35 // The HELLO message from the client to the server is always sent using | 35 // The HELLO message from the client to the server is always sent using |
36 // sendmsg because it will contain the file descriptor that the server | 36 // sendmsg because it will contain the file descriptor that the server |
37 // needs to send file descriptors in later messages. | 37 // needs to send file descriptors in later messages. |
38 #define IPC_USES_READWRITE 1 | 38 #define IPC_USES_READWRITE 1 |
39 #endif | 39 #endif |
40 | 40 |
41 namespace IPC { | 41 namespace IPC { |
42 | 42 |
43 // An implementation of ChannelImpl for POSIX systems that works via | |
44 // socketpairs. See the .cc file for an overview of the implementation. | |
45 class Channel::ChannelImpl : public MessageLoopForIO::Watcher { | 43 class Channel::ChannelImpl : public MessageLoopForIO::Watcher { |
46 public: | 44 public: |
47 // Mirror methods of Channel, see ipc_channel.h for description. | 45 // Mirror methods of Channel, see ipc_channel.h for description. |
48 ChannelImpl(const IPC::ChannelHandle &channel_handle, Mode mode, | 46 ChannelImpl(const IPC::ChannelHandle& channel_handle, Mode mode, |
49 Listener* listener); | 47 Listener* listener); |
50 ~ChannelImpl(); | 48 ~ChannelImpl(); |
51 bool Connect(); | 49 bool Connect(); |
52 void Close(); | 50 void Close(); |
53 void set_listener(Listener* listener) { listener_ = listener; } | 51 void set_listener(Listener* listener) { listener_ = listener; } |
54 bool Send(Message* message); | 52 bool Send(Message* message); |
55 int GetClientFileDescriptor() const; | 53 int GetClientFileDescriptor() const; |
| 54 bool AcceptsConnections() const; |
| 55 bool HasAcceptedConnection() const; |
| 56 void ResetToAcceptingConnectionState(); |
56 | 57 |
57 private: | 58 private: |
58 bool CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode); | 59 bool CreatePipe(const IPC::ChannelHandle& channel_handle, |
| 60 bool uses_domain_sockets); |
59 | 61 |
60 bool ProcessIncomingMessages(); | 62 bool ProcessIncomingMessages(); |
61 bool ProcessOutgoingMessages(); | 63 bool ProcessOutgoingMessages(); |
62 | 64 |
| 65 bool AcceptConnection(); |
| 66 void ClosePipeOnError(); |
| 67 void QueueHelloMessage(); |
| 68 bool IsHelloMessage(const Message* m) const; |
| 69 |
63 // MessageLoopForIO::Watcher implementation. | 70 // MessageLoopForIO::Watcher implementation. |
64 virtual void OnFileCanReadWithoutBlocking(int fd); | 71 virtual void OnFileCanReadWithoutBlocking(int fd); |
65 virtual void OnFileCanWriteWithoutBlocking(int fd); | 72 virtual void OnFileCanWriteWithoutBlocking(int fd); |
66 | 73 |
67 Mode mode_; | 74 Mode mode_; |
68 | 75 |
69 // After accepting one client connection on our server socket we want to | 76 // After accepting one client connection on our server socket we want to |
70 // stop listening. | 77 // stop listening. |
71 MessageLoopForIO::FileDescriptorWatcher server_listen_connection_watcher_; | 78 MessageLoopForIO::FileDescriptorWatcher server_listen_connection_watcher_; |
72 MessageLoopForIO::FileDescriptorWatcher read_watcher_; | 79 MessageLoopForIO::FileDescriptorWatcher read_watcher_; |
73 MessageLoopForIO::FileDescriptorWatcher write_watcher_; | 80 MessageLoopForIO::FileDescriptorWatcher write_watcher_; |
74 | 81 |
75 // Indicates whether we're currently blocked waiting for a write to complete. | 82 // Indicates whether we're currently blocked waiting for a write to complete. |
76 bool is_blocked_on_write_; | 83 bool is_blocked_on_write_; |
| 84 bool waiting_connect_; |
77 | 85 |
78 // If sending a message blocks then we use this variable | 86 // If sending a message blocks then we use this variable |
79 // to keep track of where we are. | 87 // to keep track of where we are. |
80 size_t message_send_bytes_written_; | 88 size_t message_send_bytes_written_; |
81 | 89 |
82 // If the kTestingChannelID flag is specified, we use a FIFO instead of | 90 // File descriptor we're listening on for new connections if we listen |
83 // a socketpair(). | 91 // for connections. |
84 bool uses_fifo_; | |
85 | |
86 // File descriptor we're listening on for new connections in the FIFO case; | |
87 // unused otherwise. | |
88 int server_listen_pipe_; | 92 int server_listen_pipe_; |
89 | 93 |
90 // The pipe used for communication. | 94 // The pipe used for communication. |
91 int pipe_; | 95 int pipe_; |
92 | 96 |
93 // For a server, the client end of our socketpair() -- the other end of our | 97 // For a server, the client end of our socketpair() -- the other end of our |
94 // pipe_ that is passed to the client. | 98 // pipe_ that is passed to the client. |
95 int client_pipe_; | 99 int client_pipe_; |
96 | 100 |
97 #if defined(IPC_USES_READWRITE) | 101 #if defined(IPC_USES_READWRITE) |
(...skipping 27 matching lines...) Expand all Loading... |
125 char input_cmsg_buf_[1024]; | 129 char input_cmsg_buf_[1024]; |
126 #else | 130 #else |
127 char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * MAX_READ_FDS)]; | 131 char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * MAX_READ_FDS)]; |
128 #endif | 132 #endif |
129 | 133 |
130 // Large messages that span multiple pipe buffers, get built-up using | 134 // Large messages that span multiple pipe buffers, get built-up using |
131 // this buffer. | 135 // this buffer. |
132 std::string input_overflow_buf_; | 136 std::string input_overflow_buf_; |
133 std::vector<int> input_overflow_fds_; | 137 std::vector<int> input_overflow_fds_; |
134 | 138 |
135 // In server-mode, we have to wait for the client to connect before we | 139 // True if we are responsible for unlinking the unix domain socket file. |
136 // can begin reading. We make use of the input_state_ when performing | 140 bool must_unlink_; |
137 // the connect operation in overlapped mode. | |
138 bool waiting_connect_; | |
139 | 141 |
140 ScopedRunnableMethodFactory<ChannelImpl> factory_; | 142 ScopedRunnableMethodFactory<ChannelImpl> factory_; |
141 | 143 |
142 DISALLOW_COPY_AND_ASSIGN(ChannelImpl); | 144 DISALLOW_COPY_AND_ASSIGN(ChannelImpl); |
143 }; | 145 }; |
144 | 146 |
145 } // namespace IPC | 147 } // namespace IPC |
146 | 148 |
147 #endif // IPC_IPC_CHANNEL_POSIX_H_ | 149 #endif // IPC_IPC_CHANNEL_POSIX_H_ |
OLD | NEW |