Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: ipc/ipc_channel_posix.h

Issue 5749001: Add support for sockets that can listen and accept a connection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix up use of DCHECK which was causing release build failures Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_channel.h ('k') | ipc/ipc_channel_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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,
61 bool listening_socket);
59 62
60 bool ProcessIncomingMessages(); 63 bool ProcessIncomingMessages();
61 bool ProcessOutgoingMessages(); 64 bool ProcessOutgoingMessages();
62 65
66 bool AcceptConnection();
67 void ClosePipeOnError();
68 void QueueHelloMessage();
69 bool IsHelloMessage(const Message* m) const;
70
63 // MessageLoopForIO::Watcher implementation. 71 // MessageLoopForIO::Watcher implementation.
64 virtual void OnFileCanReadWithoutBlocking(int fd); 72 virtual void OnFileCanReadWithoutBlocking(int fd);
65 virtual void OnFileCanWriteWithoutBlocking(int fd); 73 virtual void OnFileCanWriteWithoutBlocking(int fd);
66 74
67 Mode mode_; 75 Mode mode_;
68 76
69 // After accepting one client connection on our server socket we want to 77 // After accepting one client connection on our server socket we want to
70 // stop listening. 78 // stop listening.
71 MessageLoopForIO::FileDescriptorWatcher server_listen_connection_watcher_; 79 MessageLoopForIO::FileDescriptorWatcher server_listen_connection_watcher_;
72 MessageLoopForIO::FileDescriptorWatcher read_watcher_; 80 MessageLoopForIO::FileDescriptorWatcher read_watcher_;
73 MessageLoopForIO::FileDescriptorWatcher write_watcher_; 81 MessageLoopForIO::FileDescriptorWatcher write_watcher_;
74 82
75 // Indicates whether we're currently blocked waiting for a write to complete. 83 // Indicates whether we're currently blocked waiting for a write to complete.
76 bool is_blocked_on_write_; 84 bool is_blocked_on_write_;
85 bool waiting_connect_;
77 86
78 // If sending a message blocks then we use this variable 87 // If sending a message blocks then we use this variable
79 // to keep track of where we are. 88 // to keep track of where we are.
80 size_t message_send_bytes_written_; 89 size_t message_send_bytes_written_;
81 90
82 // If the kTestingChannelID flag is specified, we use a FIFO instead of 91 // File descriptor we're listening on for new connections if we listen
83 // a socketpair(). 92 // 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_; 93 int server_listen_pipe_;
89 94
90 // The pipe used for communication. 95 // The pipe used for communication.
91 int pipe_; 96 int pipe_;
92 97
93 // For a server, the client end of our socketpair() -- the other end of our 98 // For a server, the client end of our socketpair() -- the other end of our
94 // pipe_ that is passed to the client. 99 // pipe_ that is passed to the client.
95 int client_pipe_; 100 int client_pipe_;
96 101
97 #if defined(IPC_USES_READWRITE) 102 #if defined(IPC_USES_READWRITE)
(...skipping 27 matching lines...) Expand all
125 char input_cmsg_buf_[1024]; 130 char input_cmsg_buf_[1024];
126 #else 131 #else
127 char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * MAX_READ_FDS)]; 132 char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * MAX_READ_FDS)];
128 #endif 133 #endif
129 134
130 // Large messages that span multiple pipe buffers, get built-up using 135 // Large messages that span multiple pipe buffers, get built-up using
131 // this buffer. 136 // this buffer.
132 std::string input_overflow_buf_; 137 std::string input_overflow_buf_;
133 std::vector<int> input_overflow_fds_; 138 std::vector<int> input_overflow_fds_;
134 139
135 // In server-mode, we have to wait for the client to connect before we 140 // 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 141 bool must_unlink_;
137 // the connect operation in overlapped mode.
138 bool waiting_connect_;
139 142
140 ScopedRunnableMethodFactory<ChannelImpl> factory_; 143 ScopedRunnableMethodFactory<ChannelImpl> factory_;
141 144
142 DISALLOW_COPY_AND_ASSIGN(ChannelImpl); 145 DISALLOW_COPY_AND_ASSIGN(ChannelImpl);
143 }; 146 };
144 147
148 // The maximum length of the name of a pipe for MODE_NAMED_SERVER or
149 // MODE_NAMED_CLIENT if you want to pass in your own socket.
150 // The standard size on linux is 108, mac is 104. To maintain consistency
151 // across platforms we standardize on the smaller value.
152 static const size_t kMaxPipeNameLength = 104;
153
145 } // namespace IPC 154 } // namespace IPC
146 155
147 #endif // IPC_IPC_CHANNEL_POSIX_H_ 156 #endif // IPC_IPC_CHANNEL_POSIX_H_
OLDNEW
« no previous file with comments | « ipc/ipc_channel.h ('k') | ipc/ipc_channel_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698