OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_CLIENT_SOCKET_H_ | 5 #ifndef NET_SOCKET_TCP_CLIENT_SOCKET_H_ |
6 #define NET_SOCKET_TCP_CLIENT_SOCKET_H_ | 6 #define NET_SOCKET_TCP_CLIENT_SOCKET_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "net/base/address_list.h" | 13 #include "net/base/address_list.h" |
14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
15 #include "net/base/net_export.h" | 15 #include "net/base/net_export.h" |
16 #include "net/log/net_log.h" | 16 #include "net/log/net_log.h" |
17 #include "net/socket/connection_attempts.h" | 17 #include "net/socket/connection_attempts.h" |
18 #include "net/socket/stream_socket.h" | 18 #include "net/socket/stream_socket.h" |
19 #include "net/socket/tcp_socket.h" | 19 #include "net/socket/tcp_socket.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 | 22 |
| 23 class SocketPerformanceWatcher; |
| 24 |
23 // A client socket that uses TCP as the transport layer. | 25 // A client socket that uses TCP as the transport layer. |
24 class NET_EXPORT TCPClientSocket : public StreamSocket { | 26 class NET_EXPORT TCPClientSocket : public StreamSocket { |
25 public: | 27 public: |
26 // The IP address(es) and port number to connect to. The TCP socket will try | 28 // The IP address(es) and port number to connect to. The TCP socket will try |
27 // each IP address in the list until it succeeds in establishing a | 29 // each IP address in the list until it succeeds in establishing a |
28 // connection. | 30 // connection. |
29 TCPClientSocket(const AddressList& addresses, | 31 TCPClientSocket( |
30 net::NetLog* net_log, | 32 const AddressList& addresses, |
31 const net::NetLog::Source& source); | 33 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
| 34 net::NetLog* net_log, |
| 35 const net::NetLog::Source& source); |
32 | 36 |
33 // Adopts the given, connected socket and then acts as if Connect() had been | 37 // Adopts the given, connected socket and then acts as if Connect() had been |
34 // called. This function is used by TCPServerSocket and for testing. | 38 // called. This function is used by TCPServerSocket and for testing. |
35 TCPClientSocket(scoped_ptr<TCPSocket> connected_socket, | 39 TCPClientSocket(scoped_ptr<TCPSocket> connected_socket, |
36 const IPEndPoint& peer_address); | 40 const IPEndPoint& peer_address); |
37 | 41 |
38 ~TCPClientSocket() override; | 42 ~TCPClientSocket() override; |
39 | 43 |
40 // Binds the socket to a local IP address and port. | 44 // Binds the socket to a local IP address and port. |
41 int Bind(const IPEndPoint& address); | 45 int Bind(const IPEndPoint& address); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 void DidCompleteRead(const CompletionCallback& callback, int result); | 101 void DidCompleteRead(const CompletionCallback& callback, int result); |
98 void DidCompleteWrite(const CompletionCallback& callback, int result); | 102 void DidCompleteWrite(const CompletionCallback& callback, int result); |
99 void DidCompleteReadWrite(const CompletionCallback& callback, int result); | 103 void DidCompleteReadWrite(const CompletionCallback& callback, int result); |
100 | 104 |
101 int OpenSocket(AddressFamily family); | 105 int OpenSocket(AddressFamily family); |
102 | 106 |
103 // Emits histograms for TCP metrics, at the time the socket is | 107 // Emits histograms for TCP metrics, at the time the socket is |
104 // disconnected. | 108 // disconnected. |
105 void EmitTCPMetricsHistogramsOnDisconnect(); | 109 void EmitTCPMetricsHistogramsOnDisconnect(); |
106 | 110 |
| 111 // Socket performance statistics (such as RTT) are reported to the |
| 112 // |socket_performance_watcher_|. May be nullptr. |
| 113 SocketPerformanceWatcher* socket_performance_watcher_; |
| 114 |
107 scoped_ptr<TCPSocket> socket_; | 115 scoped_ptr<TCPSocket> socket_; |
108 | 116 |
109 // Local IP address and port we are bound to. Set to NULL if Bind() | 117 // Local IP address and port we are bound to. Set to NULL if Bind() |
110 // wasn't called (in that case OS chooses address/port). | 118 // wasn't called (in that case OS chooses address/port). |
111 scoped_ptr<IPEndPoint> bind_address_; | 119 scoped_ptr<IPEndPoint> bind_address_; |
112 | 120 |
113 // The list of addresses we should try in order to establish a connection. | 121 // The list of addresses we should try in order to establish a connection. |
114 AddressList addresses_; | 122 AddressList addresses_; |
115 | 123 |
116 // Where we are in above list. Set to -1 if uninitialized. | 124 // Where we are in above list. Set to -1 if uninitialized. |
(...skipping 11 matching lines...) Expand all Loading... |
128 // Record of connectivity and transmissions, for use in speculative connection | 136 // Record of connectivity and transmissions, for use in speculative connection |
129 // histograms. | 137 // histograms. |
130 UseHistory use_history_; | 138 UseHistory use_history_; |
131 | 139 |
132 // Failed connection attempts made while trying to connect this socket. | 140 // Failed connection attempts made while trying to connect this socket. |
133 ConnectionAttempts connection_attempts_; | 141 ConnectionAttempts connection_attempts_; |
134 | 142 |
135 // Total number of bytes received by the socket. | 143 // Total number of bytes received by the socket. |
136 int64_t total_received_bytes_; | 144 int64_t total_received_bytes_; |
137 | 145 |
| 146 // True if the |socket_performance_watcher_| should be notified that the |
| 147 // socket has been reset. |
| 148 bool notify_reset_socket_performance_watcher_; |
| 149 |
138 DISALLOW_COPY_AND_ASSIGN(TCPClientSocket); | 150 DISALLOW_COPY_AND_ASSIGN(TCPClientSocket); |
139 }; | 151 }; |
140 | 152 |
141 } // namespace net | 153 } // namespace net |
142 | 154 |
143 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_H_ | 155 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_H_ |
OLD | NEW |