| 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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 void TCPSocketLibevent::Close() { | 362 void TCPSocketLibevent::Close() { |
| 363 socket_.reset(); | 363 socket_.reset(); |
| 364 tcp_fastopen_connected_ = false; | 364 tcp_fastopen_connected_ = false; |
| 365 fast_open_status_ = FAST_OPEN_STATUS_UNKNOWN; | 365 fast_open_status_ = FAST_OPEN_STATUS_UNKNOWN; |
| 366 } | 366 } |
| 367 | 367 |
| 368 bool TCPSocketLibevent::UsingTCPFastOpen() const { | 368 bool TCPSocketLibevent::UsingTCPFastOpen() const { |
| 369 return use_tcp_fastopen_; | 369 return use_tcp_fastopen_; |
| 370 } | 370 } |
| 371 | 371 |
| 372 void TCPSocketLibevent::EnableTCPFastOpen() { |
| 373 if (!use_tcp_fastopen_ && IsTCPFastOpenSupported()) |
| 374 use_tcp_fastopen_ = true; |
| 375 } |
| 376 |
| 372 bool TCPSocketLibevent::IsValid() const { | 377 bool TCPSocketLibevent::IsValid() const { |
| 373 return socket_ != NULL && socket_->socket_fd() != kInvalidSocket; | 378 return socket_ != NULL && socket_->socket_fd() != kInvalidSocket; |
| 374 } | 379 } |
| 375 | 380 |
| 376 void TCPSocketLibevent::StartLoggingMultipleConnectAttempts( | 381 void TCPSocketLibevent::StartLoggingMultipleConnectAttempts( |
| 377 const AddressList& addresses) { | 382 const AddressList& addresses) { |
| 378 if (!logging_multiple_connect_attempts_) { | 383 if (!logging_multiple_connect_attempts_) { |
| 379 logging_multiple_connect_attempts_ = true; | 384 logging_multiple_connect_attempts_ = true; |
| 380 LogConnectBegin(addresses); | 385 LogConnectBegin(addresses); |
| 381 } else { | 386 } else { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 | 493 |
| 489 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT, | 494 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT, |
| 490 CreateNetLogSourceAddressCallback(storage.addr, | 495 CreateNetLogSourceAddressCallback(storage.addr, |
| 491 storage.addr_len)); | 496 storage.addr_len)); |
| 492 } | 497 } |
| 493 | 498 |
| 494 void TCPSocketLibevent::ReadCompleted(const scoped_refptr<IOBuffer>& buf, | 499 void TCPSocketLibevent::ReadCompleted(const scoped_refptr<IOBuffer>& buf, |
| 495 const CompletionCallback& callback, | 500 const CompletionCallback& callback, |
| 496 int rv) { | 501 int rv) { |
| 497 DCHECK_NE(ERR_IO_PENDING, rv); | 502 DCHECK_NE(ERR_IO_PENDING, rv); |
| 498 // Records fast open status regardless of error in asynchronous case. | 503 // Records TCP FastOpen status regardless of error in asynchronous case. |
| 499 // TODO(rdsmith,jri): Change histogram name to indicate it could be called on | 504 // TODO(rdsmith,jri): Change histogram name to indicate it could be called on |
| 500 // error. | 505 // error. |
| 501 RecordFastOpenStatus(); | 506 RecordFastOpenStatus(); |
| 502 callback.Run(HandleReadCompleted(buf, rv)); | 507 callback.Run(HandleReadCompleted(buf, rv)); |
| 503 } | 508 } |
| 504 | 509 |
| 505 int TCPSocketLibevent::HandleReadCompleted(IOBuffer* buf, int rv) { | 510 int TCPSocketLibevent::HandleReadCompleted(IOBuffer* buf, int rv) { |
| 506 if (rv < 0) { | 511 if (rv < 0) { |
| 507 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, | 512 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, |
| 508 CreateNetLogSocketErrorCallback(rv, errno)); | 513 CreateNetLogSocketErrorCallback(rv, errno)); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 } | 595 } |
| 591 | 596 |
| 592 void TCPSocketLibevent::RecordFastOpenStatus() { | 597 void TCPSocketLibevent::RecordFastOpenStatus() { |
| 593 if (use_tcp_fastopen_ && | 598 if (use_tcp_fastopen_ && |
| 594 (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN || | 599 (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN || |
| 595 fast_open_status_ == FAST_OPEN_SLOW_CONNECT_RETURN)) { | 600 fast_open_status_ == FAST_OPEN_SLOW_CONNECT_RETURN)) { |
| 596 DCHECK_NE(FAST_OPEN_STATUS_UNKNOWN, fast_open_status_); | 601 DCHECK_NE(FAST_OPEN_STATUS_UNKNOWN, fast_open_status_); |
| 597 bool getsockopt_success(false); | 602 bool getsockopt_success(false); |
| 598 bool server_acked_data(false); | 603 bool server_acked_data(false); |
| 599 #if defined(TCP_INFO) | 604 #if defined(TCP_INFO) |
| 600 // Probe to see the if the socket used TCP Fast Open. | 605 // Probe to see the if the socket used TCP FastOpen. |
| 601 tcp_info info; | 606 tcp_info info; |
| 602 socklen_t info_len = sizeof(tcp_info); | 607 socklen_t info_len = sizeof(tcp_info); |
| 603 getsockopt_success = | 608 getsockopt_success = |
| 604 getsockopt(socket_->socket_fd(), IPPROTO_TCP, TCP_INFO, | 609 getsockopt(socket_->socket_fd(), IPPROTO_TCP, TCP_INFO, |
| 605 &info, &info_len) == 0 && | 610 &info, &info_len) == 0 && |
| 606 info_len == sizeof(tcp_info); | 611 info_len == sizeof(tcp_info); |
| 607 server_acked_data = getsockopt_success && | 612 server_acked_data = getsockopt_success && |
| 608 (info.tcpi_options & TCPI_OPT_SYN_DATA); | 613 (info.tcpi_options & TCPI_OPT_SYN_DATA); |
| 609 #endif | 614 #endif |
| 610 if (getsockopt_success) { | 615 if (getsockopt_success) { |
| 611 if (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN) { | 616 if (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN) { |
| 612 fast_open_status_ = (server_acked_data ? FAST_OPEN_SYN_DATA_ACK : | 617 fast_open_status_ = (server_acked_data ? FAST_OPEN_SYN_DATA_ACK : |
| 613 FAST_OPEN_SYN_DATA_NACK); | 618 FAST_OPEN_SYN_DATA_NACK); |
| 614 } else { | 619 } else { |
| 615 fast_open_status_ = (server_acked_data ? FAST_OPEN_NO_SYN_DATA_ACK : | 620 fast_open_status_ = (server_acked_data ? FAST_OPEN_NO_SYN_DATA_ACK : |
| 616 FAST_OPEN_NO_SYN_DATA_NACK); | 621 FAST_OPEN_NO_SYN_DATA_NACK); |
| 617 } | 622 } |
| 618 } else { | 623 } else { |
| 619 fast_open_status_ = (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN ? | 624 fast_open_status_ = (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN ? |
| 620 FAST_OPEN_SYN_DATA_FAILED : | 625 FAST_OPEN_SYN_DATA_FAILED : |
| 621 FAST_OPEN_NO_SYN_DATA_FAILED); | 626 FAST_OPEN_NO_SYN_DATA_FAILED); |
| 622 } | 627 } |
| 623 } | 628 } |
| 624 } | 629 } |
| 625 | 630 |
| 626 } // namespace net | 631 } // namespace net |
| OLD | NEW |