Chromium Code Reviews| Index: runtime/bin/sync_socket_android.cc |
| diff --git a/runtime/bin/sync_socket_android.cc b/runtime/bin/sync_socket_android.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..673e42a2d6961dc9a6e30dfd4c3045257c534c7c |
| --- /dev/null |
| +++ b/runtime/bin/sync_socket_android.cc |
| @@ -0,0 +1,91 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
|
zra
2017/04/07 16:29:40
2017
bkonyi
2017/04/10 19:20:05
Done.
|
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +#if !defined(DART_IO_DISABLED) |
| + |
| +#include "platform/globals.h" |
| +#if defined(HOST_OS_ANDROID) |
| + |
| +#include "bin/sync_socket.h" |
| + |
| +#include <errno.h> // NOLINT |
|
zra
2017/04/07 16:29:40
Are all of these includes really needed?
bkonyi
2017/04/10 19:20:05
Apparently not. I've removed them here and on most
|
| +#include <ifaddrs.h> // NOLINT |
| +#include <net/if.h> // NOLINT |
| +#include <netinet/tcp.h> // NOLINT |
| +#include <poll.h> // NOLINT |
| +#include <stdio.h> // NOLINT |
| +#include <stdlib.h> // NOLINT |
| +#include <string.h> // NOLINT |
| +#include <sys/stat.h> // NOLINT |
| +#include <unistd.h> // NOLINT |
| + |
| +#include "bin/fdutils.h" |
| +#include "bin/file.h" |
| +#include "bin/socket_base_android.h" |
| +#include "bin/thread.h" |
| +#include "platform/signal_blocker.h" |
| + |
| +namespace dart { |
| +namespace bin { |
| + |
| +SynchronousSocket::SynchronousSocket(intptr_t fd) : fd_(fd) {} |
| + |
| + |
| +void SynchronousSocket::SetClosedFd() { |
| + fd_ = kClosedFd; |
| +} |
| + |
| + |
| +bool SynchronousSocket::Initialize() { |
| + // Nothing to do on Android. |
| + return true; |
| +} |
| + |
| + |
| +static intptr_t Create(const RawAddr& addr) { |
| + intptr_t fd; |
| + intptr_t type = SOCK_STREAM | SOCK_CLOEXEC; |
| + fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, type, 0)); |
| + if (fd < 0) { |
| + return -1; |
| + } |
| + return fd; |
| +} |
| + |
| + |
| +static intptr_t Connect(intptr_t fd, const RawAddr& addr) { |
| + intptr_t result = TEMP_FAILURE_RETRY( |
| + connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr))); |
| + if ((result == 0) || (errno == EINPROGRESS)) { |
|
zra
2017/04/07 16:29:40
The socket is not non-blocking, so errno should ne
bkonyi
2017/04/10 19:20:05
Done.
|
| + return fd; |
| + } |
| + FDUtils::FDUtils::SaveErrorAndClose(fd); |
| + return -1; |
| +} |
| + |
| + |
| +intptr_t SynchronousSocket::CreateConnect(const RawAddr& addr) { |
| + intptr_t fd = Create(addr); |
| + if (fd < 0) { |
| + return fd; |
| + } |
| + return Connect(fd, addr); |
| +} |
| + |
| + |
| +void SynchronousSocket::ShutdownRead(intptr_t fd) { |
| + VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_RD)); |
| +} |
| + |
| + |
| +void SynchronousSocket::ShutdownWrite(intptr_t fd) { |
| + VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_WR)); |
| +} |
| + |
| +} // namespace bin |
| +} // namespace dart |
| + |
| +#endif // defined(HOST_OS_ANDROID) |
| + |
| +#endif // !defined(DART_IO_DISABLED) |