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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 #if defined(OS_LINUX) || defined(OS_ANDROID) | 132 #if defined(OS_LINUX) || defined(OS_ANDROID) |
133 base::PostTaskAndReplyWithResult( | 133 base::PostTaskAndReplyWithResult( |
134 base::WorkerPool::GetTaskRunner(/*task_is_slow=*/false).get(), | 134 base::WorkerPool::GetTaskRunner(/*task_is_slow=*/false).get(), |
135 FROM_HERE, | 135 FROM_HERE, |
136 base::Bind(SystemSupportsTCPFastOpen), | 136 base::Bind(SystemSupportsTCPFastOpen), |
137 base::Bind(RegisterTCPFastOpenIntentAndSupport, user_enabled)); | 137 base::Bind(RegisterTCPFastOpenIntentAndSupport, user_enabled)); |
138 #endif | 138 #endif |
139 } | 139 } |
140 | 140 |
141 TCPSocketPosix::TCPSocketPosix( | 141 TCPSocketPosix::TCPSocketPosix( |
142 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher, | 142 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
143 NetLog* net_log, | 143 NetLog* net_log, |
144 const NetLog::Source& source) | 144 const NetLog::Source& source) |
145 : socket_performance_watcher_(std::move(socket_performance_watcher)), | 145 : socket_performance_watcher_(std::move(socket_performance_watcher)), |
146 tick_clock_(new base::DefaultTickClock()), | 146 tick_clock_(new base::DefaultTickClock()), |
147 rtt_notifications_minimum_interval_(base::TimeDelta::FromSeconds(1)), | 147 rtt_notifications_minimum_interval_(base::TimeDelta::FromSeconds(1)), |
148 use_tcp_fastopen_(false), | 148 use_tcp_fastopen_(false), |
149 tcp_fastopen_write_attempted_(false), | 149 tcp_fastopen_write_attempted_(false), |
150 tcp_fastopen_connected_(false), | 150 tcp_fastopen_connected_(false), |
151 tcp_fastopen_status_(TCP_FASTOPEN_STATUS_UNKNOWN), | 151 tcp_fastopen_status_(TCP_FASTOPEN_STATUS_UNKNOWN), |
152 logging_multiple_connect_attempts_(false), | 152 logging_multiple_connect_attempts_(false), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 return ERR_ADDRESS_INVALID; | 195 return ERR_ADDRESS_INVALID; |
196 | 196 |
197 return socket_->Bind(storage); | 197 return socket_->Bind(storage); |
198 } | 198 } |
199 | 199 |
200 int TCPSocketPosix::Listen(int backlog) { | 200 int TCPSocketPosix::Listen(int backlog) { |
201 DCHECK(socket_); | 201 DCHECK(socket_); |
202 return socket_->Listen(backlog); | 202 return socket_->Listen(backlog); |
203 } | 203 } |
204 | 204 |
205 int TCPSocketPosix::Accept(scoped_ptr<TCPSocketPosix>* tcp_socket, | 205 int TCPSocketPosix::Accept(std::unique_ptr<TCPSocketPosix>* tcp_socket, |
206 IPEndPoint* address, | 206 IPEndPoint* address, |
207 const CompletionCallback& callback) { | 207 const CompletionCallback& callback) { |
208 DCHECK(tcp_socket); | 208 DCHECK(tcp_socket); |
209 DCHECK(!callback.is_null()); | 209 DCHECK(!callback.is_null()); |
210 DCHECK(socket_); | 210 DCHECK(socket_); |
211 DCHECK(!accept_socket_); | 211 DCHECK(!accept_socket_); |
212 | 212 |
213 net_log_.BeginEvent(NetLog::TYPE_TCP_ACCEPT); | 213 net_log_.BeginEvent(NetLog::TYPE_TCP_ACCEPT); |
214 | 214 |
215 int rv = socket_->Accept( | 215 int rv = socket_->Accept( |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 void TCPSocketPosix::EndLoggingMultipleConnectAttempts(int net_error) { | 476 void TCPSocketPosix::EndLoggingMultipleConnectAttempts(int net_error) { |
477 if (logging_multiple_connect_attempts_) { | 477 if (logging_multiple_connect_attempts_) { |
478 LogConnectEnd(net_error); | 478 LogConnectEnd(net_error); |
479 logging_multiple_connect_attempts_ = false; | 479 logging_multiple_connect_attempts_ = false; |
480 } else { | 480 } else { |
481 NOTREACHED(); | 481 NOTREACHED(); |
482 } | 482 } |
483 } | 483 } |
484 | 484 |
485 void TCPSocketPosix::SetTickClockForTesting( | 485 void TCPSocketPosix::SetTickClockForTesting( |
486 scoped_ptr<base::TickClock> tick_clock) { | 486 std::unique_ptr<base::TickClock> tick_clock) { |
487 tick_clock_ = std::move(tick_clock); | 487 tick_clock_ = std::move(tick_clock); |
488 } | 488 } |
489 | 489 |
490 void TCPSocketPosix::AcceptCompleted(scoped_ptr<TCPSocketPosix>* tcp_socket, | 490 void TCPSocketPosix::AcceptCompleted( |
491 IPEndPoint* address, | 491 std::unique_ptr<TCPSocketPosix>* tcp_socket, |
492 const CompletionCallback& callback, | 492 IPEndPoint* address, |
493 int rv) { | 493 const CompletionCallback& callback, |
| 494 int rv) { |
494 DCHECK_NE(ERR_IO_PENDING, rv); | 495 DCHECK_NE(ERR_IO_PENDING, rv); |
495 callback.Run(HandleAcceptCompleted(tcp_socket, address, rv)); | 496 callback.Run(HandleAcceptCompleted(tcp_socket, address, rv)); |
496 } | 497 } |
497 | 498 |
498 int TCPSocketPosix::HandleAcceptCompleted( | 499 int TCPSocketPosix::HandleAcceptCompleted( |
499 scoped_ptr<TCPSocketPosix>* tcp_socket, | 500 std::unique_ptr<TCPSocketPosix>* tcp_socket, |
500 IPEndPoint* address, | 501 IPEndPoint* address, |
501 int rv) { | 502 int rv) { |
502 if (rv == OK) | 503 if (rv == OK) |
503 rv = BuildTcpSocketPosix(tcp_socket, address); | 504 rv = BuildTcpSocketPosix(tcp_socket, address); |
504 | 505 |
505 if (rv == OK) { | 506 if (rv == OK) { |
506 net_log_.EndEvent(NetLog::TYPE_TCP_ACCEPT, | 507 net_log_.EndEvent(NetLog::TYPE_TCP_ACCEPT, |
507 CreateNetLogIPEndPointCallback(address)); | 508 CreateNetLogIPEndPointCallback(address)); |
508 } else { | 509 } else { |
509 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, rv); | 510 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_TCP_ACCEPT, rv); |
510 } | 511 } |
511 | 512 |
512 return rv; | 513 return rv; |
513 } | 514 } |
514 | 515 |
515 int TCPSocketPosix::BuildTcpSocketPosix(scoped_ptr<TCPSocketPosix>* tcp_socket, | 516 int TCPSocketPosix::BuildTcpSocketPosix( |
516 IPEndPoint* address) { | 517 std::unique_ptr<TCPSocketPosix>* tcp_socket, |
| 518 IPEndPoint* address) { |
517 DCHECK(accept_socket_); | 519 DCHECK(accept_socket_); |
518 | 520 |
519 SockaddrStorage storage; | 521 SockaddrStorage storage; |
520 if (accept_socket_->GetPeerAddress(&storage) != OK || | 522 if (accept_socket_->GetPeerAddress(&storage) != OK || |
521 !address->FromSockAddr(storage.addr, storage.addr_len)) { | 523 !address->FromSockAddr(storage.addr, storage.addr_len)) { |
522 accept_socket_.reset(); | 524 accept_socket_.reset(); |
523 return ERR_ADDRESS_INVALID; | 525 return ERR_ADDRESS_INVALID; |
524 } | 526 } |
525 | 527 |
526 tcp_socket->reset( | 528 tcp_socket->reset( |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 if (info.tcpi_rtt > 0) { | 815 if (info.tcpi_rtt > 0) { |
814 *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt); | 816 *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt); |
815 return true; | 817 return true; |
816 } | 818 } |
817 } | 819 } |
818 #endif // defined(TCP_INFO) | 820 #endif // defined(TCP_INFO) |
819 return false; | 821 return false; |
820 } | 822 } |
821 | 823 |
822 } // namespace net | 824 } // namespace net |
OLD | NEW |