OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 NET_SOCKET_TCP_SOCKET_POSIX_H_ | 5 #ifndef NET_SOCKET_TCP_SOCKET_POSIX_H_ |
6 #define NET_SOCKET_TCP_SOCKET_POSIX_H_ | 6 #define NET_SOCKET_TCP_SOCKET_POSIX_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "net/base/address_family.h" | 15 #include "net/base/address_family.h" |
16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
17 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
| 18 #include "net/base/socket_performance_watcher.h" |
18 #include "net/log/net_log.h" | 19 #include "net/log/net_log.h" |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 | 22 |
22 class AddressList; | 23 class AddressList; |
23 class IOBuffer; | 24 class IOBuffer; |
24 class IPEndPoint; | 25 class IPEndPoint; |
25 class SocketPosix; | 26 class SocketPosix; |
26 | 27 |
27 class NET_EXPORT TCPSocketPosix { | 28 class NET_EXPORT TCPSocketPosix { |
28 public: | 29 public: |
29 TCPSocketPosix(NetLog* net_log, const NetLog::Source& source); | 30 TCPSocketPosix( |
| 31 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
| 32 NetLog* net_log, |
| 33 const NetLog::Source& source); |
30 virtual ~TCPSocketPosix(); | 34 virtual ~TCPSocketPosix(); |
31 | 35 |
32 int Open(AddressFamily family); | 36 int Open(AddressFamily family); |
33 // Takes ownership of |socket_fd|. | 37 // Takes ownership of |socket_fd|. |
34 int AdoptConnectedSocket(int socket_fd, const IPEndPoint& peer_address); | 38 int AdoptConnectedSocket(int socket_fd, const IPEndPoint& peer_address); |
35 | 39 |
36 int Bind(const IPEndPoint& address); | 40 int Bind(const IPEndPoint& address); |
37 | 41 |
38 int Listen(int backlog); | 42 int Listen(int backlog); |
39 int Accept(scoped_ptr<TCPSocketPosix>* socket, | 43 int Accept(scoped_ptr<TCPSocketPosix>* socket, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 void AcceptCompleted(scoped_ptr<TCPSocketPosix>* tcp_socket, | 174 void AcceptCompleted(scoped_ptr<TCPSocketPosix>* tcp_socket, |
171 IPEndPoint* address, | 175 IPEndPoint* address, |
172 const CompletionCallback& callback, | 176 const CompletionCallback& callback, |
173 int rv); | 177 int rv); |
174 int HandleAcceptCompleted(scoped_ptr<TCPSocketPosix>* tcp_socket, | 178 int HandleAcceptCompleted(scoped_ptr<TCPSocketPosix>* tcp_socket, |
175 IPEndPoint* address, | 179 IPEndPoint* address, |
176 int rv); | 180 int rv); |
177 int BuildTcpSocketPosix(scoped_ptr<TCPSocketPosix>* tcp_socket, | 181 int BuildTcpSocketPosix(scoped_ptr<TCPSocketPosix>* tcp_socket, |
178 IPEndPoint* address); | 182 IPEndPoint* address); |
179 | 183 |
180 void ConnectCompleted(const CompletionCallback& callback, int rv) const; | 184 void ConnectCompleted(const CompletionCallback& callback, int rv); |
181 int HandleConnectCompleted(int rv) const; | 185 int HandleConnectCompleted(int rv) const; |
182 void LogConnectBegin(const AddressList& addresses) const; | 186 void LogConnectBegin(const AddressList& addresses) const; |
183 void LogConnectEnd(int net_error) const; | 187 void LogConnectEnd(int net_error) const; |
184 | 188 |
185 void ReadCompleted(const scoped_refptr<IOBuffer>& buf, | 189 void ReadCompleted(const scoped_refptr<IOBuffer>& buf, |
186 const CompletionCallback& callback, | 190 const CompletionCallback& callback, |
187 int rv); | 191 int rv); |
188 int HandleReadCompleted(IOBuffer* buf, int rv); | 192 int HandleReadCompleted(IOBuffer* buf, int rv); |
189 | 193 |
190 void WriteCompleted(const scoped_refptr<IOBuffer>& buf, | 194 void WriteCompleted(const scoped_refptr<IOBuffer>& buf, |
191 const CompletionCallback& callback, | 195 const CompletionCallback& callback, |
192 int rv); | 196 int rv); |
193 int HandleWriteCompleted(IOBuffer* buf, int rv); | 197 int HandleWriteCompleted(IOBuffer* buf, int rv); |
194 int TcpFastOpenWrite(IOBuffer* buf, | 198 int TcpFastOpenWrite(IOBuffer* buf, |
195 int buf_len, | 199 int buf_len, |
196 const CompletionCallback& callback); | 200 const CompletionCallback& callback); |
197 | 201 |
| 202 // Notifies |socket_performance_watcher_| of the latest RTT estimate available |
| 203 // from the tcp_info struct for this TCP socket. |
| 204 void NotifySocketPerformanceWatcher(); |
| 205 |
198 // Called after the first read completes on a TCP FastOpen socket. | 206 // Called after the first read completes on a TCP FastOpen socket. |
199 void UpdateTCPFastOpenStatusAfterRead(); | 207 void UpdateTCPFastOpenStatusAfterRead(); |
200 | 208 |
201 scoped_ptr<SocketPosix> socket_; | 209 scoped_ptr<SocketPosix> socket_; |
202 scoped_ptr<SocketPosix> accept_socket_; | 210 scoped_ptr<SocketPosix> accept_socket_; |
203 | 211 |
| 212 // Socket performance statistics (such as RTT) are reported to the |
| 213 // |socket_performance_watcher_|. May be nullptr. |
| 214 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher_; |
| 215 |
204 // Enables experimental TCP FastOpen option. | 216 // Enables experimental TCP FastOpen option. |
205 bool use_tcp_fastopen_; | 217 bool use_tcp_fastopen_; |
206 | 218 |
207 // True when TCP FastOpen is in use and we have attempted the | 219 // True when TCP FastOpen is in use and we have attempted the |
208 // connect with write. | 220 // connect with write. |
209 bool tcp_fastopen_write_attempted_; | 221 bool tcp_fastopen_write_attempted_; |
210 | 222 |
211 // True when TCP FastOpen is in use and we have done the connect. | 223 // True when TCP FastOpen is in use and we have done the connect. |
212 bool tcp_fastopen_connected_; | 224 bool tcp_fastopen_connected_; |
213 | 225 |
214 TCPFastOpenStatus tcp_fastopen_status_; | 226 TCPFastOpenStatus tcp_fastopen_status_; |
215 | 227 |
216 bool logging_multiple_connect_attempts_; | 228 bool logging_multiple_connect_attempts_; |
217 | 229 |
218 BoundNetLog net_log_; | 230 BoundNetLog net_log_; |
219 | 231 |
220 DISALLOW_COPY_AND_ASSIGN(TCPSocketPosix); | 232 DISALLOW_COPY_AND_ASSIGN(TCPSocketPosix); |
221 }; | 233 }; |
222 | 234 |
223 } // namespace net | 235 } // namespace net |
224 | 236 |
225 #endif // NET_SOCKET_TCP_SOCKET_POSIX_H_ | 237 #endif // NET_SOCKET_TCP_SOCKET_POSIX_H_ |
OLD | NEW |