| 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 #include "net/socket/tcp_socket_win.h" | 6 #include "net/socket/tcp_socket_win.h" |
| 7 | 7 |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <mstcpip.h> | 9 #include <mstcpip.h> |
| 10 | 10 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 277 |
| 278 if (!SetNonBlockingAndGetError(socket_, &os_error)) { | 278 if (!SetNonBlockingAndGetError(socket_, &os_error)) { |
| 279 int result = MapSystemError(os_error); | 279 int result = MapSystemError(os_error); |
| 280 Close(); | 280 Close(); |
| 281 return result; | 281 return result; |
| 282 } | 282 } |
| 283 | 283 |
| 284 return OK; | 284 return OK; |
| 285 } | 285 } |
| 286 | 286 |
| 287 int TCPSocketWin::AdoptConnectedSocket(SOCKET socket, | 287 int TCPSocketWin::AdoptConnectedSocket(SocketDescriptor socket, |
| 288 const IPEndPoint& peer_address) { | 288 const IPEndPoint& peer_address) { |
| 289 DCHECK(CalledOnValidThread()); | 289 DCHECK(CalledOnValidThread()); |
| 290 DCHECK_EQ(socket_, INVALID_SOCKET); | 290 DCHECK_EQ(socket_, INVALID_SOCKET); |
| 291 DCHECK(!core_.get()); | 291 DCHECK(!core_.get()); |
| 292 | 292 |
| 293 socket_ = socket; | 293 socket_ = socket; |
| 294 | 294 |
| 295 int os_error; | 295 int os_error; |
| 296 if (!SetNonBlockingAndGetError(socket_, &os_error)) { | 296 if (!SetNonBlockingAndGetError(socket_, &os_error)) { |
| 297 int result = MapSystemError(os_error); | 297 int result = MapSystemError(os_error); |
| 298 Close(); | 298 Close(); |
| 299 return result; | 299 return result; |
| 300 } | 300 } |
| 301 | 301 |
| 302 core_ = new Core(this); | 302 core_ = new Core(this); |
| 303 peer_address_.reset(new IPEndPoint(peer_address)); | 303 peer_address_.reset(new IPEndPoint(peer_address)); |
| 304 | 304 |
| 305 return OK; | 305 return OK; |
| 306 } | 306 } |
| 307 | 307 |
| 308 int TCPSocketWin::AdoptListenSocket(SOCKET socket) { | 308 int TCPSocketWin::AdoptUnconnectedSocket(SocketDescriptor socket) { |
| 309 DCHECK(CalledOnValidThread()); | 309 DCHECK(CalledOnValidThread()); |
| 310 DCHECK_EQ(socket_, INVALID_SOCKET); | 310 DCHECK_EQ(socket_, INVALID_SOCKET); |
| 311 | 311 |
| 312 socket_ = socket; | 312 socket_ = socket; |
| 313 | 313 |
| 314 int os_error; | 314 int os_error; |
| 315 if (!SetNonBlockingAndGetError(socket_, &os_error)) { | 315 if (!SetNonBlockingAndGetError(socket_, &os_error)) { |
| 316 int result = MapSystemError(os_error); | 316 int result = MapSystemError(os_error); |
| 317 Close(); | 317 Close(); |
| 318 return result; | 318 return result; |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 | 722 |
| 723 void TCPSocketWin::EndLoggingMultipleConnectAttempts(int net_error) { | 723 void TCPSocketWin::EndLoggingMultipleConnectAttempts(int net_error) { |
| 724 if (logging_multiple_connect_attempts_) { | 724 if (logging_multiple_connect_attempts_) { |
| 725 LogConnectEnd(net_error); | 725 LogConnectEnd(net_error); |
| 726 logging_multiple_connect_attempts_ = false; | 726 logging_multiple_connect_attempts_ = false; |
| 727 } else { | 727 } else { |
| 728 NOTREACHED(); | 728 NOTREACHED(); |
| 729 } | 729 } |
| 730 } | 730 } |
| 731 | 731 |
| 732 SocketDescriptor TCPSocketWin::ReleaseSocketDescriptorForTesting() { |
| 733 SocketDescriptor socket_descriptor = socket_; |
| 734 socket_ = INVALID_SOCKET; |
| 735 Close(); |
| 736 return socket_descriptor; |
| 737 } |
| 738 |
| 732 int TCPSocketWin::AcceptInternal(std::unique_ptr<TCPSocketWin>* socket, | 739 int TCPSocketWin::AcceptInternal(std::unique_ptr<TCPSocketWin>* socket, |
| 733 IPEndPoint* address) { | 740 IPEndPoint* address) { |
| 734 SockaddrStorage storage; | 741 SockaddrStorage storage; |
| 735 int new_socket = accept(socket_, storage.addr, &storage.addr_len); | 742 int new_socket = accept(socket_, storage.addr, &storage.addr_len); |
| 736 int os_error = WSAGetLastError(); | 743 int os_error = WSAGetLastError(); |
| 737 if (new_socket < 0) { | 744 if (new_socket < 0) { |
| 738 int net_error = MapSystemError(os_error); | 745 int net_error = MapSystemError(os_error); |
| 739 if (net_error != ERR_IO_PENDING) | 746 if (net_error != ERR_IO_PENDING) |
| 740 net_log_.EndEventWithNetErrorCode(NetLogEventType::TCP_ACCEPT, net_error); | 747 net_log_.EndEventWithNetErrorCode(NetLogEventType::TCP_ACCEPT, net_error); |
| 741 return net_error; | 748 return net_error; |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 } | 1043 } |
| 1037 | 1044 |
| 1038 bool TCPSocketWin::GetEstimatedRoundTripTime(base::TimeDelta* out_rtt) const { | 1045 bool TCPSocketWin::GetEstimatedRoundTripTime(base::TimeDelta* out_rtt) const { |
| 1039 DCHECK(out_rtt); | 1046 DCHECK(out_rtt); |
| 1040 // TODO(bmcquade): Consider implementing using | 1047 // TODO(bmcquade): Consider implementing using |
| 1041 // GetPerTcpConnectionEStats/GetPerTcp6ConnectionEStats. | 1048 // GetPerTcpConnectionEStats/GetPerTcp6ConnectionEStats. |
| 1042 return false; | 1049 return false; |
| 1043 } | 1050 } |
| 1044 | 1051 |
| 1045 } // namespace net | 1052 } // namespace net |
| OLD | NEW |