Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
sync_socket_macos.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include "platform/globals.h"
6#if defined(DART_HOST_OS_MACOS)
7
8#include "bin/sync_socket.h"
9
10#include <errno.h> // NOLINT
11
12#include "bin/fdutils.h"
13#include "bin/socket_base.h"
15
16namespace dart {
17namespace bin {
18
20 // Nothing to do on Linux.
21 return true;
22}
23
24static intptr_t Create(const RawAddr& addr) {
25 intptr_t fd;
26 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0));
27 if (fd < 0) {
28 return -1;
29 }
30 if (!FDUtils::SetCloseOnExec(fd)) {
32 return -1;
33 }
34 return fd;
35}
36
37static intptr_t Connect(intptr_t fd, const RawAddr& addr) {
38 intptr_t result = TEMP_FAILURE_RETRY(
39 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr)));
40 if (result == 0) {
41 return fd;
42 }
43 ASSERT(errno != EINPROGRESS);
45 return -1;
46}
47
48intptr_t SynchronousSocket::CreateConnect(const RawAddr& addr) {
49 intptr_t fd = Create(addr);
50 if (fd < 0) {
51 return fd;
52 }
53 return Connect(fd, addr);
54}
55
56intptr_t SynchronousSocket::Available(intptr_t fd) {
58}
59
60intptr_t SynchronousSocket::GetPort(intptr_t fd) {
61 return SocketBase::GetPort(fd);
62}
63
64SocketAddress* SynchronousSocket::GetRemotePeer(intptr_t fd, intptr_t* port) {
65 return SocketBase::GetRemotePeer(fd, port);
66}
67
68intptr_t SynchronousSocket::Read(intptr_t fd,
69 void* buffer,
70 intptr_t num_bytes) {
71 return SocketBase::Read(fd, buffer, num_bytes, SocketBase::kSync);
72}
73
74intptr_t SynchronousSocket::Write(intptr_t fd,
75 const void* buffer,
76 intptr_t num_bytes) {
77 return SocketBase::Write(fd, buffer, num_bytes, SocketBase::kSync);
78}
79
80void SynchronousSocket::ShutdownRead(intptr_t fd) {
81 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_RD));
82}
83
84void SynchronousSocket::ShutdownWrite(intptr_t fd) {
85 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_WR));
86}
87
88void SynchronousSocket::Close(intptr_t fd) {
89 return SocketBase::Close(fd);
90}
91
92} // namespace bin
93} // namespace dart
94
95#endif // defined(DART_HOST_OS_MACOS)
static sk_sp< Effect > Create()
static bool SetCloseOnExec(intptr_t fd)
static void SaveErrorAndClose(intptr_t fd)
static intptr_t GetAddrLength(const RawAddr &addr, bool unnamed_unix_socket=false)
static SocketAddress * GetRemotePeer(intptr_t fd, intptr_t *port)
static intptr_t Available(intptr_t fd)
static void Close(intptr_t fd)
static intptr_t Read(intptr_t fd, void *buffer, intptr_t num_bytes, SocketOpKind sync)
static intptr_t Write(intptr_t fd, const void *buffer, intptr_t num_bytes, SocketOpKind sync)
static intptr_t GetPort(intptr_t fd)
static SocketAddress * GetRemotePeer(intptr_t fd, intptr_t *port)
static intptr_t Available(intptr_t fd)
static intptr_t CreateConnect(const RawAddr &addr)
static void ShutdownRead(intptr_t fd)
static void Close(intptr_t fd)
static intptr_t Read(intptr_t fd, void *buffer, intptr_t num_bytes)
static intptr_t Write(intptr_t fd, const void *buffer, intptr_t num_bytes)
static intptr_t GetPort(intptr_t fd)
static void ShutdownWrite(intptr_t fd)
#define ASSERT(E)
static const uint8_t buffer[]
GAsyncResult * result
#define NO_RETRY_EXPECTED(expression)
#define VOID_NO_RETRY_EXPECTED(expression)
#define TEMP_FAILURE_RETRY(expression)