OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "net/socket/tcp_client_socket.h" | 5 #include "net/socket/tcp_client_socket.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <netdb.h> | 9 #include <netdb.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 143 |
144 // If already connected, then just return OK. | 144 // If already connected, then just return OK. |
145 if (socket_ != kInvalidSocket) | 145 if (socket_ != kInvalidSocket) |
146 return OK; | 146 return OK; |
147 | 147 |
148 static base::StatsCounter connects("tcp.connect"); | 148 static base::StatsCounter connects("tcp.connect"); |
149 connects.Increment(); | 149 connects.Increment(); |
150 | 150 |
151 DCHECK(!waiting_connect()); | 151 DCHECK(!waiting_connect()); |
152 | 152 |
153 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT, | 153 net_log_.BeginEvent( |
154 new AddressListNetLogParam(addresses_)); | 154 NetLog::TYPE_TCP_CONNECT, |
| 155 make_scoped_refptr(new AddressListNetLogParam(addresses_))); |
155 | 156 |
156 // We will try to connect to each address in addresses_. Start with the | 157 // We will try to connect to each address in addresses_. Start with the |
157 // first one in the list. | 158 // first one in the list. |
158 next_connect_state_ = CONNECT_STATE_CONNECT; | 159 next_connect_state_ = CONNECT_STATE_CONNECT; |
159 current_ai_ = addresses_.head(); | 160 current_ai_ = addresses_.head(); |
160 | 161 |
161 int rv = DoConnectLoop(OK); | 162 int rv = DoConnectLoop(OK); |
162 if (rv == ERR_IO_PENDING) { | 163 if (rv == ERR_IO_PENDING) { |
163 // Synchronous operation not supported. | 164 // Synchronous operation not supported. |
164 DCHECK(callback); | 165 DCHECK(callback); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 DCHECK(current_ai_); | 200 DCHECK(current_ai_); |
200 | 201 |
201 DCHECK_EQ(0, connect_os_error_); | 202 DCHECK_EQ(0, connect_os_error_); |
202 | 203 |
203 if (previously_disconnected_) { | 204 if (previously_disconnected_) { |
204 use_history_.Reset(); | 205 use_history_.Reset(); |
205 previously_disconnected_ = false; | 206 previously_disconnected_ = false; |
206 } | 207 } |
207 | 208 |
208 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, | 209 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, |
209 new NetLogStringParameter( | 210 make_scoped_refptr(new NetLogStringParameter( |
210 "address", NetAddressToStringWithPort(current_ai_))); | 211 "address", NetAddressToStringWithPort(current_ai_)))); |
211 | 212 |
212 next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE; | 213 next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE; |
213 | 214 |
214 // Create a non-blocking socket. | 215 // Create a non-blocking socket. |
215 connect_os_error_ = CreateSocket(current_ai_); | 216 connect_os_error_ = CreateSocket(current_ai_); |
216 if (connect_os_error_) | 217 if (connect_os_error_) |
217 return MapPosixError(connect_os_error_); | 218 return MapPosixError(connect_os_error_); |
218 | 219 |
219 // Connect the socket. | 220 // Connect the socket. |
220 if (!use_tcp_fastopen_) { | 221 if (!use_tcp_fastopen_) { |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 | 602 |
602 bool TCPClientSocketLibevent::WasEverUsed() const { | 603 bool TCPClientSocketLibevent::WasEverUsed() const { |
603 return use_history_.was_used_to_convey_data(); | 604 return use_history_.was_used_to_convey_data(); |
604 } | 605 } |
605 | 606 |
606 bool TCPClientSocketLibevent::UsingTCPFastOpen() const { | 607 bool TCPClientSocketLibevent::UsingTCPFastOpen() const { |
607 return use_tcp_fastopen_; | 608 return use_tcp_fastopen_; |
608 } | 609 } |
609 | 610 |
610 } // namespace net | 611 } // namespace net |
OLD | NEW |