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

Unified Diff: runtime/bin/socket_win.cc

Issue 17842003: Avoid picking port 65535 for ServerSockets, when any is requested. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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
« runtime/bin/socket_macos.cc ('K') | « runtime/bin/socket_macos.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_win.cc
diff --git a/runtime/bin/socket_win.cc b/runtime/bin/socket_win.cc
index f24cfc591dc0642fe3cf92ac643ee017742aa8ef..ef37ad24e411143a4ed66c907590a480fd862c04 100644
--- a/runtime/bin/socket_win.cc
+++ b/runtime/bin/socket_win.cc
@@ -375,15 +375,30 @@ intptr_t ServerSocket::CreateBindListen(RawAddr addr,
return -1;
}
+ ListenSocket* listen_socket = new ListenSocket(s);
+
+ // Test for invalid socket port 65535 (some browsers disallow it).
+ if (port == 0 &&
+ Socket::GetPort(reinterpret_cast<intptr_t>(listen_socket)) == 65535) {
+ // Don't close fd until we have created new. By doing that we ensure another
+ // port.
+ intptr_t new_s = CreateBindListen(addr, 0, backlog, v6_only);
+ DWORD rc = WSAGetLastError();
+ closesocket(s);
+ delete listen_socket;
+ SetLastError(rc);
+ return new_s;
+ }
+
status = listen(s, backlog > 0 ? backlog : SOMAXCONN);
if (status == SOCKET_ERROR) {
DWORD rc = WSAGetLastError();
closesocket(s);
+ delete listen_socket;
SetLastError(rc);
return -1;
}
- ListenSocket* listen_socket = new ListenSocket(s);
return reinterpret_cast<intptr_t>(listen_socket);
}
« runtime/bin/socket_macos.cc ('K') | « runtime/bin/socket_macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698