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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
« runtime/bin/socket_macos.cc ('K') | « runtime/bin/socket_macos.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_WINDOWS) 6 #if defined(TARGET_OS_WINDOWS)
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/eventhandler.h" 9 #include "bin/eventhandler.h"
10 #include "bin/file.h" 10 #include "bin/file.h"
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 status = bind(s, 368 status = bind(s,
369 &addr.addr, 369 &addr.addr,
370 SocketAddress::GetAddrLength(&addr)); 370 SocketAddress::GetAddrLength(&addr));
371 if (status == SOCKET_ERROR) { 371 if (status == SOCKET_ERROR) {
372 DWORD rc = WSAGetLastError(); 372 DWORD rc = WSAGetLastError();
373 closesocket(s); 373 closesocket(s);
374 SetLastError(rc); 374 SetLastError(rc);
375 return -1; 375 return -1;
376 } 376 }
377 377
378 ListenSocket* listen_socket = new ListenSocket(s);
379
380 // Test for invalid socket port 65535 (some browsers disallow it).
381 if (port == 0 &&
382 Socket::GetPort(reinterpret_cast<intptr_t>(listen_socket)) == 65535) {
383 // Don't close fd until we have created new. By doing that we ensure another
384 // port.
385 intptr_t new_s = CreateBindListen(addr, 0, backlog, v6_only);
386 DWORD rc = WSAGetLastError();
387 closesocket(s);
388 delete listen_socket;
389 SetLastError(rc);
390 return new_s;
391 }
392
378 status = listen(s, backlog > 0 ? backlog : SOMAXCONN); 393 status = listen(s, backlog > 0 ? backlog : SOMAXCONN);
379 if (status == SOCKET_ERROR) { 394 if (status == SOCKET_ERROR) {
380 DWORD rc = WSAGetLastError(); 395 DWORD rc = WSAGetLastError();
381 closesocket(s); 396 closesocket(s);
397 delete listen_socket;
382 SetLastError(rc); 398 SetLastError(rc);
383 return -1; 399 return -1;
384 } 400 }
385 401
386 ListenSocket* listen_socket = new ListenSocket(s);
387 return reinterpret_cast<intptr_t>(listen_socket); 402 return reinterpret_cast<intptr_t>(listen_socket);
388 } 403 }
389 404
390 405
391 void Socket::Close(intptr_t fd) { 406 void Socket::Close(intptr_t fd) {
392 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(fd); 407 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(fd);
393 client_socket->Close(); 408 client_socket->Close();
394 } 409 }
395 410
396 411
(...skipping 26 matching lines...) Expand all
423 IPPROTO_TCP, 438 IPPROTO_TCP,
424 TCP_NODELAY, 439 TCP_NODELAY,
425 reinterpret_cast<char *>(&on), 440 reinterpret_cast<char *>(&on),
426 sizeof(on)) == 0; 441 sizeof(on)) == 0;
427 } 442 }
428 443
429 } // namespace bin 444 } // namespace bin
430 } // namespace dart 445 } // namespace dart
431 446
432 #endif // defined(TARGET_OS_WINDOWS) 447 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« 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