Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Unified Diff: net/socket/tcp_client_socket_libevent.cc

Issue 10803027: Fix TCPClientSocket::GetLocalAddress() to work when socket is not connected. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/socket/stream_socket.h ('k') | net/socket/tcp_client_socket_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/tcp_client_socket_libevent.cc
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index d139a5478d60a0e99ddcd72553701f4ba97e1647..043ffb9d96e33582f6e78f99ff69128a010c98e6 100644
--- a/net/socket/tcp_client_socket_libevent.cc
+++ b/net/socket/tcp_client_socket_libevent.cc
@@ -180,7 +180,7 @@ int TCPClientSocketLibevent::Bind(const IPEndPoint& address) {
if (!address.ToSockAddr(storage.addr, &storage.addr_len))
return ERR_INVALID_ARGUMENT;
- // Create |bound_socket_| and try to bound it to |address|.
+ // Create |bound_socket_| and try to bind it to |address|.
int error = CreateSocket(address.GetFamily(), &bound_socket_);
if (error)
return MapSystemError(error);
@@ -363,6 +363,7 @@ void TCPClientSocketLibevent::Disconnect() {
DoDisconnect();
current_address_index_ = -1;
+ bind_address_.reset();
}
void TCPClientSocketLibevent::DoDisconnect() {
@@ -718,8 +719,13 @@ int TCPClientSocketLibevent::GetPeerAddress(IPEndPoint* address) const {
int TCPClientSocketLibevent::GetLocalAddress(IPEndPoint* address) const {
DCHECK(CalledOnValidThread());
DCHECK(address);
- if (!IsConnected())
+ if (socket_ == kInvalidSocket) {
+ if (bind_address_.get()) {
+ *address = *bind_address_;
+ return OK;
+ }
return ERR_SOCKET_NOT_CONNECTED;
+ }
SockaddrStorage storage;
if (getsockname(socket_, storage.addr, &storage.addr_len))
« no previous file with comments | « net/socket/stream_socket.h ('k') | net/socket/tcp_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698