| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 #if !defined(DART_IO_DISABLED) | |
| 6 | |
| 7 #include "platform/globals.h" | |
| 8 #if defined(HOST_OS_MACOS) | |
| 9 | |
| 10 #include "bin/sync_socket.h" | |
| 11 | |
| 12 #include <errno.h> // NOLINT | |
| 13 | |
| 14 #include "bin/fdutils.h" | |
| 15 #include "platform/signal_blocker.h" | |
| 16 | |
| 17 namespace dart { | |
| 18 namespace bin { | |
| 19 | |
| 20 SynchronousSocket::SynchronousSocket(intptr_t fd) : fd_(fd) {} | |
| 21 | |
| 22 | |
| 23 void SynchronousSocket::SetClosedFd() { | |
| 24 fd_ = kClosedFd; | |
| 25 } | |
| 26 | |
| 27 | |
| 28 static intptr_t Create(const RawAddr& addr) { | |
| 29 intptr_t fd; | |
| 30 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); | |
| 31 if (fd < 0) { | |
| 32 return -1; | |
| 33 } | |
| 34 if (!FDUtils::SetCloseOnExec(fd)) { | |
| 35 FDUtils::SaveErrorAndClose(fd); | |
| 36 return -1; | |
| 37 } | |
| 38 return fd; | |
| 39 } | |
| 40 | |
| 41 | |
| 42 static intptr_t Connect(intptr_t fd, const RawAddr& addr) { | |
| 43 intptr_t result = TEMP_FAILURE_RETRY( | |
| 44 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr))); | |
| 45 if (result == 0) { | |
| 46 return fd; | |
| 47 } | |
| 48 ASSERT(errno != EINPROGRESS); | |
| 49 FDUtils::FDUtils::SaveErrorAndClose(fd); | |
| 50 return -1; | |
| 51 } | |
| 52 | |
| 53 | |
| 54 intptr_t SynchronousSocket::CreateConnect(const RawAddr& addr) { | |
| 55 intptr_t fd = Create(addr); | |
| 56 if (fd < 0) { | |
| 57 return fd; | |
| 58 } | |
| 59 return Connect(fd, addr); | |
| 60 } | |
| 61 | |
| 62 | |
| 63 void SynchronousSocket::ShutdownRead(intptr_t fd) { | |
| 64 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_RD)); | |
| 65 } | |
| 66 | |
| 67 | |
| 68 void SynchronousSocket::ShutdownWrite(intptr_t fd) { | |
| 69 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_WR)); | |
| 70 } | |
| 71 | |
| 72 } // namespace bin | |
| 73 } // namespace dart | |
| 74 | |
| 75 #endif // defined(HOST_OS_MACOS) | |
| 76 | |
| 77 #endif // !defined(DART_IO_DISABLED) | |
| OLD | NEW |