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. |
|
wtc
2012/07/19 18:36:36
In the CL's description, the BUG=119312 field shou
Sergey Ulanov
2012/07/19 21:36:20
Done.
| |
| 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.h" | 5 #include "net/socket/tcp_client_socket.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <netdb.h> | 9 #include <netdb.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| 11 #include <netinet/tcp.h> | 11 #include <netinet/tcp.h> |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 if (current_address_index_ >= 0 || bind_address_.get()) { | 173 if (current_address_index_ >= 0 || bind_address_.get()) { |
| 174 // Cannot bind the socket if we are already bound connected or | 174 // Cannot bind the socket if we are already bound connected or |
| 175 // connecting. | 175 // connecting. |
| 176 return ERR_UNEXPECTED; | 176 return ERR_UNEXPECTED; |
| 177 } | 177 } |
| 178 | 178 |
| 179 SockaddrStorage storage; | 179 SockaddrStorage storage; |
| 180 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) | 180 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) |
| 181 return ERR_INVALID_ARGUMENT; | 181 return ERR_INVALID_ARGUMENT; |
| 182 | 182 |
| 183 // Create |bound_socket_| and try to bound it to |address|. | 183 // Create |bound_socket_| and try to bind it to |address|. |
| 184 int error = CreateSocket(address.GetFamily(), &bound_socket_); | 184 int error = CreateSocket(address.GetFamily(), &bound_socket_); |
| 185 if (error) | 185 if (error) |
| 186 return MapSystemError(error); | 186 return MapSystemError(error); |
| 187 | 187 |
| 188 if (HANDLE_EINTR(bind(bound_socket_, storage.addr, storage.addr_len))) { | 188 if (HANDLE_EINTR(bind(bound_socket_, storage.addr, storage.addr_len))) { |
| 189 error = errno; | 189 error = errno; |
| 190 if (HANDLE_EINTR(close(bound_socket_)) < 0) | 190 if (HANDLE_EINTR(close(bound_socket_)) < 0) |
| 191 PLOG(ERROR) << "close"; | 191 PLOG(ERROR) << "close"; |
| 192 bound_socket_ = kInvalidSocket; | 192 bound_socket_ = kInvalidSocket; |
| 193 return MapSystemError(error); | 193 return MapSystemError(error); |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 711 DCHECK(address); | 711 DCHECK(address); |
| 712 if (!IsConnected()) | 712 if (!IsConnected()) |
| 713 return ERR_SOCKET_NOT_CONNECTED; | 713 return ERR_SOCKET_NOT_CONNECTED; |
| 714 *address = addresses_[current_address_index_]; | 714 *address = addresses_[current_address_index_]; |
| 715 return OK; | 715 return OK; |
| 716 } | 716 } |
| 717 | 717 |
| 718 int TCPClientSocketLibevent::GetLocalAddress(IPEndPoint* address) const { | 718 int TCPClientSocketLibevent::GetLocalAddress(IPEndPoint* address) const { |
| 719 DCHECK(CalledOnValidThread()); | 719 DCHECK(CalledOnValidThread()); |
| 720 DCHECK(address); | 720 DCHECK(address); |
| 721 if (!IsConnected()) | 721 if (socket_ == kInvalidSocket) { |
| 722 return ERR_SOCKET_NOT_CONNECTED; | 722 if (bind_address_.get()) { |
| 723 *address = *bind_address_; | |
| 724 return OK; | |
| 725 } else { | |
| 726 return ERR_SOCKET_NOT_CONNECTED; | |
| 727 } | |
| 728 } | |
| 723 | 729 |
| 724 SockaddrStorage storage; | 730 SockaddrStorage storage; |
| 725 if (getsockname(socket_, storage.addr, &storage.addr_len)) | 731 if (getsockname(socket_, storage.addr, &storage.addr_len)) |
| 726 return MapSystemError(errno); | 732 return MapSystemError(errno); |
| 727 if (!address->FromSockAddr(storage.addr, storage.addr_len)) | 733 if (!address->FromSockAddr(storage.addr, storage.addr_len)) |
| 728 return ERR_FAILED; | 734 return ERR_FAILED; |
| 729 | 735 |
| 730 return OK; | 736 return OK; |
| 731 } | 737 } |
| 732 | 738 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 756 | 762 |
| 757 base::TimeDelta TCPClientSocketLibevent::GetConnectTimeMicros() const { | 763 base::TimeDelta TCPClientSocketLibevent::GetConnectTimeMicros() const { |
| 758 return connect_time_micros_; | 764 return connect_time_micros_; |
| 759 } | 765 } |
| 760 | 766 |
| 761 NextProto TCPClientSocketLibevent::GetNegotiatedProtocol() const { | 767 NextProto TCPClientSocketLibevent::GetNegotiatedProtocol() const { |
| 762 return kProtoUnknown; | 768 return kProtoUnknown; |
| 763 } | 769 } |
| 764 | 770 |
| 765 } // namespace net | 771 } // namespace net |
| OLD | NEW |