6#if defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_LINUX) || \
7 defined(DART_HOST_OS_MACOS)
12#include <netinet/tcp.h>
29 if (unnamed_unix_socket) {
32 }
else if (sa->sa_family == AF_UNIX) {
33 struct sockaddr_un* un = ((
struct sockaddr_un*)sa);
34 memmove(as_string_, un->sun_path,
sizeof(un->sun_path));
36 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
38 as_string_, INET6_ADDRSTRLEN)) {
43 GetAddrLength(*
reinterpret_cast<RawAddr*
>(sa), unnamed_unix_socket);
44 memmove(
reinterpret_cast<void*
>(&addr_), sa, salen);
57 nullptr, 0, NI_NUMERICHOST)) == 0);
61 return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL ||
62 error_number == EINVAL;
75 ASSERT(EAGAIN == EWOULDBLOCK);
76 if ((sync ==
kAsync) && (read_bytes == -1) && (errno == EWOULDBLOCK)) {
90 socklen_t addr_len =
sizeof(
addr->ss);
92 recvfrom(fd,
buffer, num_bytes, 0, &
addr->addr, &addr_len));
93 if ((sync ==
kAsync) && (read_bytes == -1) && (errno == EWOULDBLOCK)) {
102 return level_ == SOL_SOCKET && type_ == SCM_RIGHTS;
109const size_t kMaxSocketMessageControlLength = 2048;
113 int64_t* p_buffer_num_bytes,
114 SocketControlMessage** p_messages,
116 OSError* p_oserror) {
118 ASSERT(p_messages !=
nullptr);
119 ASSERT(p_buffer_num_bytes !=
nullptr);
122 memset(iov, 0,
sizeof(iov));
124 iov[0].iov_len = *p_buffer_num_bytes;
127 memset(&msg, 0,
sizeof(msg));
130 uint8_t control_buffer[kMaxSocketMessageControlLength];
131 msg.msg_control = control_buffer;
132 msg.msg_controllen =
sizeof(control_buffer);
135#ifdef MSG_CMSG_CLOEXEC
137 flags &= MSG_CMSG_CLOEXEC;
140 if ((sync ==
kAsync) && (read_bytes == -1) && (errno == EWOULDBLOCK)) {
145 if (read_bytes < 0) {
149 *p_buffer_num_bytes = read_bytes;
151 struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
152 size_t num_messages = 0;
153 while (cmsg !=
nullptr) {
155 cmsg = CMSG_NXTHDR(&msg, cmsg);
157 (*p_messages) =
reinterpret_cast<SocketControlMessage*
>(
159 SocketControlMessage* control_message = *p_messages;
160 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg !=
nullptr;
161 cmsg = CMSG_NXTHDR(&msg, cmsg), control_message++) {
162 void*
data = CMSG_DATA(cmsg);
163 size_t data_length = cmsg->cmsg_len - (
reinterpret_cast<uint8_t*
>(
data) -
164 reinterpret_cast<uint8_t*
>(cmsg));
166 ASSERT(copied_data !=
nullptr);
167 memmove(copied_data,
data, data_length);
168 ASSERT(cmsg->cmsg_level == SOL_SOCKET);
169 ASSERT(cmsg->cmsg_type == SCM_RIGHTS);
170 new (control_message) SocketControlMessage(
171 cmsg->cmsg_level, cmsg->cmsg_type, copied_data, data_length);
174 memmove(&fd, CMSG_DATA(cmsg),
sizeof(
int));
176#ifndef MSG_CMSG_CLOEXEC
189 intptr_t num_bytes) {
192 recvfrom(fd,
buffer, num_bytes, MSG_PEEK,
nullptr,
nullptr));
193 return read_bytes >= 0;
196intptr_t SocketBase::WriteImpl(intptr_t fd,
209 ssize_t written_bytes =
212 ASSERT(EAGAIN == EWOULDBLOCK);
213 if ((sync ==
kAsync) && (written_bytes == -1) && (errno == EWOULDBLOCK)) {
218 return written_bytes;
224 SocketControlMessage* messages,
225 intptr_t num_messages,
227 OSError* p_oserror) {
232 .iov_len = num_bytes,
236 memset(&msg, 0,
sizeof(msg));
240 if (messages !=
nullptr && num_messages > 0) {
241 SocketControlMessage*
message = messages;
242 size_t total_length = 0;
243 for (intptr_t
i = 0;
i < num_messages;
i++,
message++) {
244 total_length += CMSG_SPACE(
message->data_length());
247 uint8_t* control_buffer =
249 memset(control_buffer, 0, total_length);
250 msg.msg_control = control_buffer;
251 msg.msg_controllen = total_length;
253 struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
255 for (intptr_t
i = 0;
i < num_messages;
256 i++,
message++, cmsg = CMSG_NXTHDR(&msg, cmsg)) {
258 cmsg->cmsg_level = SOL_SOCKET;
259 cmsg->cmsg_type = SCM_RIGHTS;
261 intptr_t data_length =
message->data_length();
262 cmsg->cmsg_len = CMSG_LEN(data_length);
263 memmove(CMSG_DATA(cmsg),
message->data(), data_length);
265 msg.msg_controllen = total_length;
269 ASSERT(EAGAIN == EWOULDBLOCK);
270 if ((sync ==
kAsync) && (written_bytes == -1) && (errno == EWOULDBLOCK)) {
275 if (written_bytes < 0) {
279 return written_bytes;
286 socklen_t
size =
sizeof(raw);
294 new (p_sa) SocketAddress(&raw.addr,
295 size ==
sizeof(sa_family_t));
302 socklen_t
size =
sizeof(raw);
312 socklen_t
size =
sizeof(raw);
319 if (
size ==
sizeof(sa_family_t)) {
321 return new SocketAddress(&raw.addr,
true);
324 return new SocketAddress(&raw.addr);
334 OSError** os_error) {
335 ASSERT(host_len >= NI_MAXHOST);
338 host_len,
nullptr, 0, NI_NAMEREQD));
340 ASSERT(*os_error ==
nullptr);
360static bool ShouldIncludeIfaAddrs(
struct ifaddrs* ifa,
int lookup_family) {
361 if (ifa->ifa_addr ==
nullptr) {
365 int family = ifa->ifa_addr->sa_family;
366 return ((lookup_family == family) ||
367 ((lookup_family == AF_UNSPEC) &&
368 ((family == AF_INET) || (family == AF_INET6))));
373 OSError** os_error) {
374 struct ifaddrs* ifaddr;
378 ASSERT(*os_error ==
nullptr);
387 for (
struct ifaddrs* ifa = ifaddr; ifa !=
nullptr; ifa = ifa->ifa_next) {
388 if (ShouldIncludeIfaAddrs(ifa, lookup_family)) {
393 AddressList<InterfaceSocketAddress>* addresses =
394 new AddressList<InterfaceSocketAddress>(
count);
396 for (
struct ifaddrs* ifa = ifaddr; ifa !=
nullptr; ifa = ifa->ifa_next) {
397 if (ShouldIncludeIfaAddrs(ifa, lookup_family)) {
400 i,
new InterfaceSocketAddress(ifa->ifa_addr, ifa_name,
401 if_nametoindex(ifa->ifa_name)));
415 if (
addr->addr.sa_family == AF_INET) {
416 return inet_ntop(AF_INET, &
addr->in.sin_addr, str, INET_ADDRSTRLEN) !=
420 return inet_ntop(AF_INET6, &
addr->in6.sin6_addr, str, INET6_ADDRSTRLEN) !=
427 socklen_t
len =
sizeof(on);
429 reinterpret_cast<void*
>(&on), &
len));
431 *enabled = (on == 1);
437 int on = enabled ? 1 : 0;
439 reinterpret_cast<char*
>(&on),
447 socklen_t
len =
sizeof(on);
450 : IPV6_MULTICAST_LOOP;
452 reinterpret_cast<char*
>(&on), &
len)) == 0) {
453 *enabled = (on == 1);
461 socklen_t
len =
sizeof(v);
464 : IPV6_MULTICAST_HOPS;
466 reinterpret_cast<char*
>(&v), &
len)) == 0) {
477 : IPV6_MULTICAST_HOPS;
479 fd,
level, optname,
reinterpret_cast<char*
>(&v),
sizeof(v))) == 0;
484 socklen_t
len =
sizeof(on);
486 reinterpret_cast<char*
>(&on), &
len));
488 *enabled = (on == 1);
494 int on = enabled ? 1 : 0;
496 reinterpret_cast<char*
>(&on),
static bool read(SkStream *stream, void *buffer, size_t amount)
static char * ScopedCopyCString(const char *str)
static intptr_t AvailableBytes(intptr_t fd)
static bool SetCloseOnExec(intptr_t fd)
static void SaveErrorAndClose(intptr_t fd)
static int16_t FromType(int type)
static intptr_t GetAddrLength(const RawAddr &addr, bool unnamed_unix_socket=false)
SocketAddress(struct sockaddr *sa, bool unnamed_unix_socket=false)
static intptr_t GetAddrPort(const RawAddr &addr)
static bool AvailableDatagram(intptr_t fd, void *buffer, intptr_t num_bytes)
static bool SetMulticastHops(intptr_t fd, intptr_t protocol, int value)
static intptr_t GetStdioHandle(intptr_t num)
static intptr_t ReceiveMessage(intptr_t fd, void *buffer, int64_t *p_buffer_num_bytes, SocketControlMessage **p_messages, SocketOpKind sync, OSError *p_oserror)
static bool SetOption(intptr_t fd, int level, int option, const char *data, int length)
static SocketAddress * GetRemotePeer(intptr_t fd, intptr_t *port)
static bool FormatNumericAddress(const RawAddr &addr, char *address, int len)
static bool SetNoDelay(intptr_t fd, bool enabled)
static bool GetSocketName(intptr_t fd, SocketAddress *p_sa)
static bool ParseAddress(int type, const char *address, RawAddr *addr)
static intptr_t Available(intptr_t fd)
static void Close(intptr_t fd)
static intptr_t RecvFrom(intptr_t fd, void *buffer, intptr_t num_bytes, RawAddr *addr, SocketOpKind sync)
static bool IsBindError(intptr_t error_number)
static intptr_t Read(intptr_t fd, void *buffer, intptr_t num_bytes, SocketOpKind sync)
static bool SetBroadcast(intptr_t fd, bool value)
static bool GetNoDelay(intptr_t fd, bool *enabled)
static bool ReverseLookup(const RawAddr &addr, char *host, intptr_t host_len, OSError **os_error)
static bool RawAddrToString(RawAddr *addr, char *str)
static intptr_t SendTo(intptr_t fd, const void *buffer, intptr_t num_bytes, const RawAddr &addr, SocketOpKind sync)
static bool GetMulticastHops(intptr_t fd, intptr_t protocol, int *value)
static bool GetMulticastLoop(intptr_t fd, intptr_t protocol, bool *enabled)
static intptr_t SendMessage(intptr_t fd, void *buffer, size_t buffer_num_bytes, SocketControlMessage *messages, intptr_t num_messages, SocketOpKind sync, OSError *p_oserror)
static AddressList< InterfaceSocketAddress > * ListInterfaces(int type, OSError **os_error)
static bool GetBroadcast(intptr_t fd, bool *value)
static intptr_t GetPort(intptr_t fd)
bool is_file_descriptors_control_message()
FlutterSemanticsFlag flags
DART_EXPORT uint8_t * Dart_ScopeAllocate(intptr_t size)
static int8_t data[kExtLength]
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service port
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service host
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
#define NO_RETRY_EXPECTED(expression)
#define TEMP_FAILURE_RETRY(expression)
void write(SkWStream *wStream, const T &text)