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> |
11 #include <netinet/tcp.h> | 11 #include <netinet/tcp.h> |
12 #if defined(OS_POSIX) | 12 #if defined(OS_POSIX) |
13 #include <netinet/in.h> | 13 #include <netinet/in.h> |
14 #endif | 14 #endif |
15 | 15 |
16 #include "base/eintr_wrapper.h" | 16 #include "base/eintr_wrapper.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
19 #include "base/metrics/stats_counters.h" | 19 #include "base/metrics/stats_counters.h" |
20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "net/base/address_list_net_log_param.h" | 21 #include "net/base/address_list_net_log_param.h" |
| 22 #include "net/base/connection_type_histograms.h" |
22 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
24 #include "net/base/net_log.h" | 25 #include "net/base/net_log.h" |
25 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
26 #include "net/base/network_change_notifier.h" | 27 #include "net/base/network_change_notifier.h" |
27 #if defined(USE_SYSTEM_LIBEVENT) | 28 #if defined(USE_SYSTEM_LIBEVENT) |
28 #include <event.h> | 29 #include <event.h> |
29 #else | 30 #else |
30 #include "third_party/libevent/event.h" | 31 #include "third_party/libevent/event.h" |
31 #endif | 32 #endif |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 | 516 |
516 // This mirrors the behaviour on Windows. See the comment in | 517 // This mirrors the behaviour on Windows. See the comment in |
517 // tcp_client_socket_win.cc after searching for "NODELAY". | 518 // tcp_client_socket_win.cc after searching for "NODELAY". |
518 DisableNagle(socket_); // If DisableNagle fails, we don't care. | 519 DisableNagle(socket_); // If DisableNagle fails, we don't care. |
519 SetTCPKeepAlive(socket_); | 520 SetTCPKeepAlive(socket_); |
520 | 521 |
521 return 0; | 522 return 0; |
522 } | 523 } |
523 | 524 |
524 void TCPClientSocketLibevent::LogConnectCompletion(int net_error) { | 525 void TCPClientSocketLibevent::LogConnectCompletion(int net_error) { |
525 scoped_refptr<NetLog::EventParameters> params; | 526 if (net_error == OK) |
526 if (net_error != OK) | 527 UpdateConnectionTypeHistograms(CONNECTION_ANY); |
527 params = new NetLogIntegerParameter("net_error", net_error); | 528 |
528 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT, params); | 529 if (net_error != OK) { |
| 530 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT, |
| 531 make_scoped_refptr( |
| 532 new NetLogIntegerParameter("net_error", net_error))); |
| 533 return; |
| 534 } |
| 535 |
| 536 struct sockaddr_storage source_address; |
| 537 socklen_t addrlen = sizeof(source_address); |
| 538 int rv = getsockname( |
| 539 socket_, reinterpret_cast<struct sockaddr*>(&source_address), &addrlen); |
| 540 if (rv != 0) { |
| 541 PLOG(ERROR) << "getsockname() [rv: " << rv << "] error: "; |
| 542 NOTREACHED(); |
| 543 scoped_refptr<NetLog::EventParameters> params; |
| 544 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT, NULL); |
| 545 return; |
| 546 } |
| 547 |
| 548 const std::string source_address_str = |
| 549 NetAddressToStringWithPort( |
| 550 reinterpret_cast<const struct sockaddr*>(&source_address), |
| 551 sizeof(source_address)); |
| 552 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT, |
| 553 make_scoped_refptr(new NetLogStringParameter( |
| 554 "source address", |
| 555 source_address_str))); |
529 } | 556 } |
530 | 557 |
531 void TCPClientSocketLibevent::DoReadCallback(int rv) { | 558 void TCPClientSocketLibevent::DoReadCallback(int rv) { |
532 DCHECK_NE(rv, ERR_IO_PENDING); | 559 DCHECK_NE(rv, ERR_IO_PENDING); |
533 DCHECK(read_callback_); | 560 DCHECK(read_callback_); |
534 | 561 |
535 // since Run may result in Read being called, clear read_callback_ up front. | 562 // since Run may result in Read being called, clear read_callback_ up front. |
536 CompletionCallback* c = read_callback_; | 563 CompletionCallback* c = read_callback_; |
537 read_callback_ = NULL; | 564 read_callback_ = NULL; |
538 c->Run(rv); | 565 c->Run(rv); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 | 674 |
648 bool TCPClientSocketLibevent::WasEverUsed() const { | 675 bool TCPClientSocketLibevent::WasEverUsed() const { |
649 return use_history_.was_used_to_convey_data(); | 676 return use_history_.was_used_to_convey_data(); |
650 } | 677 } |
651 | 678 |
652 bool TCPClientSocketLibevent::UsingTCPFastOpen() const { | 679 bool TCPClientSocketLibevent::UsingTCPFastOpen() const { |
653 return use_tcp_fastopen_; | 680 return use_tcp_fastopen_; |
654 } | 681 } |
655 | 682 |
656 } // namespace net | 683 } // namespace net |
OLD | NEW |