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_win.h" | 5 #include "net/socket/tcp_socket_win.h" |
6 | 6 |
7 #include <mstcpip.h> | 7 #include <mstcpip.h> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 Close(); | 315 Close(); |
316 return result; | 316 return result; |
317 } | 317 } |
318 | 318 |
319 core_ = new Core(this); | 319 core_ = new Core(this); |
320 peer_address_.reset(new IPEndPoint(peer_address)); | 320 peer_address_.reset(new IPEndPoint(peer_address)); |
321 | 321 |
322 return OK; | 322 return OK; |
323 } | 323 } |
324 | 324 |
| 325 int TCPSocketWin::AdoptListenSocket(SOCKET socket) { |
| 326 DCHECK(CalledOnValidThread()); |
| 327 DCHECK_EQ(socket_, INVALID_SOCKET); |
| 328 |
| 329 socket_ = socket; |
| 330 |
| 331 if (SetNonBlocking(socket_)) { |
| 332 int result = MapSystemError(WSAGetLastError()); |
| 333 Close(); |
| 334 return result; |
| 335 } |
| 336 |
| 337 // |core_| is not needed for sockets that are used to accept connections. |
| 338 // The operation here is more like Open but with an existing socket. |
| 339 |
| 340 return OK; |
| 341 } |
| 342 |
325 int TCPSocketWin::Bind(const IPEndPoint& address) { | 343 int TCPSocketWin::Bind(const IPEndPoint& address) { |
326 DCHECK(CalledOnValidThread()); | 344 DCHECK(CalledOnValidThread()); |
327 DCHECK_NE(socket_, INVALID_SOCKET); | 345 DCHECK_NE(socket_, INVALID_SOCKET); |
328 | 346 |
329 SockaddrStorage storage; | 347 SockaddrStorage storage; |
330 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) | 348 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) |
331 return ERR_ADDRESS_INVALID; | 349 return ERR_ADDRESS_INVALID; |
332 | 350 |
333 int result = bind(socket_, storage.addr, storage.addr_len); | 351 int result = bind(socket_, storage.addr, storage.addr_len); |
334 if (result < 0) { | 352 if (result < 0) { |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 waiting_read_ = false; | 1012 waiting_read_ = false; |
995 core_->read_iobuffer_ = NULL; | 1013 core_->read_iobuffer_ = NULL; |
996 core_->read_buffer_length_ = 0; | 1014 core_->read_buffer_length_ = 0; |
997 | 1015 |
998 DCHECK_NE(rv, ERR_IO_PENDING); | 1016 DCHECK_NE(rv, ERR_IO_PENDING); |
999 base::ResetAndReturn(&read_callback_).Run(rv); | 1017 base::ResetAndReturn(&read_callback_).Run(rv); |
1000 } | 1018 } |
1001 | 1019 |
1002 } // namespace net | 1020 } // namespace net |
1003 | 1021 |
OLD | NEW |