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" | |
11 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
12 #include "net/socket/tcp_client_socket.h" | 11 #include "net/socket/tcp_client_socket.h" |
13 | 12 |
14 namespace net { | 13 namespace net { |
15 | 14 |
16 TCPServerSocket::TCPServerSocket(NetLog* net_log, const NetLog::Source& source) | 15 TCPServerSocket::TCPServerSocket(NetLog* net_log, const NetLog::Source& source) |
17 : socket_(net_log, source), | 16 : socket_(net_log, source), |
18 pending_accept_(false) { | 17 pending_accept_(false) { |
19 } | 18 } |
20 | 19 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 80 } |
82 | 81 |
83 int TCPServerSocket::ConvertAcceptedSocket( | 82 int TCPServerSocket::ConvertAcceptedSocket( |
84 int result, | 83 int result, |
85 scoped_ptr<StreamSocket>* output_accepted_socket) { | 84 scoped_ptr<StreamSocket>* output_accepted_socket) { |
86 // Make sure the TCPSocket object is destroyed in any case. | 85 // Make sure the TCPSocket object is destroyed in any case. |
87 scoped_ptr<TCPSocket> temp_accepted_socket(accepted_socket_.Pass()); | 86 scoped_ptr<TCPSocket> temp_accepted_socket(accepted_socket_.Pass()); |
88 if (result != OK) | 87 if (result != OK) |
89 return result; | 88 return result; |
90 | 89 |
91 // TODO(yzshen): Once we switch TCPClientSocketLibevent to take a connected | 90 output_accepted_socket->reset(new TCPClientSocket( |
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_)); | 91 temp_accepted_socket.Pass(), accepted_address_)); |
96 #elif defined(OS_POSIX) | |
97 scoped_ptr<TCPClientSocket> client_socket(new TCPClientSocket( | |
98 AddressList(accepted_address_), | |
99 temp_accepted_socket->net_log().net_log(), | |
100 temp_accepted_socket->net_log().source())); | |
101 int raw_socket = temp_accepted_socket->Release(); | |
102 result = client_socket->AdoptSocket(raw_socket); | |
103 if (result != OK) { | |
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. | |
106 temp_accepted_socket->Adopt(raw_socket); | |
107 return result; | |
108 } | |
109 #endif | |
110 | 92 |
111 *output_accepted_socket = client_socket.Pass(); | |
112 return OK; | 93 return OK; |
113 } | 94 } |
114 | 95 |
115 void TCPServerSocket::OnAcceptCompleted( | 96 void TCPServerSocket::OnAcceptCompleted( |
116 scoped_ptr<StreamSocket>* output_accepted_socket, | 97 scoped_ptr<StreamSocket>* output_accepted_socket, |
117 const CompletionCallback& forward_callback, | 98 const CompletionCallback& forward_callback, |
118 int result) { | 99 int result) { |
119 result = ConvertAcceptedSocket(result, output_accepted_socket); | 100 result = ConvertAcceptedSocket(result, output_accepted_socket); |
120 pending_accept_ = false; | 101 pending_accept_ = false; |
121 forward_callback.Run(result); | 102 forward_callback.Run(result); |
122 } | 103 } |
123 | 104 |
124 } // namespace net | 105 } // namespace net |
OLD | NEW |