| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/metrics/stats_counters.h" | 14 #include "base/metrics/stats_counters.h" |
| 15 #include "base/posix/eintr_wrapper.h" | 15 #include "base/posix/eintr_wrapper.h" |
| 16 #include "base/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
| 17 #include "base/threading/worker_pool.h" | 17 #include "base/threading/worker_pool.h" |
| 18 #include "net/base/address_list.h" | 18 #include "net/base/address_list.h" |
| 19 #include "net/base/connection_type_histograms.h" | 19 #include "net/base/connection_type_histograms.h" |
| 20 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
| 21 #include "net/base/ip_endpoint.h" | 21 #include "net/base/ip_endpoint.h" |
| 22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 24 #include "net/base/network_activity_monitor.h" |
| 24 #include "net/base/network_change_notifier.h" | 25 #include "net/base/network_change_notifier.h" |
| 25 #include "net/socket/socket_libevent.h" | 26 #include "net/socket/socket_libevent.h" |
| 26 #include "net/socket/socket_net_log_params.h" | 27 #include "net/socket/socket_net_log_params.h" |
| 27 | 28 |
| 28 // If we don't have a definition for TCPI_OPT_SYN_DATA, create one. | 29 // If we don't have a definition for TCPI_OPT_SYN_DATA, create one. |
| 29 #ifndef TCPI_OPT_SYN_DATA | 30 #ifndef TCPI_OPT_SYN_DATA |
| 30 #define TCPI_OPT_SYN_DATA 32 | 31 #define TCPI_OPT_SYN_DATA 32 |
| 31 #endif | 32 #endif |
| 32 | 33 |
| 33 namespace net { | 34 namespace net { |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 if (rv < 0) { | 595 if (rv < 0) { |
| 595 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, | 596 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, |
| 596 CreateNetLogSocketErrorCallback(rv, errno)); | 597 CreateNetLogSocketErrorCallback(rv, errno)); |
| 597 return rv; | 598 return rv; |
| 598 } | 599 } |
| 599 | 600 |
| 600 base::StatsCounter read_bytes("tcp.read_bytes"); | 601 base::StatsCounter read_bytes("tcp.read_bytes"); |
| 601 read_bytes.Add(rv); | 602 read_bytes.Add(rv); |
| 602 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, rv, | 603 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, rv, |
| 603 buf->data()); | 604 buf->data()); |
| 605 NetworkActivityMonitor::GetInstance()->IncrementBytesReceived(rv); |
| 606 |
| 604 return rv; | 607 return rv; |
| 605 } | 608 } |
| 606 | 609 |
| 607 void TCPSocketLibevent::WriteCompleted(const scoped_refptr<IOBuffer>& buf, | 610 void TCPSocketLibevent::WriteCompleted(const scoped_refptr<IOBuffer>& buf, |
| 608 const CompletionCallback& callback, | 611 const CompletionCallback& callback, |
| 609 int rv) { | 612 int rv) { |
| 610 DCHECK_NE(ERR_IO_PENDING, rv); | 613 DCHECK_NE(ERR_IO_PENDING, rv); |
| 611 callback.Run(HandleWriteCompleted(buf.get(), rv)); | 614 callback.Run(HandleWriteCompleted(buf.get(), rv)); |
| 612 } | 615 } |
| 613 | 616 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 626 } | 629 } |
| 627 net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR, | 630 net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR, |
| 628 CreateNetLogSocketErrorCallback(rv, errno)); | 631 CreateNetLogSocketErrorCallback(rv, errno)); |
| 629 return rv; | 632 return rv; |
| 630 } | 633 } |
| 631 | 634 |
| 632 base::StatsCounter write_bytes("tcp.write_bytes"); | 635 base::StatsCounter write_bytes("tcp.write_bytes"); |
| 633 write_bytes.Add(rv); | 636 write_bytes.Add(rv); |
| 634 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, rv, | 637 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, rv, |
| 635 buf->data()); | 638 buf->data()); |
| 639 NetworkActivityMonitor::GetInstance()->IncrementBytesSent(rv); |
| 636 return rv; | 640 return rv; |
| 637 } | 641 } |
| 638 | 642 |
| 639 int TCPSocketLibevent::TcpFastOpenWrite( | 643 int TCPSocketLibevent::TcpFastOpenWrite( |
| 640 IOBuffer* buf, | 644 IOBuffer* buf, |
| 641 int buf_len, | 645 int buf_len, |
| 642 const CompletionCallback& callback) { | 646 const CompletionCallback& callback) { |
| 643 SockaddrStorage storage; | 647 SockaddrStorage storage; |
| 644 int rv = socket_->GetPeerAddress(&storage); | 648 int rv = socket_->GetPeerAddress(&storage); |
| 645 if (rv != OK) | 649 if (rv != OK) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 } | 740 } |
| 737 } else { | 741 } else { |
| 738 tcp_fastopen_status_ = | 742 tcp_fastopen_status_ = |
| 739 (tcp_fastopen_status_ == TCP_FASTOPEN_FAST_CONNECT_RETURN ? | 743 (tcp_fastopen_status_ == TCP_FASTOPEN_FAST_CONNECT_RETURN ? |
| 740 TCP_FASTOPEN_SYN_DATA_GETSOCKOPT_FAILED : | 744 TCP_FASTOPEN_SYN_DATA_GETSOCKOPT_FAILED : |
| 741 TCP_FASTOPEN_NO_SYN_DATA_GETSOCKOPT_FAILED); | 745 TCP_FASTOPEN_NO_SYN_DATA_GETSOCKOPT_FAILED); |
| 742 } | 746 } |
| 743 } | 747 } |
| 744 | 748 |
| 745 } // namespace net | 749 } // namespace net |
| OLD | NEW |