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

Side by Side Diff: runtime/bin/socket_linux.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
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_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include <errno.h> // NOLINT 8 #include <errno.h> // NOLINT
9 #include <stdio.h> // NOLINT 9 #include <stdio.h> // NOLINT
10 #include <stdlib.h> // NOLINT 10 #include <stdlib.h> // NOLINT
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 315
316 SocketAddress::SetAddrPort(&addr, port); 316 SocketAddress::SetAddrPort(&addr, port);
317 if (TEMP_FAILURE_RETRY( 317 if (TEMP_FAILURE_RETRY(
318 bind(fd, 318 bind(fd,
319 &addr.addr, 319 &addr.addr,
320 SocketAddress::GetAddrLength(&addr))) < 0) { 320 SocketAddress::GetAddrLength(&addr))) < 0) {
321 TEMP_FAILURE_RETRY(close(fd)); 321 TEMP_FAILURE_RETRY(close(fd));
322 return -1; 322 return -1;
323 } 323 }
324 324
325 // Test for invalid socket port 65535 (some browsers disallow it).
326 if (port == 0 && Socket::GetPort(fd) == 65535) {
327 // Don't close fd until we have created new. By doing that we ensure another
328 // port.
329 intptr_t new_fd = CreateBindListen(addr, 0, backlog, v6_only);
330 int err = errno;
331 TEMP_FAILURE_RETRY(close(fd));
332 errno = err;
333 return new_fd;
334 }
335
325 if (TEMP_FAILURE_RETRY(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { 336 if (TEMP_FAILURE_RETRY(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
326 TEMP_FAILURE_RETRY(close(fd)); 337 TEMP_FAILURE_RETRY(close(fd));
327 return -1; 338 return -1;
328 } 339 }
329 340
330 Socket::SetNonBlocking(fd); 341 Socket::SetNonBlocking(fd);
331 return fd; 342 return fd;
332 } 343 }
333 344
334 345
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 SOL_TCP, 401 SOL_TCP,
391 TCP_NODELAY, 402 TCP_NODELAY,
392 reinterpret_cast<char *>(&on), 403 reinterpret_cast<char *>(&on),
393 sizeof(on))) == 0; 404 sizeof(on))) == 0;
394 } 405 }
395 406
396 } // namespace bin 407 } // namespace bin
397 } // namespace dart 408 } // namespace dart
398 409
399 #endif // defined(TARGET_OS_LINUX) 410 #endif // defined(TARGET_OS_LINUX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698