Chromium Code Reviews| 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 int TCPClientSocketWin::Bind(const IPEndPoint& address) { | 366 int TCPClientSocketWin::Bind(const IPEndPoint& address) { |
| 367 if (current_address_index_ >= 0 || bind_address_.get()) { | 367 if (current_address_index_ >= 0 || bind_address_.get()) { |
| 368 // Cannot bind the socket if we are already connected or connecting. | 368 // Cannot bind the socket if we are already connected or connecting. |
| 369 return ERR_UNEXPECTED; | 369 return ERR_UNEXPECTED; |
| 370 } | 370 } |
| 371 | 371 |
| 372 SockaddrStorage storage; | 372 SockaddrStorage storage; |
| 373 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) | 373 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) |
| 374 return ERR_INVALID_ARGUMENT; | 374 return ERR_INVALID_ARGUMENT; |
| 375 | 375 |
| 376 // Create |bound_socket_| and try to bound it to |address|. | 376 // Create |bound_socket_| and try to bind it to |address|. |
| 377 int error = CreateSocket(address.GetFamily(), &bound_socket_); | 377 int error = CreateSocket(address.GetFamily(), &bound_socket_); |
| 378 if (error) | 378 if (error) |
| 379 return MapSystemError(error); | 379 return MapSystemError(error); |
| 380 | 380 |
| 381 if (bind(bound_socket_, storage.addr, storage.addr_len)) { | 381 if (bind(bound_socket_, storage.addr, storage.addr_len)) { |
| 382 error = errno; | 382 error = errno; |
| 383 if (closesocket(bound_socket_) < 0) | 383 if (closesocket(bound_socket_) < 0) |
| 384 PLOG(ERROR) << "closesocket"; | 384 PLOG(ERROR) << "closesocket"; |
| 385 bound_socket_ = INVALID_SOCKET; | 385 bound_socket_ = INVALID_SOCKET; |
| 386 return MapSystemError(error); | 386 return MapSystemError(error); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 DCHECK(address); | 639 DCHECK(address); |
| 640 if (!IsConnected()) | 640 if (!IsConnected()) |
| 641 return ERR_SOCKET_NOT_CONNECTED; | 641 return ERR_SOCKET_NOT_CONNECTED; |
| 642 *address = addresses_[current_address_index_]; | 642 *address = addresses_[current_address_index_]; |
| 643 return OK; | 643 return OK; |
| 644 } | 644 } |
| 645 | 645 |
| 646 int TCPClientSocketWin::GetLocalAddress(IPEndPoint* address) const { | 646 int TCPClientSocketWin::GetLocalAddress(IPEndPoint* address) const { |
| 647 DCHECK(CalledOnValidThread()); | 647 DCHECK(CalledOnValidThread()); |
| 648 DCHECK(address); | 648 DCHECK(address); |
| 649 if (!IsConnected()) | 649 if (socket_ == INVALID_SOCKET) { |
| 650 return ERR_SOCKET_NOT_CONNECTED; | 650 if (bind_address_.get()) { |
| 651 *address = *bind_address_; | |
| 652 return OK; | |
| 653 } else { | |
|
wtc
2012/07/19 18:36:36
Nit: omit "else" after a return statement.
Sergey Ulanov
2012/07/19 21:36:20
Done.
| |
| 654 return ERR_SOCKET_NOT_CONNECTED; | |
| 655 } | |
| 656 } | |
|
wtc
2012/07/19 18:36:36
If socket_ is INVALID_SOCKET, I think we should si
Sergey Ulanov
2012/07/19 21:36:20
Done.
| |
| 651 | 657 |
| 652 struct sockaddr_storage addr_storage; | 658 struct sockaddr_storage addr_storage; |
| 653 socklen_t addr_len = sizeof(addr_storage); | 659 socklen_t addr_len = sizeof(addr_storage); |
| 654 struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage); | 660 struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addr_storage); |
| 655 if (getsockname(socket_, addr, &addr_len)) | 661 if (getsockname(socket_, addr, &addr_len)) |
| 656 return MapSystemError(WSAGetLastError()); | 662 return MapSystemError(WSAGetLastError()); |
| 657 if (!address->FromSockAddr(addr, addr_len)) | 663 if (!address->FromSockAddr(addr, addr_len)) |
| 658 return ERR_FAILED; | 664 return ERR_FAILED; |
| 659 return OK; | 665 return OK; |
| 660 } | 666 } |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 941 use_history_.set_was_used_to_convey_data(); | 947 use_history_.set_was_used_to_convey_data(); |
| 942 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, | 948 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, |
| 943 core_->write_buffer_.buf); | 949 core_->write_buffer_.buf); |
| 944 } | 950 } |
| 945 } | 951 } |
| 946 core_->write_iobuffer_ = NULL; | 952 core_->write_iobuffer_ = NULL; |
| 947 DoWriteCallback(rv); | 953 DoWriteCallback(rv); |
| 948 } | 954 } |
| 949 | 955 |
| 950 } // namespace net | 956 } // namespace net |
| OLD | NEW |