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

Unified Diff: net/socket/tcp_client_socket_win.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
Index: net/socket/tcp_client_socket_win.cc
diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc
index aed2adbb85153a41073f2aa1c7659a2b233bde2f..1c69d3ed0293ef655aaba3d4793d58e17a585a51 100644
--- a/net/socket/tcp_client_socket_win.cc
+++ b/net/socket/tcp_client_socket_win.cc
@@ -373,7 +373,7 @@ int TCPClientSocketWin::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);
@@ -646,8 +646,14 @@ int TCPClientSocketWin::GetPeerAddress(IPEndPoint* address) const {
int TCPClientSocketWin::GetLocalAddress(IPEndPoint* address) const {
DCHECK(CalledOnValidThread());
DCHECK(address);
- if (!IsConnected())
- return ERR_SOCKET_NOT_CONNECTED;
+ if (socket_ == INVALID_SOCKET) {
+ if (bind_address_.get()) {
+ *address = *bind_address_;
+ return OK;
+ } else {
wtc 2012/07/19 18:36:36 Nit: omit "else" after a return statement.
Sergey Ulanov 2012/07/19 21:36:20 Done.
+ return ERR_SOCKET_NOT_CONNECTED;
+ }
+ }
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.
struct sockaddr_storage addr_storage;
socklen_t addr_len = sizeof(addr_storage);
« net/socket/tcp_client_socket_unittest.cc ('K') | « net/socket/tcp_client_socket_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698