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

Side by Side Diff: runtime/bin/socket_macos.cc

Issue 907883002: Remove SetNonBlocking/SetBlocking methods from Socket and add missing close-on-exec (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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_MACOS) 6 #if defined(TARGET_OS_MACOS)
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 return -1; 79 return -1;
80 } 80 }
81 81
82 82
83 intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) { 83 intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) {
84 intptr_t fd = Socket::Create(addr); 84 intptr_t fd = Socket::Create(addr);
85 if (fd < 0) { 85 if (fd < 0) {
86 return fd; 86 return fd;
87 } 87 }
88 88
89 Socket::SetNonBlocking(fd); 89 FDUtils::SetNonBlocking(fd);
90 90
91 return Socket::Connect(fd, addr, port); 91 return Socket::Connect(fd, addr, port);
92 } 92 }
93 93
94 94
95 intptr_t Socket::Available(intptr_t fd) { 95 intptr_t Socket::Available(intptr_t fd) {
96 return FDUtils::AvailableBytes(fd); 96 return FDUtils::AvailableBytes(fd);
97 } 97 }
98 98
99 99
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))); 291 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)));
292 } 292 }
293 293
294 SocketAddress::SetAddrPort(addr, port); 294 SocketAddress::SetAddrPort(addr, port);
295 if (NO_RETRY_EXPECTED( 295 if (NO_RETRY_EXPECTED(
296 bind(fd, &addr->addr, SocketAddress::GetAddrLength(addr))) < 0) { 296 bind(fd, &addr->addr, SocketAddress::GetAddrLength(addr))) < 0) {
297 VOID_TEMP_FAILURE_RETRY(close(fd)); 297 VOID_TEMP_FAILURE_RETRY(close(fd));
298 return -1; 298 return -1;
299 } 299 }
300 300
301 Socket::SetNonBlocking(fd); 301 FDUtils::SetNonBlocking(fd);
302 return fd; 302 return fd;
303 } 303 }
304 304
305 305
306 static bool ShouldIncludeIfaAddrs(struct ifaddrs* ifa, int lookup_family) { 306 static bool ShouldIncludeIfaAddrs(struct ifaddrs* ifa, int lookup_family) {
307 if (ifa->ifa_addr == NULL) { 307 if (ifa->ifa_addr == NULL) {
308 // OpenVPN's virtual device tun0. 308 // OpenVPN's virtual device tun0.
309 return false; 309 return false;
310 } 310 }
311 int family = ifa->ifa_addr->sa_family; 311 int family = ifa->ifa_addr->sa_family;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 VOID_TEMP_FAILURE_RETRY(close(fd)); 391 VOID_TEMP_FAILURE_RETRY(close(fd));
392 errno = err; 392 errno = err;
393 return new_fd; 393 return new_fd;
394 } 394 }
395 395
396 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) { 396 if (NO_RETRY_EXPECTED(listen(fd, backlog > 0 ? backlog : SOMAXCONN)) != 0) {
397 VOID_TEMP_FAILURE_RETRY(close(fd)); 397 VOID_TEMP_FAILURE_RETRY(close(fd));
398 return -1; 398 return -1;
399 } 399 }
400 400
401 Socket::SetNonBlocking(fd); 401 FDUtils::SetNonBlocking(fd);
402 return fd; 402 return fd;
403 } 403 }
404 404
405 405
406 bool ServerSocket::StartAccept(intptr_t fd) { 406 bool ServerSocket::StartAccept(intptr_t fd) {
407 USE(fd); 407 USE(fd);
408 return true; 408 return true;
409 } 409 }
410 410
411 411
412 intptr_t ServerSocket::Accept(intptr_t fd) { 412 intptr_t ServerSocket::Accept(intptr_t fd) {
413 intptr_t socket; 413 intptr_t socket;
414 struct sockaddr clientaddr; 414 struct sockaddr clientaddr;
415 socklen_t addrlen = sizeof(clientaddr); 415 socklen_t addrlen = sizeof(clientaddr);
416 socket = TEMP_FAILURE_RETRY(accept(fd, &clientaddr, &addrlen)); 416 socket = TEMP_FAILURE_RETRY(accept(fd, &clientaddr, &addrlen));
417 if (socket == -1) { 417 if (socket == -1) {
418 if (errno == EAGAIN) { 418 if (errno == EAGAIN) {
419 // We need to signal to the caller that this is actually not an 419 // We need to signal to the caller that this is actually not an
420 // error. We got woken up from the poll on the listening socket, 420 // error. We got woken up from the poll on the listening socket,
421 // but there is no connection ready to be accepted. 421 // but there is no connection ready to be accepted.
422 ASSERT(kTemporaryFailure != -1); 422 ASSERT(kTemporaryFailure != -1);
423 socket = kTemporaryFailure; 423 socket = kTemporaryFailure;
424 } 424 }
425 } else { 425 } else {
426 Socket::SetNonBlocking(socket); 426 FDUtils::SetNonBlocking(socket);
427 FDUtils::SetCloseOnExec(socket);
kustermann 2015/02/09 16:25:32 ditto.
Søren Gjesse 2015/02/10 07:28:15 Done.
427 } 428 }
428 return socket; 429 return socket;
429 } 430 }
430 431
431 432
432 void Socket::Close(intptr_t fd) { 433 void Socket::Close(intptr_t fd) {
433 ASSERT(fd >= 0); 434 ASSERT(fd >= 0);
434 VOID_TEMP_FAILURE_RETRY(close(fd)); 435 VOID_TEMP_FAILURE_RETRY(close(fd));
435 } 436 }
436 437
437 438
438 bool Socket::SetNonBlocking(intptr_t fd) {
439 return FDUtils::SetNonBlocking(fd);
440 }
441
442
443 bool Socket::SetBlocking(intptr_t fd) {
444 return FDUtils::SetBlocking(fd);
445 }
446
447
448 bool Socket::GetNoDelay(intptr_t fd, bool* enabled) { 439 bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
449 int on; 440 int on;
450 socklen_t len = sizeof(on); 441 socklen_t len = sizeof(on);
451 int err = NO_RETRY_EXPECTED(getsockopt(fd, 442 int err = NO_RETRY_EXPECTED(getsockopt(fd,
452 IPPROTO_TCP, 443 IPPROTO_TCP,
453 TCP_NODELAY, 444 TCP_NODELAY,
454 reinterpret_cast<void *>(&on), 445 reinterpret_cast<void *>(&on),
455 &len)); 446 &len));
456 if (err == 0) { 447 if (err == 0) {
457 *enabled = on == 1; 448 *enabled = on == 1;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 594
604 bool Socket::LeaveMulticast( 595 bool Socket::LeaveMulticast(
605 intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex) { 596 intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex) {
606 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false); 597 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false);
607 } 598 }
608 599
609 } // namespace bin 600 } // namespace bin
610 } // namespace dart 601 } // namespace dart
611 602
612 #endif // defined(TARGET_OS_MACOS) 603 #endif // defined(TARGET_OS_MACOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698