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 #include "net/socket/tcp_socket.h" | 5 #include "net/socket/tcp_socket.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <netinet/tcp.h> | 8 #include <netinet/tcp.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... | |
32 | 32 |
33 namespace net { | 33 namespace net { |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 // True if OS supports TCP FastOpen. | 37 // True if OS supports TCP FastOpen. |
38 bool g_tcp_fastopen_supported = false; | 38 bool g_tcp_fastopen_supported = false; |
39 // True if TCP FastOpen is user-enabled for all connections. | 39 // True if TCP FastOpen is user-enabled for all connections. |
40 // TODO(jri): Change global variable to param in HttpNetworkSession::Params. | 40 // TODO(jri): Change global variable to param in HttpNetworkSession::Params. |
41 bool g_tcp_fastopen_user_enabled = false; | 41 bool g_tcp_fastopen_user_enabled = false; |
42 // True if TCP FastOpen connect-with-write has failed at least once. | |
43 bool g_tcp_fastopen_has_failed = false; | |
44 | |
42 | 45 |
43 // SetTCPNoDelay turns on/off buffering in the kernel. By default, TCP sockets | 46 // SetTCPNoDelay turns on/off buffering in the kernel. By default, TCP sockets |
44 // will wait up to 200ms for more data to complete a packet before transmitting. | 47 // will wait up to 200ms for more data to complete a packet before transmitting. |
45 // After calling this function, the kernel will not wait. See TCP_NODELAY in | 48 // After calling this function, the kernel will not wait. See TCP_NODELAY in |
46 // `man 7 tcp`. | 49 // `man 7 tcp`. |
47 bool SetTCPNoDelay(int fd, bool no_delay) { | 50 bool SetTCPNoDelay(int fd, bool no_delay) { |
48 int on = no_delay ? 1 : 0; | 51 int on = no_delay ? 1 : 0; |
49 int error = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); | 52 int error = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); |
50 return error == 0; | 53 return error == 0; |
51 } | 54 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 base::WorkerPool::GetTaskRunner(/*task_is_slow=*/false).get(), | 125 base::WorkerPool::GetTaskRunner(/*task_is_slow=*/false).get(), |
123 FROM_HERE, | 126 FROM_HERE, |
124 base::Bind(SystemSupportsTCPFastOpen), | 127 base::Bind(SystemSupportsTCPFastOpen), |
125 base::Bind(RegisterTCPFastOpenIntentAndSupport, user_enabled)); | 128 base::Bind(RegisterTCPFastOpenIntentAndSupport, user_enabled)); |
126 #endif | 129 #endif |
127 } | 130 } |
128 | 131 |
129 TCPSocketLibevent::TCPSocketLibevent(NetLog* net_log, | 132 TCPSocketLibevent::TCPSocketLibevent(NetLog* net_log, |
130 const NetLog::Source& source) | 133 const NetLog::Source& source) |
131 : use_tcp_fastopen_(false), | 134 : use_tcp_fastopen_(false), |
135 tcp_fastopen_write_attempted_(false), | |
132 tcp_fastopen_connected_(false), | 136 tcp_fastopen_connected_(false), |
133 fast_open_status_(FAST_OPEN_STATUS_UNKNOWN), | 137 tcp_fastopen_status_(FAST_OPEN_STATUS_UNKNOWN), |
134 logging_multiple_connect_attempts_(false), | 138 logging_multiple_connect_attempts_(false), |
135 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { | 139 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { |
136 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, | 140 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, |
137 source.ToEventParametersCallback()); | 141 source.ToEventParametersCallback()); |
138 } | 142 } |
139 | 143 |
140 TCPSocketLibevent::~TCPSocketLibevent() { | 144 TCPSocketLibevent::~TCPSocketLibevent() { |
141 net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE); | 145 net_log_.EndEvent(NetLog::TYPE_SOCKET_ALIVE); |
142 if (tcp_fastopen_connected_) { | 146 if (tcp_fastopen_write_attempted_) { |
143 UMA_HISTOGRAM_ENUMERATION("Net.TcpFastOpenSocketConnection", | 147 UMA_HISTOGRAM_ENUMERATION("Net.TcpFastOpenSocketConnection", |
144 fast_open_status_, FAST_OPEN_MAX_VALUE); | 148 tcp_fastopen_status_, FAST_OPEN_MAX_VALUE); |
mmenke
2014/09/23 15:21:00
You need to update histograms.xml in this CL as we
mmenke
2014/09/23 15:21:00
Since you're significantly changing this histogram
Jana
2014/09/24 00:51:26
I thought about that ... but this histogram doesn'
Jana
2014/09/24 00:51:26
I did add histograms.xml to this CL, but to add my
| |
145 } | 149 } |
146 } | 150 } |
147 | 151 |
148 int TCPSocketLibevent::Open(AddressFamily family) { | 152 int TCPSocketLibevent::Open(AddressFamily family) { |
149 DCHECK(!socket_); | 153 DCHECK(!socket_); |
150 socket_.reset(new SocketLibevent); | 154 socket_.reset(new SocketLibevent); |
151 int rv = socket_->Open(ConvertAddressFamily(family)); | 155 int rv = socket_->Open(ConvertAddressFamily(family)); |
152 if (rv != OK) | 156 if (rv != OK) |
153 socket_.reset(); | 157 socket_.reset(); |
154 return rv; | 158 return rv; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 | 219 |
216 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, | 220 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, |
217 CreateNetLogIPEndPointCallback(&address)); | 221 CreateNetLogIPEndPointCallback(&address)); |
218 | 222 |
219 SockaddrStorage storage; | 223 SockaddrStorage storage; |
220 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) | 224 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) |
221 return ERR_ADDRESS_INVALID; | 225 return ERR_ADDRESS_INVALID; |
222 | 226 |
223 if (use_tcp_fastopen_) { | 227 if (use_tcp_fastopen_) { |
224 // With TCP FastOpen, we pretend that the socket is connected. | 228 // With TCP FastOpen, we pretend that the socket is connected. |
225 DCHECK(!tcp_fastopen_connected_); | 229 DCHECK(!tcp_fastopen_write_attempted_); |
226 socket_->SetPeerAddress(storage); | 230 socket_->SetPeerAddress(storage); |
227 return OK; | 231 return OK; |
228 } | 232 } |
229 | 233 |
230 int rv = socket_->Connect(storage, | 234 int rv = socket_->Connect(storage, |
231 base::Bind(&TCPSocketLibevent::ConnectCompleted, | 235 base::Bind(&TCPSocketLibevent::ConnectCompleted, |
232 base::Unretained(this), callback)); | 236 base::Unretained(this), callback)); |
233 if (rv != ERR_IO_PENDING) | 237 if (rv != ERR_IO_PENDING) |
234 rv = HandleConnectCompleted(rv); | 238 rv = HandleConnectCompleted(rv); |
235 return rv; | 239 return rv; |
236 } | 240 } |
237 | 241 |
238 bool TCPSocketLibevent::IsConnected() const { | 242 bool TCPSocketLibevent::IsConnected() const { |
239 if (!socket_) | 243 if (!socket_) |
240 return false; | 244 return false; |
241 | 245 |
242 if (use_tcp_fastopen_ && !tcp_fastopen_connected_ && | 246 if (use_tcp_fastopen_ && !tcp_fastopen_write_attempted_ && |
243 socket_->HasPeerAddress()) { | 247 socket_->HasPeerAddress()) { |
244 // With TCP FastOpen, we pretend that the socket is connected. | 248 // With TCP FastOpen, we pretend that the socket is connected. |
245 // This allows GetPeerAddress() to return peer_address_. | 249 // This allows GetPeerAddress() to return peer_address_. |
246 return true; | 250 return true; |
247 } | 251 } |
248 | 252 |
249 return socket_->IsConnected(); | 253 return socket_->IsConnected(); |
250 } | 254 } |
251 | 255 |
252 bool TCPSocketLibevent::IsConnectedAndIdle() const { | 256 bool TCPSocketLibevent::IsConnectedAndIdle() const { |
253 // TODO(wtc): should we also handle the TCP FastOpen case here, | 257 // TODO(wtc): should we also handle the TCP FastOpen case here, |
254 // as we do in IsConnected()? | 258 // as we do in IsConnected()? |
255 return socket_ && socket_->IsConnectedAndIdle(); | 259 return socket_ && socket_->IsConnectedAndIdle(); |
256 } | 260 } |
257 | 261 |
258 int TCPSocketLibevent::Read(IOBuffer* buf, | 262 int TCPSocketLibevent::Read(IOBuffer* buf, |
259 int buf_len, | 263 int buf_len, |
260 const CompletionCallback& callback) { | 264 const CompletionCallback& callback) { |
261 DCHECK(socket_); | 265 DCHECK(socket_); |
262 DCHECK(!callback.is_null()); | 266 DCHECK(!callback.is_null()); |
263 | 267 |
264 int rv = socket_->Read( | 268 int rv = socket_->Read( |
265 buf, buf_len, | 269 buf, buf_len, |
266 base::Bind(&TCPSocketLibevent::ReadCompleted, | 270 base::Bind(&TCPSocketLibevent::ReadCompleted, |
267 // Grab a reference to |buf| so that ReadCompleted() can still | 271 // Grab a reference to |buf| so that ReadCompleted() can still |
268 // use it when Read() completes, as otherwise, this transfers | 272 // use it when Read() completes, as otherwise, this transfers |
269 // ownership of buf to socket. | 273 // ownership of buf to socket. |
270 base::Unretained(this), make_scoped_refptr(buf), callback)); | 274 base::Unretained(this), make_scoped_refptr(buf), callback)); |
271 if (rv >= 0) | 275 if (rv >= 0) |
272 RecordFastOpenStatus(); | 276 RecordTCPFastOpenStatus(); |
273 if (rv != ERR_IO_PENDING) | 277 if (rv != ERR_IO_PENDING) |
274 rv = HandleReadCompleted(buf, rv); | 278 rv = HandleReadCompleted(buf, rv); |
275 return rv; | 279 return rv; |
276 } | 280 } |
277 | 281 |
278 int TCPSocketLibevent::Write(IOBuffer* buf, | 282 int TCPSocketLibevent::Write(IOBuffer* buf, |
279 int buf_len, | 283 int buf_len, |
280 const CompletionCallback& callback) { | 284 const CompletionCallback& callback) { |
281 DCHECK(socket_); | 285 DCHECK(socket_); |
282 DCHECK(!callback.is_null()); | 286 DCHECK(!callback.is_null()); |
283 | 287 |
284 CompletionCallback write_callback = | 288 CompletionCallback write_callback = |
285 base::Bind(&TCPSocketLibevent::WriteCompleted, | 289 base::Bind(&TCPSocketLibevent::WriteCompleted, |
286 // Grab a reference to |buf| so that WriteCompleted() can still | 290 // Grab a reference to |buf| so that WriteCompleted() can still |
287 // use it when Write() completes, as otherwise, this transfers | 291 // use it when Write() completes, as otherwise, this transfers |
288 // ownership of buf to socket. | 292 // ownership of buf to socket. |
289 base::Unretained(this), make_scoped_refptr(buf), callback); | 293 base::Unretained(this), make_scoped_refptr(buf), callback); |
290 int rv; | 294 int rv; |
291 if (use_tcp_fastopen_ && !tcp_fastopen_connected_) { | 295 |
296 if (use_tcp_fastopen_ && !tcp_fastopen_write_attempted_) { | |
292 rv = TcpFastOpenWrite(buf, buf_len, write_callback); | 297 rv = TcpFastOpenWrite(buf, buf_len, write_callback); |
293 } else { | 298 } else { |
294 rv = socket_->Write(buf, buf_len, write_callback); | 299 rv = socket_->Write(buf, buf_len, write_callback); |
295 } | 300 } |
296 | 301 |
297 if (rv != ERR_IO_PENDING) | 302 if (rv != ERR_IO_PENDING) |
298 rv = HandleWriteCompleted(buf, rv); | 303 rv = HandleWriteCompleted(buf, rv); |
299 return rv; | 304 return rv; |
300 } | 305 } |
301 | 306 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 } | 413 } |
409 | 414 |
410 bool TCPSocketLibevent::SetNoDelay(bool no_delay) { | 415 bool TCPSocketLibevent::SetNoDelay(bool no_delay) { |
411 DCHECK(socket_); | 416 DCHECK(socket_); |
412 return SetTCPNoDelay(socket_->socket_fd(), no_delay); | 417 return SetTCPNoDelay(socket_->socket_fd(), no_delay); |
413 } | 418 } |
414 | 419 |
415 void TCPSocketLibevent::Close() { | 420 void TCPSocketLibevent::Close() { |
416 socket_.reset(); | 421 socket_.reset(); |
417 tcp_fastopen_connected_ = false; | 422 tcp_fastopen_connected_ = false; |
418 fast_open_status_ = FAST_OPEN_STATUS_UNKNOWN; | 423 tcp_fastopen_status_ = FAST_OPEN_STATUS_UNKNOWN; |
419 } | 424 } |
420 | 425 |
421 bool TCPSocketLibevent::UsingTCPFastOpen() const { | 426 bool TCPSocketLibevent::UsingTCPFastOpen() const { |
422 return use_tcp_fastopen_; | 427 return use_tcp_fastopen_; |
423 } | 428 } |
424 | 429 |
425 void TCPSocketLibevent::EnableTCPFastOpenIfSupported() { | 430 void TCPSocketLibevent::EnableTCPFastOpenIfSupported() { |
426 if (IsTCPFastOpenSupported()) | 431 // Do not enable TCP FastOpen if it had previously failed. |
432 // This check conservatively avoids middleboxes that may blackhole | |
433 // TCP FastOpen SYN+Data packets; on such a failure, subsequent sockets | |
434 // should not use TCP FastOpen. | |
435 if (IsTCPFastOpenSupported() && !g_tcp_fastopen_has_failed) | |
427 use_tcp_fastopen_ = true; | 436 use_tcp_fastopen_ = true; |
428 } | 437 } |
429 | 438 |
430 bool TCPSocketLibevent::IsValid() const { | 439 bool TCPSocketLibevent::IsValid() const { |
431 return socket_ != NULL && socket_->socket_fd() != kInvalidSocket; | 440 return socket_ != NULL && socket_->socket_fd() != kInvalidSocket; |
432 } | 441 } |
433 | 442 |
434 void TCPSocketLibevent::StartLoggingMultipleConnectAttempts( | 443 void TCPSocketLibevent::StartLoggingMultipleConnectAttempts( |
435 const AddressList& addresses) { | 444 const AddressList& addresses) { |
436 if (!logging_multiple_connect_attempts_) { | 445 if (!logging_multiple_connect_attempts_) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 storage.addr_len)); | 558 storage.addr_len)); |
550 } | 559 } |
551 | 560 |
552 void TCPSocketLibevent::ReadCompleted(const scoped_refptr<IOBuffer>& buf, | 561 void TCPSocketLibevent::ReadCompleted(const scoped_refptr<IOBuffer>& buf, |
553 const CompletionCallback& callback, | 562 const CompletionCallback& callback, |
554 int rv) { | 563 int rv) { |
555 DCHECK_NE(ERR_IO_PENDING, rv); | 564 DCHECK_NE(ERR_IO_PENDING, rv); |
556 // Records TCP FastOpen status regardless of error in asynchronous case. | 565 // Records TCP FastOpen status regardless of error in asynchronous case. |
557 // TODO(rdsmith,jri): Change histogram name to indicate it could be called on | 566 // TODO(rdsmith,jri): Change histogram name to indicate it could be called on |
558 // error. | 567 // error. |
559 RecordFastOpenStatus(); | 568 RecordTCPFastOpenStatus(); |
560 callback.Run(HandleReadCompleted(buf.get(), rv)); | 569 callback.Run(HandleReadCompleted(buf.get(), rv)); |
561 } | 570 } |
562 | 571 |
563 int TCPSocketLibevent::HandleReadCompleted(IOBuffer* buf, int rv) { | 572 int TCPSocketLibevent::HandleReadCompleted(IOBuffer* buf, int rv) { |
564 if (rv < 0) { | 573 if (rv < 0) { |
565 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, | 574 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, |
566 CreateNetLogSocketErrorCallback(rv, errno)); | 575 CreateNetLogSocketErrorCallback(rv, errno)); |
567 return rv; | 576 return rv; |
568 } | 577 } |
569 | 578 |
570 base::StatsCounter read_bytes("tcp.read_bytes"); | 579 base::StatsCounter read_bytes("tcp.read_bytes"); |
571 read_bytes.Add(rv); | 580 read_bytes.Add(rv); |
572 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, rv, | 581 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, rv, |
573 buf->data()); | 582 buf->data()); |
574 return rv; | 583 return rv; |
575 } | 584 } |
576 | 585 |
577 void TCPSocketLibevent::WriteCompleted(const scoped_refptr<IOBuffer>& buf, | 586 void TCPSocketLibevent::WriteCompleted(const scoped_refptr<IOBuffer>& buf, |
578 const CompletionCallback& callback, | 587 const CompletionCallback& callback, |
579 int rv) const { | 588 int rv) { |
580 DCHECK_NE(ERR_IO_PENDING, rv); | 589 DCHECK_NE(ERR_IO_PENDING, rv); |
581 callback.Run(HandleWriteCompleted(buf.get(), rv)); | 590 callback.Run(HandleWriteCompleted(buf.get(), rv)); |
582 } | 591 } |
583 | 592 |
584 int TCPSocketLibevent::HandleWriteCompleted(IOBuffer* buf, int rv) const { | 593 int TCPSocketLibevent::HandleWriteCompleted(IOBuffer* buf, int rv) { |
585 if (rv < 0) { | 594 if (rv < 0) { |
586 net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR, | 595 net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR, |
587 CreateNetLogSocketErrorCallback(rv, errno)); | 596 CreateNetLogSocketErrorCallback(rv, errno)); |
597 if (tcp_fastopen_write_attempted_ && !tcp_fastopen_connected_) { | |
598 // TCP FastOpen connect-with-write was attempted, but failed. | |
599 // Turn off TCP FastOpen for any subsequent connections. | |
600 g_tcp_fastopen_has_failed = true; | |
601 RecordTCPFastOpenStatus(); | |
602 } | |
588 return rv; | 603 return rv; |
589 } | 604 } |
590 | 605 |
606 tcp_fastopen_connected_ = true; | |
591 base::StatsCounter write_bytes("tcp.write_bytes"); | 607 base::StatsCounter write_bytes("tcp.write_bytes"); |
592 write_bytes.Add(rv); | 608 write_bytes.Add(rv); |
593 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, rv, | 609 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, rv, |
594 buf->data()); | 610 buf->data()); |
595 return rv; | 611 return rv; |
596 } | 612 } |
597 | 613 |
598 int TCPSocketLibevent::TcpFastOpenWrite( | 614 int TCPSocketLibevent::TcpFastOpenWrite( |
599 IOBuffer* buf, | 615 IOBuffer* buf, |
600 int buf_len, | 616 int buf_len, |
(...skipping 10 matching lines...) Expand all Loading... | |
611 // for system support on startup, but users may dynamically disable TCP Fast | 627 // for system support on startup, but users may dynamically disable TCP Fast |
612 // Open via sysctl. | 628 // Open via sysctl. |
613 flags |= MSG_NOSIGNAL; | 629 flags |= MSG_NOSIGNAL; |
614 #endif // defined(OS_LINUX) | 630 #endif // defined(OS_LINUX) |
615 rv = HANDLE_EINTR(sendto(socket_->socket_fd(), | 631 rv = HANDLE_EINTR(sendto(socket_->socket_fd(), |
616 buf->data(), | 632 buf->data(), |
617 buf_len, | 633 buf_len, |
618 flags, | 634 flags, |
619 storage.addr, | 635 storage.addr, |
620 storage.addr_len)); | 636 storage.addr_len)); |
621 tcp_fastopen_connected_ = true; | 637 tcp_fastopen_write_attempted_ = true; |
622 | 638 |
623 if (rv >= 0) { | 639 if (rv >= 0) { |
624 fast_open_status_ = FAST_OPEN_FAST_CONNECT_RETURN; | 640 tcp_fastopen_status_ = FAST_OPEN_FAST_CONNECT_RETURN; |
625 return rv; | 641 return rv; |
626 } | 642 } |
627 | 643 |
628 DCHECK_NE(EPIPE, errno); | 644 DCHECK_NE(EPIPE, errno); |
629 | 645 |
630 // If errno == EINPROGRESS, that means the kernel didn't have a cookie | 646 // If errno == EINPROGRESS, that means the kernel didn't have a cookie |
631 // and would block. The kernel is internally doing a connect() though. | 647 // and would block. The kernel is internally doing a connect() though. |
632 // Remap EINPROGRESS to EAGAIN so we treat this the same as our other | 648 // Remap EINPROGRESS to EAGAIN so we treat this the same as our other |
633 // asynchronous cases. Note that the user buffer has not been copied to | 649 // asynchronous cases. Note that the user buffer has not been copied to |
634 // kernel space. | 650 // kernel space. |
635 if (errno == EINPROGRESS) { | 651 if (errno == EINPROGRESS) { |
636 rv = ERR_IO_PENDING; | 652 rv = ERR_IO_PENDING; |
637 } else { | 653 } else { |
638 rv = MapSystemError(errno); | 654 rv = MapSystemError(errno); |
639 } | 655 } |
640 | 656 |
641 if (rv != ERR_IO_PENDING) { | 657 if (rv != ERR_IO_PENDING) { |
642 fast_open_status_ = FAST_OPEN_ERROR; | 658 tcp_fastopen_status_ = FAST_OPEN_ERROR; |
643 return rv; | 659 return rv; |
644 } | 660 } |
645 | 661 |
646 fast_open_status_ = FAST_OPEN_SLOW_CONNECT_RETURN; | 662 tcp_fastopen_status_ = FAST_OPEN_SLOW_CONNECT_RETURN; |
647 return socket_->WaitForWrite(buf, buf_len, callback); | 663 return socket_->WaitForWrite(buf, buf_len, callback); |
648 } | 664 } |
649 | 665 |
650 void TCPSocketLibevent::RecordFastOpenStatus() { | 666 void TCPSocketLibevent::RecordTCPFastOpenStatus() { |
mmenke
2014/09/23 15:21:00
nit: Think "Record" is a bit of a misnomer, since
Jana
2014/09/24 00:51:26
Sure, but we are recording the status here locally
| |
651 if (use_tcp_fastopen_ && | 667 if (use_tcp_fastopen_ && |
652 (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN || | 668 (tcp_fastopen_status_ == FAST_OPEN_FAST_CONNECT_RETURN || |
mmenke
2014/09/23 15:21:00
nit: Should be consistent here: Either always us
Jana
2014/09/24 00:51:26
Yup, good call. I left this one as it was (this hi
| |
653 fast_open_status_ == FAST_OPEN_SLOW_CONNECT_RETURN)) { | 669 tcp_fastopen_status_ == FAST_OPEN_SLOW_CONNECT_RETURN)) { |
mmenke
2014/09/23 15:21:00
While you're here, would you mind switching to an
Jana
2014/09/24 00:51:27
Done.
| |
654 DCHECK_NE(FAST_OPEN_STATUS_UNKNOWN, fast_open_status_); | 670 DCHECK_NE(FAST_OPEN_STATUS_UNKNOWN, tcp_fastopen_status_); |
671 | |
672 if (g_tcp_fastopen_has_failed && tcp_fastopen_write_attempted_) { | |
673 // Writing TCP FastOpen SYN+DATA or SYN-option failed. | |
674 tcp_fastopen_status_ = | |
675 (tcp_fastopen_status_ == FAST_OPEN_FAST_CONNECT_RETURN ? | |
676 FAST_OPEN_FAST_CONNECT_FAILED : FAST_OPEN_SLOW_CONNECT_FAILED); | |
mmenke
2014/09/23 15:21:00
If g_tcp_fastopen_has_failed is true, you're assum
Jana
2014/09/24 00:51:26
I don't think so -- but I've streamlined the logic
| |
677 return; | |
678 } | |
679 | |
655 bool getsockopt_success(false); | 680 bool getsockopt_success(false); |
656 bool server_acked_data(false); | 681 bool server_acked_data(false); |
657 #if defined(TCP_INFO) | 682 #if defined(TCP_INFO) |
658 // Probe to see the if the socket used TCP FastOpen. | 683 // Probe to see the if the socket used TCP FastOpen. |
659 tcp_info info; | 684 tcp_info info; |
660 socklen_t info_len = sizeof(tcp_info); | 685 socklen_t info_len = sizeof(tcp_info); |
661 getsockopt_success = | 686 getsockopt_success = |
662 getsockopt(socket_->socket_fd(), IPPROTO_TCP, TCP_INFO, | 687 getsockopt(socket_->socket_fd(), IPPROTO_TCP, TCP_INFO, |
663 &info, &info_len) == 0 && | 688 &info, &info_len) == 0 && |
664 info_len == sizeof(tcp_info); | 689 info_len == sizeof(tcp_info); |
665 server_acked_data = getsockopt_success && | 690 server_acked_data = getsockopt_success && |
666 (info.tcpi_options & TCPI_OPT_SYN_DATA); | 691 (info.tcpi_options & TCPI_OPT_SYN_DATA); |
667 #endif | 692 #endif |
668 if (getsockopt_success) { | 693 if (getsockopt_success) { |
669 if (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN) { | 694 if (tcp_fastopen_status_ == FAST_OPEN_FAST_CONNECT_RETURN) { |
670 fast_open_status_ = (server_acked_data ? FAST_OPEN_SYN_DATA_ACK : | 695 tcp_fastopen_status_ = (server_acked_data ? FAST_OPEN_SYN_DATA_ACK : |
671 FAST_OPEN_SYN_DATA_NACK); | 696 FAST_OPEN_SYN_DATA_NACK); |
672 } else { | 697 } else { |
673 fast_open_status_ = (server_acked_data ? FAST_OPEN_NO_SYN_DATA_ACK : | 698 tcp_fastopen_status_ = (server_acked_data ? FAST_OPEN_NO_SYN_DATA_ACK : |
674 FAST_OPEN_NO_SYN_DATA_NACK); | 699 FAST_OPEN_NO_SYN_DATA_NACK); |
675 } | 700 } |
676 } else { | 701 } else { |
677 fast_open_status_ = (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN ? | 702 tcp_fastopen_status_ = |
678 FAST_OPEN_SYN_DATA_FAILED : | 703 (tcp_fastopen_status_ == FAST_OPEN_FAST_CONNECT_RETURN ? |
679 FAST_OPEN_NO_SYN_DATA_FAILED); | 704 FAST_OPEN_SYN_DATA_FAILED : FAST_OPEN_NO_SYN_DATA_FAILED); |
680 } | 705 } |
681 } | 706 } |
682 } | 707 } |
683 | 708 |
684 } // namespace net | 709 } // namespace net |
OLD | NEW |