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

Side by Side Diff: runtime/bin/socket_android.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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/socket_linux.cc » ('j') | runtime/bin/socket_macos.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 316
317 SocketAddress::SetAddrPort(&addr, port); 317 SocketAddress::SetAddrPort(&addr, port);
318 if (TEMP_FAILURE_RETRY( 318 if (TEMP_FAILURE_RETRY(
319 bind(fd, 319 bind(fd,
320 &addr.addr, 320 &addr.addr,
321 SocketAddress::GetAddrLength(&addr))) < 0) { 321 SocketAddress::GetAddrLength(&addr))) < 0) {
322 TEMP_FAILURE_RETRY(close(fd)); 322 TEMP_FAILURE_RETRY(close(fd));
323 return -1; 323 return -1;
324 } 324 }
325 325
326 // Test for invalid socket port 65535 (some browsers disallow it).
327 if (port == 0 && Socket::GetPort(fd) == 65535) {
328 // Don't close fd until we have created new. By doing that we ensure another
329 // port.
330 intptr_t new_fd = CreateBindListen(addr, 0, backlog, v6_only);
331 int err = errno;
332 TEMP_FAILURE_RETRY(close(fd));
333 errno = err;
334 return new_fd;
335 }
336
326 if (TEMP_FAILURE_RETRY(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { 337 if (TEMP_FAILURE_RETRY(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
327 TEMP_FAILURE_RETRY(close(fd)); 338 TEMP_FAILURE_RETRY(close(fd));
328 return -1; 339 return -1;
329 } 340 }
330 341
331 Socket::SetNonBlocking(fd); 342 Socket::SetNonBlocking(fd);
332 return fd; 343 return fd;
333 } 344 }
334 345
335 346
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 SOL_TCP, 402 SOL_TCP,
392 TCP_NODELAY, 403 TCP_NODELAY,
393 reinterpret_cast<char *>(&on), 404 reinterpret_cast<char *>(&on),
394 sizeof(on))) == 0; 405 sizeof(on))) == 0;
395 } 406 }
396 407
397 } // namespace bin 408 } // namespace bin
398 } // namespace dart 409 } // namespace dart
399 410
400 #endif // defined(TARGET_OS_ANDROID) 411 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/socket_linux.cc » ('j') | runtime/bin/socket_macos.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698