| OLD | NEW |
| 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 (error == ENOPROTOOPT) || (error == EHOSTDOWN) || (error == ENONET) || | 413 (error == ENOPROTOOPT) || (error == EHOSTDOWN) || (error == ENONET) || |
| 414 (error == EHOSTUNREACH) || (error == EOPNOTSUPP) || | 414 (error == EHOSTUNREACH) || (error == EOPNOTSUPP) || |
| 415 (error == ENETUNREACH); | 415 (error == ENETUNREACH); |
| 416 } | 416 } |
| 417 | 417 |
| 418 | 418 |
| 419 intptr_t ServerSocket::Accept(intptr_t fd) { | 419 intptr_t ServerSocket::Accept(intptr_t fd) { |
| 420 intptr_t socket; | 420 intptr_t socket; |
| 421 struct sockaddr clientaddr; | 421 struct sockaddr clientaddr; |
| 422 socklen_t addrlen = sizeof(clientaddr); | 422 socklen_t addrlen = sizeof(clientaddr); |
| 423 socket = TEMP_FAILURE_RETRY(accept4( | 423 socket = TEMP_FAILURE_RETRY(accept(fd, &clientaddr, &addrlen)); |
| 424 fd, &clientaddr, &addrlen, SOCK_NONBLOCK | SOCK_CLOEXEC)); | |
| 425 if (socket == -1) { | 424 if (socket == -1) { |
| 426 if (IsTemporaryAcceptError(errno)) { | 425 if (IsTemporaryAcceptError(errno)) { |
| 427 // We need to signal to the caller that this is actually not an | 426 // We need to signal to the caller that this is actually not an |
| 428 // error. We got woken up from the poll on the listening socket, | 427 // error. We got woken up from the poll on the listening socket, |
| 429 // but there is no connection ready to be accepted. | 428 // but there is no connection ready to be accepted. |
| 430 ASSERT(kTemporaryFailure != -1); | 429 ASSERT(kTemporaryFailure != -1); |
| 431 socket = kTemporaryFailure; | 430 socket = kTemporaryFailure; |
| 432 } | 431 } |
| 432 } else { |
| 433 FDUtils::SetNonBlocking(socket); |
| 434 FDUtils::SetCloseOnExec(socket); |
| 433 } | 435 } |
| 434 return socket; | 436 return socket; |
| 435 } | 437 } |
| 436 | 438 |
| 437 | 439 |
| 438 void Socket::Close(intptr_t fd) { | 440 void Socket::Close(intptr_t fd) { |
| 439 ASSERT(fd >= 0); | 441 ASSERT(fd >= 0); |
| 440 int err = TEMP_FAILURE_RETRY(close(fd)); | 442 int err = TEMP_FAILURE_RETRY(close(fd)); |
| 441 if (err != 0) { | 443 if (err != 0) { |
| 442 const int kBufferSize = 1024; | 444 const int kBufferSize = 1024; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 mreq.gr_interface = interfaceIndex; | 560 mreq.gr_interface = interfaceIndex; |
| 559 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); | 561 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); |
| 560 return NO_RETRY_EXPECTED( | 562 return NO_RETRY_EXPECTED( |
| 561 setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; | 563 setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; |
| 562 } | 564 } |
| 563 | 565 |
| 564 } // namespace bin | 566 } // namespace bin |
| 565 } // namespace dart | 567 } // namespace dart |
| 566 | 568 |
| 567 #endif // defined(TARGET_OS_LINUX) | 569 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |