OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_client_socket_win.h" | 5 #include "net/socket/tcp_client_socket_win.h" |
6 | 6 |
7 #include <mstcpip.h> | 7 #include <mstcpip.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 if (current_address_index_ >= 0 || bind_address_.get()) { | 376 if (current_address_index_ >= 0 || bind_address_.get()) { |
377 // Cannot bind the socket if we are already connected or connecting. | 377 // Cannot bind the socket if we are already connected or connecting. |
378 return ERR_UNEXPECTED; | 378 return ERR_UNEXPECTED; |
379 } | 379 } |
380 | 380 |
381 SockaddrStorage storage; | 381 SockaddrStorage storage; |
382 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) | 382 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) |
383 return ERR_INVALID_ARGUMENT; | 383 return ERR_INVALID_ARGUMENT; |
384 | 384 |
385 // Create |bound_socket_| and try to bind it to |address|. | 385 // Create |bound_socket_| and try to bind it to |address|. |
386 int error = CreateSocket(address.GetFamily(), &bound_socket_); | 386 int error = CreateSocket(address.GetSockAddrFamily(), &bound_socket_); |
387 if (error) | 387 if (error) |
388 return MapSystemError(error); | 388 return MapSystemError(error); |
389 | 389 |
390 if (bind(bound_socket_, storage.addr, storage.addr_len)) { | 390 if (bind(bound_socket_, storage.addr, storage.addr_len)) { |
391 error = errno; | 391 error = errno; |
392 if (closesocket(bound_socket_) < 0) | 392 if (closesocket(bound_socket_) < 0) |
393 PLOG(ERROR) << "closesocket"; | 393 PLOG(ERROR) << "closesocket"; |
394 bound_socket_ = INVALID_SOCKET; | 394 bound_socket_ = INVALID_SOCKET; |
395 return MapSystemError(error); | 395 return MapSystemError(error); |
396 } | 396 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, | 472 net_log_.BeginEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, |
473 CreateNetLogIPEndPointCallback(&endpoint)); | 473 CreateNetLogIPEndPointCallback(&endpoint)); |
474 | 474 |
475 next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE; | 475 next_connect_state_ = CONNECT_STATE_CONNECT_COMPLETE; |
476 | 476 |
477 if (bound_socket_ != INVALID_SOCKET) { | 477 if (bound_socket_ != INVALID_SOCKET) { |
478 DCHECK(bind_address_.get()); | 478 DCHECK(bind_address_.get()); |
479 socket_ = bound_socket_; | 479 socket_ = bound_socket_; |
480 bound_socket_ = INVALID_SOCKET; | 480 bound_socket_ = INVALID_SOCKET; |
481 } else { | 481 } else { |
482 connect_os_error_ = CreateSocket(endpoint.GetFamily(), &socket_); | 482 connect_os_error_ = CreateSocket(endpoint.GetSockAddrFamily(), &socket_); |
483 if (connect_os_error_ != 0) | 483 if (connect_os_error_ != 0) |
484 return MapSystemError(connect_os_error_); | 484 return MapSystemError(connect_os_error_); |
485 | 485 |
486 if (bind_address_.get()) { | 486 if (bind_address_.get()) { |
487 SockaddrStorage storage; | 487 SockaddrStorage storage; |
488 if (!bind_address_->ToSockAddr(storage.addr, &storage.addr_len)) | 488 if (!bind_address_->ToSockAddr(storage.addr, &storage.addr_len)) |
489 return ERR_INVALID_ARGUMENT; | 489 return ERR_INVALID_ARGUMENT; |
490 if (bind(socket_, storage.addr, storage.addr_len)) | 490 if (bind(socket_, storage.addr, storage.addr_len)) |
491 return MapSystemError(errno); | 491 return MapSystemError(errno); |
492 } | 492 } |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 core_->WatchForRead(); | 1044 core_->WatchForRead(); |
1045 return; | 1045 return; |
1046 } | 1046 } |
1047 waiting_read_ = false; | 1047 waiting_read_ = false; |
1048 core_->read_iobuffer_ = NULL; | 1048 core_->read_iobuffer_ = NULL; |
1049 core_->read_buffer_length_ = 0; | 1049 core_->read_buffer_length_ = 0; |
1050 DoReadCallback(rv); | 1050 DoReadCallback(rv); |
1051 } | 1051 } |
1052 | 1052 |
1053 } // namespace net | 1053 } // namespace net |
OLD | NEW |