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, Mode mode); |
59 | 60 |
60 bool ProcessIncomingMessages(); | 61 bool ProcessIncomingMessages(); |
61 bool ProcessOutgoingMessages(); | 62 bool ProcessOutgoingMessages(); |
62 | 63 |
64 bool AcceptConnection(); | |
65 void ClosePipeOnError(); | |
66 void QueueHelloMessage(); | |
67 bool IsHelloMessage(const Message* m) const; | |
68 | |
63 // MessageLoopForIO::Watcher implementation. | 69 // MessageLoopForIO::Watcher implementation. |
64 virtual void OnFileCanReadWithoutBlocking(int fd); | 70 virtual void OnFileCanReadWithoutBlocking(int fd); |
65 virtual void OnFileCanWriteWithoutBlocking(int fd); | 71 virtual void OnFileCanWriteWithoutBlocking(int fd); |
66 | 72 |
67 Mode mode_; | 73 Mode mode_; |
68 | 74 |
69 // After accepting one client connection on our server socket we want to | 75 // After accepting one client connection on our server socket we want to |
70 // stop listening. | 76 // stop listening. |
71 MessageLoopForIO::FileDescriptorWatcher server_listen_connection_watcher_; | 77 MessageLoopForIO::FileDescriptorWatcher server_listen_connection_watcher_; |
72 MessageLoopForIO::FileDescriptorWatcher read_watcher_; | 78 MessageLoopForIO::FileDescriptorWatcher read_watcher_; |
73 MessageLoopForIO::FileDescriptorWatcher write_watcher_; | 79 MessageLoopForIO::FileDescriptorWatcher write_watcher_; |
74 | 80 |
75 // Indicates whether we're currently blocked waiting for a write to complete. | 81 // Indicates whether we're currently blocked waiting for a write to complete. |
76 bool is_blocked_on_write_; | 82 bool is_blocked_on_write_; |
83 bool waiting_connect_; | |
77 | 84 |
78 // If sending a message blocks then we use this variable | 85 // If sending a message blocks then we use this variable |
79 // to keep track of where we are. | 86 // to keep track of where we are. |
80 size_t message_send_bytes_written_; | 87 size_t message_send_bytes_written_; |
81 | 88 |
82 // If the kTestingChannelID flag is specified, we use a FIFO instead of | 89 // File descriptor we're listening on for new connections if we listen |
83 // a socketpair(). | 90 // 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_; | 91 int server_listen_pipe_; |
89 | 92 |
90 // The pipe used for communication. | 93 // The pipe used for communication. |
91 int pipe_; | 94 int pipe_; |
92 | 95 |
93 // For a server, the client end of our socketpair() -- the other end of our | 96 // For a server, the client end of our socketpair() -- the other end of our |
94 // pipe_ that is passed to the client. | 97 // pipe_ that is passed to the client. |
95 int client_pipe_; | 98 int client_pipe_; |
96 | 99 |
97 #if defined(IPC_USES_READWRITE) | 100 #if defined(IPC_USES_READWRITE) |
(...skipping 27 matching lines...) Expand all Loading... | |
125 char input_cmsg_buf_[1024]; | 128 char input_cmsg_buf_[1024]; |
126 #else | 129 #else |
127 char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * MAX_READ_FDS)]; | 130 char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * MAX_READ_FDS)]; |
128 #endif | 131 #endif |
129 | 132 |
130 // Large messages that span multiple pipe buffers, get built-up using | 133 // Large messages that span multiple pipe buffers, get built-up using |
131 // this buffer. | 134 // this buffer. |
132 std::string input_overflow_buf_; | 135 std::string input_overflow_buf_; |
133 std::vector<int> input_overflow_fds_; | 136 std::vector<int> input_overflow_fds_; |
134 | 137 |
135 // In server-mode, we have to wait for the client to connect before we | 138 // true if we responsible for unlinking the unix domain socket file. |
Nico
2010/12/10 18:08:03
no verb
dmac
2010/12/13 18:32:29
Done.
| |
136 // can begin reading. We make use of the input_state_ when performing | 139 bool must_unlink_; |
137 // the connect operation in overlapped mode. | |
138 bool waiting_connect_; | |
139 | 140 |
140 ScopedRunnableMethodFactory<ChannelImpl> factory_; | 141 ScopedRunnableMethodFactory<ChannelImpl> factory_; |
141 | 142 |
142 DISALLOW_COPY_AND_ASSIGN(ChannelImpl); | 143 DISALLOW_COPY_AND_ASSIGN(ChannelImpl); |
143 }; | 144 }; |
144 | 145 |
145 } // namespace IPC | 146 } // namespace IPC |
146 | 147 |
147 #endif // IPC_IPC_CHANNEL_POSIX_H_ | 148 #endif // IPC_IPC_CHANNEL_POSIX_H_ |
OLD | NEW |