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

Side by Side Diff: ipc/ipc_channel_posix.h

Issue 6060002: Revert 69694 - Add support for sockets that can listen and accept a connectio... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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.
43 class Channel::ChannelImpl : public MessageLoopForIO::Watcher { 45 class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
44 public: 46 public:
45 // Mirror methods of Channel, see ipc_channel.h for description. 47 // Mirror methods of Channel, see ipc_channel.h for description.
46 ChannelImpl(const IPC::ChannelHandle& channel_handle, Mode mode, 48 ChannelImpl(const IPC::ChannelHandle &channel_handle, Mode mode,
47 Listener* listener); 49 Listener* listener);
48 ~ChannelImpl(); 50 ~ChannelImpl();
49 bool Connect(); 51 bool Connect();
50 void Close(); 52 void Close();
51 void set_listener(Listener* listener) { listener_ = listener; } 53 void set_listener(Listener* listener) { listener_ = listener; }
52 bool Send(Message* message); 54 bool Send(Message* message);
53 int GetClientFileDescriptor() const; 55 int GetClientFileDescriptor() const;
54 bool AcceptsConnections() const;
55 bool HasAcceptedConnection() const;
56 void ResetToAcceptingConnectionState();
57 56
58 private: 57 private:
59 bool CreatePipe(const IPC::ChannelHandle& channel_handle, 58 bool CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode);
60 bool uses_domain_sockets,
61 bool listening_socket);
62 59
63 bool ProcessIncomingMessages(); 60 bool ProcessIncomingMessages();
64 bool ProcessOutgoingMessages(); 61 bool ProcessOutgoingMessages();
65 62
66 bool AcceptConnection();
67 void ClosePipeOnError();
68 void QueueHelloMessage();
69 bool IsHelloMessage(const Message* m) const;
70
71 // MessageLoopForIO::Watcher implementation. 63 // MessageLoopForIO::Watcher implementation.
72 virtual void OnFileCanReadWithoutBlocking(int fd); 64 virtual void OnFileCanReadWithoutBlocking(int fd);
73 virtual void OnFileCanWriteWithoutBlocking(int fd); 65 virtual void OnFileCanWriteWithoutBlocking(int fd);
74 66
75 Mode mode_; 67 Mode mode_;
76 68
77 // After accepting one client connection on our server socket we want to 69 // After accepting one client connection on our server socket we want to
78 // stop listening. 70 // stop listening.
79 MessageLoopForIO::FileDescriptorWatcher server_listen_connection_watcher_; 71 MessageLoopForIO::FileDescriptorWatcher server_listen_connection_watcher_;
80 MessageLoopForIO::FileDescriptorWatcher read_watcher_; 72 MessageLoopForIO::FileDescriptorWatcher read_watcher_;
81 MessageLoopForIO::FileDescriptorWatcher write_watcher_; 73 MessageLoopForIO::FileDescriptorWatcher write_watcher_;
82 74
83 // Indicates whether we're currently blocked waiting for a write to complete. 75 // Indicates whether we're currently blocked waiting for a write to complete.
84 bool is_blocked_on_write_; 76 bool is_blocked_on_write_;
85 bool waiting_connect_;
86 77
87 // If sending a message blocks then we use this variable 78 // If sending a message blocks then we use this variable
88 // to keep track of where we are. 79 // to keep track of where we are.
89 size_t message_send_bytes_written_; 80 size_t message_send_bytes_written_;
90 81
91 // File descriptor we're listening on for new connections if we listen 82 // If the kTestingChannelID flag is specified, we use a FIFO instead of
92 // for connections. 83 // a socketpair().
84 bool uses_fifo_;
85
86 // File descriptor we're listening on for new connections in the FIFO case;
87 // unused otherwise.
93 int server_listen_pipe_; 88 int server_listen_pipe_;
94 89
95 // The pipe used for communication. 90 // The pipe used for communication.
96 int pipe_; 91 int pipe_;
97 92
98 // For a server, the client end of our socketpair() -- the other end of our 93 // For a server, the client end of our socketpair() -- the other end of our
99 // pipe_ that is passed to the client. 94 // pipe_ that is passed to the client.
100 int client_pipe_; 95 int client_pipe_;
101 96
102 #if defined(IPC_USES_READWRITE) 97 #if defined(IPC_USES_READWRITE)
(...skipping 27 matching lines...) Expand all
130 char input_cmsg_buf_[1024]; 125 char input_cmsg_buf_[1024];
131 #else 126 #else
132 char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * MAX_READ_FDS)]; 127 char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * MAX_READ_FDS)];
133 #endif 128 #endif
134 129
135 // Large messages that span multiple pipe buffers, get built-up using 130 // Large messages that span multiple pipe buffers, get built-up using
136 // this buffer. 131 // this buffer.
137 std::string input_overflow_buf_; 132 std::string input_overflow_buf_;
138 std::vector<int> input_overflow_fds_; 133 std::vector<int> input_overflow_fds_;
139 134
140 // True if we are responsible for unlinking the unix domain socket file. 135 // In server-mode, we have to wait for the client to connect before we
141 bool must_unlink_; 136 // can begin reading. We make use of the input_state_ when performing
137 // the connect operation in overlapped mode.
138 bool waiting_connect_;
142 139
143 ScopedRunnableMethodFactory<ChannelImpl> factory_; 140 ScopedRunnableMethodFactory<ChannelImpl> factory_;
144 141
145 DISALLOW_COPY_AND_ASSIGN(ChannelImpl); 142 DISALLOW_COPY_AND_ASSIGN(ChannelImpl);
146 }; 143 };
147 144
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
154 } // namespace IPC 145 } // namespace IPC
155 146
156 #endif // IPC_IPC_CHANNEL_POSIX_H_ 147 #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