| 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_server_socket.h" | 5 #include "net/socket/tcp_server_socket.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 int TCPServerSocket::ConvertAcceptedSocket( | 83 int TCPServerSocket::ConvertAcceptedSocket( |
| 84 int result, | 84 int result, |
| 85 scoped_ptr<StreamSocket>* output_accepted_socket) { | 85 scoped_ptr<StreamSocket>* output_accepted_socket) { |
| 86 // Make sure the TCPSocket object is destroyed in any case. | 86 // Make sure the TCPSocket object is destroyed in any case. |
| 87 scoped_ptr<TCPSocket> temp_accepted_socket(accepted_socket_.Pass()); | 87 scoped_ptr<TCPSocket> temp_accepted_socket(accepted_socket_.Pass()); |
| 88 if (result != OK) | 88 if (result != OK) |
| 89 return result; | 89 return result; |
| 90 | 90 |
| 91 // TODO(yzshen): Once we switch TCPClientSocketLibevent to take a connected |
| 92 // TCPSocket object, we don't need to do platform-specific handling. |
| 93 #if defined(OS_WIN) |
| 94 scoped_ptr<TCPClientSocket> client_socket(new TCPClientSocket( |
| 95 temp_accepted_socket.Pass(), accepted_address_)); |
| 96 #elif defined(OS_POSIX) |
| 91 scoped_ptr<TCPClientSocket> client_socket(new TCPClientSocket( | 97 scoped_ptr<TCPClientSocket> client_socket(new TCPClientSocket( |
| 92 AddressList(accepted_address_), | 98 AddressList(accepted_address_), |
| 93 temp_accepted_socket->net_log().net_log(), | 99 temp_accepted_socket->net_log().net_log(), |
| 94 temp_accepted_socket->net_log().source())); | 100 temp_accepted_socket->net_log().source())); |
| 95 // TODO(yzshen): Once we switch TCPClientSocket::AdoptSocket() to take a | |
| 96 // TCPSocket object, we don't need to do platform-specific handling. | |
| 97 #if defined(OS_WIN) | |
| 98 SOCKET raw_socket = temp_accepted_socket->Release(); | |
| 99 #elif defined(OS_POSIX) | |
| 100 int raw_socket = temp_accepted_socket->Release(); | 101 int raw_socket = temp_accepted_socket->Release(); |
| 101 #endif | |
| 102 result = client_socket->AdoptSocket(raw_socket); | 102 result = client_socket->AdoptSocket(raw_socket); |
| 103 if (result != OK) { | 103 if (result != OK) { |
| 104 // |client_socket| won't take ownership of |raw_socket| on failure. | 104 // |client_socket| won't take ownership of |raw_socket| on failure. |
| 105 // Therefore, we put it back into |temp_accepted_socket| to close it. | 105 // Therefore, we put it back into |temp_accepted_socket| to close it. |
| 106 temp_accepted_socket->Adopt(raw_socket); | 106 temp_accepted_socket->Adopt(raw_socket); |
| 107 return result; | 107 return result; |
| 108 } | 108 } |
| 109 #endif |
| 109 | 110 |
| 110 *output_accepted_socket = client_socket.Pass(); | 111 *output_accepted_socket = client_socket.Pass(); |
| 111 return OK; | 112 return OK; |
| 112 } | 113 } |
| 113 | 114 |
| 114 void TCPServerSocket::OnAcceptCompleted( | 115 void TCPServerSocket::OnAcceptCompleted( |
| 115 scoped_ptr<StreamSocket>* output_accepted_socket, | 116 scoped_ptr<StreamSocket>* output_accepted_socket, |
| 116 const CompletionCallback& forward_callback, | 117 const CompletionCallback& forward_callback, |
| 117 int result) { | 118 int result) { |
| 118 result = ConvertAcceptedSocket(result, output_accepted_socket); | 119 result = ConvertAcceptedSocket(result, output_accepted_socket); |
| 119 pending_accept_ = false; | 120 pending_accept_ = false; |
| 120 forward_callback.Run(result); | 121 forward_callback.Run(result); |
| 121 } | 122 } |
| 122 | 123 |
| 123 } // namespace net | 124 } // namespace net |
| OLD | NEW |