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