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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 void DidCompleteRead(const CompletionCallback& callback, int result); | 102 void DidCompleteRead(const CompletionCallback& callback, int result); |
99 void DidCompleteWrite(const CompletionCallback& callback, int result); | 103 void DidCompleteWrite(const CompletionCallback& callback, int result); |
100 void DidCompleteReadWrite(const CompletionCallback& callback, int result); | 104 void DidCompleteReadWrite(const CompletionCallback& callback, int result); |
101 | 105 |
102 int OpenSocket(AddressFamily family); | 106 int OpenSocket(AddressFamily family); |
103 | 107 |
104 // Emits histograms for TCP metrics, at the time the socket is | 108 // Emits histograms for TCP metrics, at the time the socket is |
105 // disconnected. | 109 // disconnected. |
106 void EmitTCPMetricsHistogramsOnDisconnect(); | 110 void EmitTCPMetricsHistogramsOnDisconnect(); |
107 | 111 |
| 112 // Socket performance statistics (such as RTT) are reported to the |
| 113 // |socket_performance_watcher_|. May be nullptr. |
| 114 SocketPerformanceWatcher* socket_performance_watcher_; |
| 115 |
108 scoped_ptr<TCPSocket> socket_; | 116 scoped_ptr<TCPSocket> socket_; |
109 | 117 |
110 // Local IP address and port we are bound to. Set to NULL if Bind() | 118 // Local IP address and port we are bound to. Set to NULL if Bind() |
111 // wasn't called (in that case OS chooses address/port). | 119 // wasn't called (in that case OS chooses address/port). |
112 scoped_ptr<IPEndPoint> bind_address_; | 120 scoped_ptr<IPEndPoint> bind_address_; |
113 | 121 |
114 // The list of addresses we should try in order to establish a connection. | 122 // The list of addresses we should try in order to establish a connection. |
115 AddressList addresses_; | 123 AddressList addresses_; |
116 | 124 |
117 // Where we are in above list. Set to -1 if uninitialized. | 125 // Where we are in above list. Set to -1 if uninitialized. |
(...skipping 17 matching lines...) Expand all Loading... |
135 | 143 |
136 // Total number of bytes received by the socket. | 144 // Total number of bytes received by the socket. |
137 int64_t total_received_bytes_; | 145 int64_t total_received_bytes_; |
138 | 146 |
139 DISALLOW_COPY_AND_ASSIGN(TCPClientSocket); | 147 DISALLOW_COPY_AND_ASSIGN(TCPClientSocket); |
140 }; | 148 }; |
141 | 149 |
142 } // namespace net | 150 } // namespace net |
143 | 151 |
144 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_H_ | 152 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_H_ |
OLD | NEW |