| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
| 6 | 6 |
| 7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
| 8 #if defined(HOST_OS_LINUX) | 8 #if defined(HOST_OS_LINUX) |
| 9 | 9 |
| 10 #include "bin/sync_socket.h" | 10 #include "bin/sync_socket.h" |
| 11 | 11 |
| 12 #include <errno.h> // NOLINT | 12 #include <errno.h> // NOLINT |
| 13 | 13 |
| 14 #include "bin/fdutils.h" | 14 #include "bin/fdutils.h" |
| 15 #include "bin/socket_base.h" | 15 #include "bin/socket_base.h" |
| 16 #include "platform/signal_blocker.h" | 16 #include "platform/signal_blocker.h" |
| 17 | 17 |
| 18 namespace dart { | 18 namespace dart { |
| 19 namespace bin { | 19 namespace bin { |
| 20 | 20 |
| 21 bool SynchronousSocket::Initialize() { | 21 bool SynchronousSocket::Initialize() { |
| 22 // Nothing to do on Linux. | 22 // Nothing to do on Linux. |
| 23 return true; | 23 return true; |
| 24 } | 24 } |
| 25 | 25 |
| 26 | |
| 27 static intptr_t Create(const RawAddr& addr) { | 26 static intptr_t Create(const RawAddr& addr) { |
| 28 intptr_t fd; | 27 intptr_t fd; |
| 29 intptr_t type = SOCK_STREAM | SOCK_CLOEXEC; | 28 intptr_t type = SOCK_STREAM | SOCK_CLOEXEC; |
| 30 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, type, 0)); | 29 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, type, 0)); |
| 31 if (fd < 0) { | 30 if (fd < 0) { |
| 32 return -1; | 31 return -1; |
| 33 } | 32 } |
| 34 return fd; | 33 return fd; |
| 35 } | 34 } |
| 36 | 35 |
| 37 | |
| 38 static intptr_t Connect(intptr_t fd, const RawAddr& addr) { | 36 static intptr_t Connect(intptr_t fd, const RawAddr& addr) { |
| 39 intptr_t result = TEMP_FAILURE_RETRY( | 37 intptr_t result = TEMP_FAILURE_RETRY( |
| 40 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr))); | 38 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr))); |
| 41 if (result == 0) { | 39 if (result == 0) { |
| 42 return fd; | 40 return fd; |
| 43 } | 41 } |
| 44 ASSERT(errno != EINPROGRESS); | 42 ASSERT(errno != EINPROGRESS); |
| 45 FDUtils::FDUtils::SaveErrorAndClose(fd); | 43 FDUtils::FDUtils::SaveErrorAndClose(fd); |
| 46 return -1; | 44 return -1; |
| 47 } | 45 } |
| 48 | 46 |
| 49 | |
| 50 intptr_t SynchronousSocket::CreateConnect(const RawAddr& addr) { | 47 intptr_t SynchronousSocket::CreateConnect(const RawAddr& addr) { |
| 51 intptr_t fd = Create(addr); | 48 intptr_t fd = Create(addr); |
| 52 if (fd < 0) { | 49 if (fd < 0) { |
| 53 return fd; | 50 return fd; |
| 54 } | 51 } |
| 55 return Connect(fd, addr); | 52 return Connect(fd, addr); |
| 56 } | 53 } |
| 57 | 54 |
| 58 | |
| 59 intptr_t SynchronousSocket::Available(intptr_t fd) { | 55 intptr_t SynchronousSocket::Available(intptr_t fd) { |
| 60 return SocketBase::Available(fd); | 56 return SocketBase::Available(fd); |
| 61 } | 57 } |
| 62 | 58 |
| 63 | |
| 64 intptr_t SynchronousSocket::GetPort(intptr_t fd) { | 59 intptr_t SynchronousSocket::GetPort(intptr_t fd) { |
| 65 return SocketBase::GetPort(fd); | 60 return SocketBase::GetPort(fd); |
| 66 } | 61 } |
| 67 | 62 |
| 68 | |
| 69 SocketAddress* SynchronousSocket::GetRemotePeer(intptr_t fd, intptr_t* port) { | 63 SocketAddress* SynchronousSocket::GetRemotePeer(intptr_t fd, intptr_t* port) { |
| 70 return SocketBase::GetRemotePeer(fd, port); | 64 return SocketBase::GetRemotePeer(fd, port); |
| 71 } | 65 } |
| 72 | 66 |
| 73 | |
| 74 intptr_t SynchronousSocket::Read(intptr_t fd, | 67 intptr_t SynchronousSocket::Read(intptr_t fd, |
| 75 void* buffer, | 68 void* buffer, |
| 76 intptr_t num_bytes) { | 69 intptr_t num_bytes) { |
| 77 return SocketBase::Read(fd, buffer, num_bytes, SocketBase::kSync); | 70 return SocketBase::Read(fd, buffer, num_bytes, SocketBase::kSync); |
| 78 } | 71 } |
| 79 | 72 |
| 80 | |
| 81 intptr_t SynchronousSocket::Write(intptr_t fd, | 73 intptr_t SynchronousSocket::Write(intptr_t fd, |
| 82 const void* buffer, | 74 const void* buffer, |
| 83 intptr_t num_bytes) { | 75 intptr_t num_bytes) { |
| 84 return SocketBase::Write(fd, buffer, num_bytes, SocketBase::kSync); | 76 return SocketBase::Write(fd, buffer, num_bytes, SocketBase::kSync); |
| 85 } | 77 } |
| 86 | 78 |
| 87 | |
| 88 void SynchronousSocket::ShutdownRead(intptr_t fd) { | 79 void SynchronousSocket::ShutdownRead(intptr_t fd) { |
| 89 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_RD)); | 80 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_RD)); |
| 90 } | 81 } |
| 91 | 82 |
| 92 | |
| 93 void SynchronousSocket::ShutdownWrite(intptr_t fd) { | 83 void SynchronousSocket::ShutdownWrite(intptr_t fd) { |
| 94 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_WR)); | 84 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_WR)); |
| 95 } | 85 } |
| 96 | 86 |
| 97 | |
| 98 void SynchronousSocket::Close(intptr_t fd) { | 87 void SynchronousSocket::Close(intptr_t fd) { |
| 99 return SocketBase::Close(fd); | 88 return SocketBase::Close(fd); |
| 100 } | 89 } |
| 101 | 90 |
| 102 } // namespace bin | 91 } // namespace bin |
| 103 } // namespace dart | 92 } // namespace dart |
| 104 | 93 |
| 105 #endif // defined(HOST_OS_LINUX) | 94 #endif // defined(HOST_OS_LINUX) |
| 106 | 95 |
| 107 #endif // !defined(DART_IO_DISABLED) | 96 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |