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 |
21 namespace base { | |
22 class TickClock; | |
23 } | |
24 | |
20 namespace net { | 25 namespace net { |
21 | 26 |
22 class AddressList; | 27 class AddressList; |
23 class IOBuffer; | 28 class IOBuffer; |
24 class IPEndPoint; | 29 class IPEndPoint; |
25 class SocketPosix; | 30 class SocketPosix; |
26 | 31 |
27 class NET_EXPORT TCPSocketPosix { | 32 class NET_EXPORT TCPSocketPosix { |
28 public: | 33 public: |
29 TCPSocketPosix(NetLog* net_log, const NetLog::Source& source); | 34 // |socket_performance_watcher| is notified of the performance metrics related |
35 // to this socket. |socket_performance_watcher| may be null. | |
36 TCPSocketPosix( | |
37 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher, | |
38 NetLog* net_log, | |
39 const NetLog::Source& source); | |
30 virtual ~TCPSocketPosix(); | 40 virtual ~TCPSocketPosix(); |
31 | 41 |
32 int Open(AddressFamily family); | 42 int Open(AddressFamily family); |
33 // Takes ownership of |socket_fd|. | 43 // Takes ownership of |socket_fd|. |
34 int AdoptConnectedSocket(int socket_fd, const IPEndPoint& peer_address); | 44 int AdoptConnectedSocket(int socket_fd, const IPEndPoint& peer_address); |
35 | 45 |
36 int Bind(const IPEndPoint& address); | 46 int Bind(const IPEndPoint& address); |
37 | 47 |
38 int Listen(int backlog); | 48 int Listen(int backlog); |
39 int Accept(scoped_ptr<TCPSocketPosix>* socket, | 49 int Accept(scoped_ptr<TCPSocketPosix>* socket, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 // succeeds in establishing a connection. The corresponding log will have | 98 // succeeds in establishing a connection. The corresponding log will have |
89 // multiple NetLog::TYPE_TCP_CONNECT_ATTEMPT entries nested within a | 99 // multiple NetLog::TYPE_TCP_CONNECT_ATTEMPT entries nested within a |
90 // NetLog::TYPE_TCP_CONNECT. These methods set the start/end of | 100 // NetLog::TYPE_TCP_CONNECT. These methods set the start/end of |
91 // NetLog::TYPE_TCP_CONNECT. | 101 // NetLog::TYPE_TCP_CONNECT. |
92 // | 102 // |
93 // TODO(yzshen): Change logging format and let TCPClientSocket log the | 103 // TODO(yzshen): Change logging format and let TCPClientSocket log the |
94 // start/end of a series of connect attempts itself. | 104 // start/end of a series of connect attempts itself. |
95 void StartLoggingMultipleConnectAttempts(const AddressList& addresses); | 105 void StartLoggingMultipleConnectAttempts(const AddressList& addresses); |
96 void EndLoggingMultipleConnectAttempts(int net_error); | 106 void EndLoggingMultipleConnectAttempts(int net_error); |
97 | 107 |
108 void SetTickClockForTesting(scoped_ptr<base::TickClock> tick_clock); | |
109 | |
98 const BoundNetLog& net_log() const { return net_log_; } | 110 const BoundNetLog& net_log() const { return net_log_; } |
99 | 111 |
100 private: | 112 private: |
101 // States that using a socket with TCP FastOpen can lead to. | 113 // States that using a socket with TCP FastOpen can lead to. |
102 enum TCPFastOpenStatus { | 114 enum TCPFastOpenStatus { |
103 TCP_FASTOPEN_STATUS_UNKNOWN, | 115 TCP_FASTOPEN_STATUS_UNKNOWN, |
104 | 116 |
105 // The initial FastOpen connect attempted returned synchronously, | 117 // The initial FastOpen connect attempted returned synchronously, |
106 // indicating that we had and sent a cookie along with the initial data. | 118 // indicating that we had and sent a cookie along with the initial data. |
107 TCP_FASTOPEN_FAST_CONNECT_RETURN, | 119 TCP_FASTOPEN_FAST_CONNECT_RETURN, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 void AcceptCompleted(scoped_ptr<TCPSocketPosix>* tcp_socket, | 182 void AcceptCompleted(scoped_ptr<TCPSocketPosix>* tcp_socket, |
171 IPEndPoint* address, | 183 IPEndPoint* address, |
172 const CompletionCallback& callback, | 184 const CompletionCallback& callback, |
173 int rv); | 185 int rv); |
174 int HandleAcceptCompleted(scoped_ptr<TCPSocketPosix>* tcp_socket, | 186 int HandleAcceptCompleted(scoped_ptr<TCPSocketPosix>* tcp_socket, |
175 IPEndPoint* address, | 187 IPEndPoint* address, |
176 int rv); | 188 int rv); |
177 int BuildTcpSocketPosix(scoped_ptr<TCPSocketPosix>* tcp_socket, | 189 int BuildTcpSocketPosix(scoped_ptr<TCPSocketPosix>* tcp_socket, |
178 IPEndPoint* address); | 190 IPEndPoint* address); |
179 | 191 |
180 void ConnectCompleted(const CompletionCallback& callback, int rv) const; | 192 void ConnectCompleted(const CompletionCallback& callback, int rv); |
181 int HandleConnectCompleted(int rv) const; | 193 int HandleConnectCompleted(int rv); |
182 void LogConnectBegin(const AddressList& addresses) const; | 194 void LogConnectBegin(const AddressList& addresses) const; |
183 void LogConnectEnd(int net_error) const; | 195 void LogConnectEnd(int net_error) const; |
184 | 196 |
185 void ReadCompleted(const scoped_refptr<IOBuffer>& buf, | 197 void ReadCompleted(const scoped_refptr<IOBuffer>& buf, |
186 const CompletionCallback& callback, | 198 const CompletionCallback& callback, |
187 int rv); | 199 int rv); |
188 int HandleReadCompleted(IOBuffer* buf, int rv); | 200 int HandleReadCompleted(IOBuffer* buf, int rv); |
189 | 201 |
190 void WriteCompleted(const scoped_refptr<IOBuffer>& buf, | 202 void WriteCompleted(const scoped_refptr<IOBuffer>& buf, |
191 const CompletionCallback& callback, | 203 const CompletionCallback& callback, |
192 int rv); | 204 int rv); |
193 int HandleWriteCompleted(IOBuffer* buf, int rv); | 205 int HandleWriteCompleted(IOBuffer* buf, int rv); |
194 int TcpFastOpenWrite(IOBuffer* buf, | 206 int TcpFastOpenWrite(IOBuffer* buf, |
195 int buf_len, | 207 int buf_len, |
196 const CompletionCallback& callback); | 208 const CompletionCallback& callback); |
197 | 209 |
210 // Notifies |socket_performance_watcher_| of the latest RTT estimate available | |
211 // from the tcp_info struct for this TCP socket. | |
212 void NotifySocketPerformanceWatcher(); | |
213 | |
198 // Called after the first read completes on a TCP FastOpen socket. | 214 // Called after the first read completes on a TCP FastOpen socket. |
199 void UpdateTCPFastOpenStatusAfterRead(); | 215 void UpdateTCPFastOpenStatusAfterRead(); |
200 | 216 |
217 // Minimum interval betweeen consecutive notifications to | |
218 // |socket_performance_watcher_|. | |
219 const base::TimeDelta rtt_notifications_minimum_interval_; | |
Ryan Sleevi
2016/04/11 22:06:56
This seems like a very odd ordering to add this me
tbansal1
2016/04/12 16:14:33
Done.
| |
220 | |
201 scoped_ptr<SocketPosix> socket_; | 221 scoped_ptr<SocketPosix> socket_; |
202 scoped_ptr<SocketPosix> accept_socket_; | 222 scoped_ptr<SocketPosix> accept_socket_; |
203 | 223 |
224 // Socket performance statistics (such as RTT) are reported to the | |
225 // |socket_performance_watcher_|. May be nullptr. | |
226 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher_; | |
227 | |
228 scoped_ptr<base::TickClock> tick_clock_; | |
229 | |
230 // Time when the |socket_performance_watcher_| was last notified of updated | |
231 // RTT. | |
232 base::TimeTicks last_rtt_notification_; | |
233 | |
204 // Enables experimental TCP FastOpen option. | 234 // Enables experimental TCP FastOpen option. |
205 bool use_tcp_fastopen_; | 235 bool use_tcp_fastopen_; |
206 | 236 |
207 // True when TCP FastOpen is in use and we have attempted the | 237 // True when TCP FastOpen is in use and we have attempted the |
208 // connect with write. | 238 // connect with write. |
209 bool tcp_fastopen_write_attempted_; | 239 bool tcp_fastopen_write_attempted_; |
210 | 240 |
211 // True when TCP FastOpen is in use and we have done the connect. | 241 // True when TCP FastOpen is in use and we have done the connect. |
212 bool tcp_fastopen_connected_; | 242 bool tcp_fastopen_connected_; |
213 | 243 |
214 TCPFastOpenStatus tcp_fastopen_status_; | 244 TCPFastOpenStatus tcp_fastopen_status_; |
215 | 245 |
216 bool logging_multiple_connect_attempts_; | 246 bool logging_multiple_connect_attempts_; |
217 | 247 |
218 BoundNetLog net_log_; | 248 BoundNetLog net_log_; |
219 | 249 |
220 DISALLOW_COPY_AND_ASSIGN(TCPSocketPosix); | 250 DISALLOW_COPY_AND_ASSIGN(TCPSocketPosix); |
221 }; | 251 }; |
222 | 252 |
223 } // namespace net | 253 } // namespace net |
224 | 254 |
225 #endif // NET_SOCKET_TCP_SOCKET_POSIX_H_ | 255 #endif // NET_SOCKET_TCP_SOCKET_POSIX_H_ |
OLD | NEW |