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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 | 332 |
333 int result = bind(socket_, storage.addr, storage.addr_len); | 333 int result = bind(socket_, storage.addr, storage.addr_len); |
334 if (result < 0) { | 334 if (result < 0) { |
335 PLOG(ERROR) << "bind() returned an error"; | 335 PLOG(ERROR) << "bind() returned an error"; |
336 return MapSystemError(WSAGetLastError()); | 336 return MapSystemError(WSAGetLastError()); |
337 } | 337 } |
338 | 338 |
339 return OK; | 339 return OK; |
340 } | 340 } |
341 | 341 |
342 int TCPSocketWin::AdoptBoundSocket(SOCKET socket) { | |
wtc
2014/04/24 23:09:31
I compared this method with AdoptConnectedSocket.
xiyuan
2014/04/25 20:29:29
|core_| is only used for read/write operations and
| |
343 DCHECK(CalledOnValidThread()); | |
344 DCHECK_EQ(socket_, INVALID_SOCKET); | |
345 | |
346 socket_ = socket; | |
347 | |
348 if (SetNonBlocking(socket_)) { | |
349 int result = MapSystemError(WSAGetLastError()); | |
350 Close(); | |
351 return result; | |
352 } | |
353 | |
354 return OK; | |
355 } | |
356 | |
342 int TCPSocketWin::Listen(int backlog) { | 357 int TCPSocketWin::Listen(int backlog) { |
343 DCHECK(CalledOnValidThread()); | 358 DCHECK(CalledOnValidThread()); |
344 DCHECK_GT(backlog, 0); | 359 DCHECK_GT(backlog, 0); |
345 DCHECK_NE(socket_, INVALID_SOCKET); | 360 DCHECK_NE(socket_, INVALID_SOCKET); |
346 DCHECK_EQ(accept_event_, WSA_INVALID_EVENT); | 361 DCHECK_EQ(accept_event_, WSA_INVALID_EVENT); |
347 | 362 |
348 accept_event_ = WSACreateEvent(); | 363 accept_event_ = WSACreateEvent(); |
349 if (accept_event_ == WSA_INVALID_EVENT) { | 364 if (accept_event_ == WSA_INVALID_EVENT) { |
350 PLOG(ERROR) << "WSACreateEvent()"; | 365 PLOG(ERROR) << "WSACreateEvent()"; |
351 return MapSystemError(WSAGetLastError()); | 366 return MapSystemError(WSAGetLastError()); |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
994 waiting_read_ = false; | 1009 waiting_read_ = false; |
995 core_->read_iobuffer_ = NULL; | 1010 core_->read_iobuffer_ = NULL; |
996 core_->read_buffer_length_ = 0; | 1011 core_->read_buffer_length_ = 0; |
997 | 1012 |
998 DCHECK_NE(rv, ERR_IO_PENDING); | 1013 DCHECK_NE(rv, ERR_IO_PENDING); |
999 base::ResetAndReturn(&read_callback_).Run(rv); | 1014 base::ResetAndReturn(&read_callback_).Run(rv); |
1000 } | 1015 } |
1001 | 1016 |
1002 } // namespace net | 1017 } // namespace net |
1003 | 1018 |
OLD | NEW |