| 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_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 |
| 11 #include <string.h> // NOLINT | 11 #include <string.h> // NOLINT |
| 12 #include <sys/stat.h> // NOLINT | 12 #include <sys/stat.h> // NOLINT |
| 13 #include <unistd.h> // NOLINT | 13 #include <unistd.h> // NOLINT |
| 14 #include <net/if.h> // NOLINT | 14 #include <net/if.h> // NOLINT |
| 15 #include <netinet/tcp.h> // NOLINT | 15 #include <netinet/tcp.h> // NOLINT |
| 16 #include <ifaddrs.h> // NOLINT | 16 #include <ifaddrs.h> // NOLINT |
| 17 | 17 |
| 18 #include "bin/fdutils.h" | 18 #include "bin/fdutils.h" |
| 19 #include "bin/file.h" | 19 #include "bin/file.h" |
| 20 #include "bin/log.h" | |
| 21 #include "bin/socket.h" | 20 #include "bin/socket.h" |
| 22 | 21 |
| 23 #include "platform/signal_blocker.h" | 22 #include "platform/signal_blocker.h" |
| 24 | 23 |
| 25 | 24 |
| 26 namespace dart { | 25 namespace dart { |
| 27 namespace bin { | 26 namespace bin { |
| 28 | 27 |
| 29 SocketAddress::SocketAddress(struct sockaddr* sa) { | 28 SocketAddress::SocketAddress(struct sockaddr* sa) { |
| 30 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); | 29 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 55 bool Socket::Initialize() { | 54 bool Socket::Initialize() { |
| 56 // Nothing to do on Mac OS. | 55 // Nothing to do on Mac OS. |
| 57 return true; | 56 return true; |
| 58 } | 57 } |
| 59 | 58 |
| 60 | 59 |
| 61 intptr_t Socket::Create(RawAddr addr) { | 60 intptr_t Socket::Create(RawAddr addr) { |
| 62 intptr_t fd; | 61 intptr_t fd; |
| 63 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); | 62 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); |
| 64 if (fd < 0) { | 63 if (fd < 0) { |
| 65 const int kBufferSize = 1024; | |
| 66 char error_message[kBufferSize]; | |
| 67 strerror_r(errno, error_message, kBufferSize); | |
| 68 Log::PrintErr("Error Create: %s\n", error_message); | |
| 69 return -1; | 64 return -1; |
| 70 } | 65 } |
| 71 | |
| 72 FDUtils::SetCloseOnExec(fd); | 66 FDUtils::SetCloseOnExec(fd); |
| 73 return fd; | 67 return fd; |
| 74 } | 68 } |
| 75 | 69 |
| 76 | 70 |
| 77 intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) { | 71 intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) { |
| 78 SocketAddress::SetAddrPort(&addr, port); | 72 SocketAddress::SetAddrPort(&addr, port); |
| 79 intptr_t result = TEMP_FAILURE_RETRY( | 73 intptr_t result = TEMP_FAILURE_RETRY( |
| 80 connect(fd, &addr.addr, SocketAddress::GetAddrLength(&addr))); | 74 connect(fd, &addr.addr, SocketAddress::GetAddrLength(&addr))); |
| 81 if (result == 0 || errno == EINPROGRESS) { | 75 if (result == 0 || errno == EINPROGRESS) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 152 } |
| 159 return written_bytes; | 153 return written_bytes; |
| 160 } | 154 } |
| 161 | 155 |
| 162 | 156 |
| 163 intptr_t Socket::GetPort(intptr_t fd) { | 157 intptr_t Socket::GetPort(intptr_t fd) { |
| 164 ASSERT(fd >= 0); | 158 ASSERT(fd >= 0); |
| 165 RawAddr raw; | 159 RawAddr raw; |
| 166 socklen_t size = sizeof(raw); | 160 socklen_t size = sizeof(raw); |
| 167 if (NO_RETRY_EXPECTED(getsockname(fd, &raw.addr, &size))) { | 161 if (NO_RETRY_EXPECTED(getsockname(fd, &raw.addr, &size))) { |
| 168 const int kBufferSize = 1024; | |
| 169 char error_message[kBufferSize]; | |
| 170 strerror_r(errno, error_message, kBufferSize); | |
| 171 Log::PrintErr("Error getsockname: %s\n", error_message); | |
| 172 return 0; | 162 return 0; |
| 173 } | 163 } |
| 174 return SocketAddress::GetAddrPort(&raw); | 164 return SocketAddress::GetAddrPort(&raw); |
| 175 } | 165 } |
| 176 | 166 |
| 177 | 167 |
| 178 SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) { | 168 SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) { |
| 179 ASSERT(fd >= 0); | 169 ASSERT(fd >= 0); |
| 180 RawAddr raw; | 170 RawAddr raw; |
| 181 socklen_t size = sizeof(raw); | 171 socklen_t size = sizeof(raw); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 424 } |
| 435 } else { | 425 } else { |
| 436 Socket::SetNonBlocking(socket); | 426 Socket::SetNonBlocking(socket); |
| 437 } | 427 } |
| 438 return socket; | 428 return socket; |
| 439 } | 429 } |
| 440 | 430 |
| 441 | 431 |
| 442 void Socket::Close(intptr_t fd) { | 432 void Socket::Close(intptr_t fd) { |
| 443 ASSERT(fd >= 0); | 433 ASSERT(fd >= 0); |
| 444 int err = TEMP_FAILURE_RETRY(close(fd)); | 434 VOID_TEMP_FAILURE_RETRY(close(fd)); |
| 445 if (err != 0) { | |
| 446 const int kBufferSize = 1024; | |
| 447 char error_message[kBufferSize]; | |
| 448 strerror_r(errno, error_message, kBufferSize); | |
| 449 Log::PrintErr("%s\n", error_message); | |
| 450 } | |
| 451 } | 435 } |
| 452 | 436 |
| 453 | 437 |
| 454 bool Socket::SetNonBlocking(intptr_t fd) { | 438 bool Socket::SetNonBlocking(intptr_t fd) { |
| 455 return FDUtils::SetNonBlocking(fd); | 439 return FDUtils::SetNonBlocking(fd); |
| 456 } | 440 } |
| 457 | 441 |
| 458 | 442 |
| 459 bool Socket::SetBlocking(intptr_t fd) { | 443 bool Socket::SetBlocking(intptr_t fd) { |
| 460 return FDUtils::SetBlocking(fd); | 444 return FDUtils::SetBlocking(fd); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 603 |
| 620 bool Socket::LeaveMulticast( | 604 bool Socket::LeaveMulticast( |
| 621 intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex) { | 605 intptr_t fd, RawAddr* addr, RawAddr* interface, int interfaceIndex) { |
| 622 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false); | 606 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false); |
| 623 } | 607 } |
| 624 | 608 |
| 625 } // namespace bin | 609 } // namespace bin |
| 626 } // namespace dart | 610 } // namespace dart |
| 627 | 611 |
| 628 #endif // defined(TARGET_OS_MACOS) | 612 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |