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