6#if defined(DART_HOST_OS_WINDOWS)
24 bool unnamed_unix_socket) {
26 ASSERT(!unnamed_unix_socket);
27 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
28 RawAddr* raw =
reinterpret_cast<RawAddr*
>(sockaddr);
38 memmove(
reinterpret_cast<void*
>(&addr_), sockaddr,
42static Mutex* init_mutex =
new Mutex();
43static bool socket_initialized =
false;
46 MutexLocker lock(init_mutex);
47 if (socket_initialized) {
52 WORD version_requested = MAKEWORD(2, 2);
53 err = WSAStartup(version_requested, &winsock_data);
55 socket_initialized =
true;
67 RawAddr& raw =
const_cast<RawAddr&
>(
addr);
68 wchar_t* waddress =
reinterpret_cast<wchar_t*
>(
71 WSAAddressToStringW(&raw.addr, salen,
nullptr, waddress, &l);
75 WideToUtf8Scope wide_name(waddress);
76 strncpy(address, wide_name.utf8(), l);
81 ClientSocket* client_socket =
reinterpret_cast<ClientSocket*
>(fd);
82 return client_socket->Available();
89 Handle* handle =
reinterpret_cast<Handle*
>(fd);
90 return handle->Read(
buffer, num_bytes);
98 Handle* handle =
reinterpret_cast<Handle*
>(fd);
99 socklen_t addr_len =
sizeof(
addr->ss);
100 return handle->RecvFrom(
buffer, num_bytes, &
addr->addr, addr_len);
109 int64_t* p_buffer_num_bytes,
110 SocketControlMessage** p_messages,
112 OSError* p_oserror) {
119 intptr_t num_bytes) {
120 ClientSocket* client_socket =
reinterpret_cast<ClientSocket*
>(fd);
121 return client_socket->DataReady();
124bool SocketBase::HasPendingWrite(intptr_t fd) {
125 Handle* handle =
reinterpret_cast<Handle*
>(fd);
126 return handle->HasPendingWrite();
133 Handle* handle =
reinterpret_cast<Handle*
>(fd);
134 return handle->Write(
buffer, num_bytes);
142 Handle* handle =
reinterpret_cast<Handle*
>(fd);
143 RawAddr& raw =
const_cast<RawAddr&
>(
addr);
144 return handle->SendTo(
buffer, num_bytes, &raw.addr,
151 SocketControlMessage* messages,
152 intptr_t num_messages,
154 OSError* p_oserror) {
163 socklen_t
size =
sizeof(raw);
164 if (getsockname(fd, &raw.addr, &
size) == SOCKET_ERROR) {
171 new (p_sa) SocketAddress(&raw.addr,
172 size ==
sizeof(u_short));
177 ASSERT(
reinterpret_cast<Handle*
>(fd)->is_socket());
178 SocketHandle* socket_handle =
reinterpret_cast<SocketHandle*
>(fd);
180 socklen_t
size =
sizeof(raw);
181 if (getsockname(socket_handle->socket(), &raw.addr, &
size) == SOCKET_ERROR) {
188 ASSERT(
reinterpret_cast<Handle*
>(fd)->is_socket());
189 SocketHandle* socket_handle =
reinterpret_cast<SocketHandle*
>(fd);
191 if (socket_handle->is_client_socket() &&
192 reinterpret_cast<ClientSocket*
>(fd)->PopulateRemoteAddr(raw)) {
195 socklen_t
size =
sizeof(raw);
196 if (getpeername(socket_handle->socket(), &raw.addr, &
size)) {
204 return new SocketAddress(&raw.addr);
208 return error_number == WSAEADDRINUSE || error_number == WSAEADDRNOTAVAIL ||
209 error_number == WSAEINVAL;
213 Handle* handle =
reinterpret_cast<Handle*
>(fd);
218 Handle* handle =
reinterpret_cast<Handle*
>(fd);
219 switch (GetFileType(handle->handle())) {
235 HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
240 std_handle->Retain();
241 std_handle->MarkDoesNotSupportOverlappedIO();
243 return reinterpret_cast<intptr_t
>(std_handle);
248 OSError** os_error) {
252 struct addrinfo hints;
253 memset(&hints, 0,
sizeof(hints));
255 hints.ai_socktype = SOCK_STREAM;
256 hints.ai_flags = AI_ADDRCONFIG;
257 hints.ai_protocol = IPPROTO_TCP;
258 struct addrinfo*
info =
nullptr;
259 int status = getaddrinfo(
host, 0, &hints, &
info);
264 status = getaddrinfo(
host, 0, &hints, &
info);
267 ASSERT(*os_error ==
nullptr);
268 DWORD error_code = WSAGetLastError();
270 *os_error =
new OSError();
274 for (
struct addrinfo* c =
info; c !=
nullptr; c = c->ai_next) {
275 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
279 AddressList<SocketAddress>* addresses =
new AddressList<SocketAddress>(
count);
281 for (
struct addrinfo* c =
info; c !=
nullptr; c = c->ai_next) {
282 if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
283 addresses->SetAt(
i,
new SocketAddress(c->ai_addr));
294 OSError** os_error) {
295 ASSERT(host_len >= NI_MAXHOST);
297 host_len,
nullptr, 0, NI_NAMEREQD);
299 ASSERT(*os_error ==
nullptr);
300 DWORD error_code = WSAGetLastError();
302 *os_error =
new OSError();
312 result = InetPton(AF_INET, system_address.get(), &
addr->in.sin_addr);
315 result = InetPton(AF_INET6, system_address.get(), &
addr->in6.sin6_addr);
324 wchar_t tmp_buffer[INET6_ADDRSTRLEN];
325 if (
addr->addr.sa_family == AF_INET) {
326 if (InetNtop(AF_INET, &
addr->in.sin_addr, tmp_buffer, INET_ADDRSTRLEN) ==
332 if (InetNtop(AF_INET6, &
addr->in6.sin6_addr, tmp_buffer,
333 INET6_ADDRSTRLEN) ==
nullptr) {
337 WideToUtf8Scope wide_to_utf8_scope(tmp_buffer);
338 if (wide_to_utf8_scope.length() <= INET6_ADDRSTRLEN) {
339 strncpy(str, wide_to_utf8_scope.utf8(), INET6_ADDRSTRLEN);
347 OSError** os_error) {
351 DWORD flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
352 GAA_FLAG_SKIP_DNS_SERVER;
355 nullptr,
nullptr, &
size);
356 IP_ADAPTER_ADDRESSES* addrs =
nullptr;
357 if (status == ERROR_BUFFER_OVERFLOW) {
358 addrs =
reinterpret_cast<IP_ADAPTER_ADDRESSES*
>(
malloc(
size));
363 if (status != NO_ERROR) {
364 ASSERT(*os_error ==
nullptr);
365 DWORD error_code = WSAGetLastError();
367 *os_error =
new OSError();
371 for (IP_ADAPTER_ADDRESSES*
a = addrs;
a !=
nullptr;
a =
a->Next) {
372 for (IP_ADAPTER_UNICAST_ADDRESS* u =
a->FirstUnicastAddress; u !=
nullptr;
377 AddressList<InterfaceSocketAddress>* addresses =
378 new AddressList<InterfaceSocketAddress>(
count);
380 for (IP_ADAPTER_ADDRESSES*
a = addrs;
a !=
nullptr;
a =
a->Next) {
381 for (IP_ADAPTER_UNICAST_ADDRESS* u =
a->FirstUnicastAddress; u !=
nullptr;
383 ASSERT(
type != AF_INET ||
a->Flags & IP_ADAPTER_IPV4_ENABLED);
384 ASSERT(
type != AF_INET6 ||
a->Flags & IP_ADAPTER_IPV6_ENABLED);
385 ASSERT(
a->IfIndex ==
a->Ipv6IfIndex ||
386 !(
a->Flags & IP_ADAPTER_IPV4_ENABLED) ||
387 !(
a->Flags & IP_ADAPTER_IPV6_ENABLED));
389 new InterfaceSocketAddress(
390 u->Address.lpSockaddr,
392 a->Ipv6IfIndex != 0 ?
a->Ipv6IfIndex :
a->IfIndex));
401 ClientSocket* client_socket =
reinterpret_cast<ClientSocket*
>(fd);
402 client_socket->Close();
406 SocketHandle* handle =
reinterpret_cast<SocketHandle*
>(fd);
408 socklen_t
len =
sizeof(on);
409 int err = getsockopt(handle->socket(), IPPROTO_TCP, TCP_NODELAY,
410 reinterpret_cast<char*
>(&on), &
len);
412 *enabled = (on == 1);
418 SocketHandle* handle =
reinterpret_cast<SocketHandle*
>(fd);
419 int on = enabled ? 1 : 0;
420 return setsockopt(handle->socket(), IPPROTO_TCP, TCP_NODELAY,
421 reinterpret_cast<char*
>(&on),
sizeof(on)) == 0;
427 SocketHandle* handle =
reinterpret_cast<SocketHandle*
>(fd);
429 socklen_t
len =
sizeof(on);
432 : IPV6_MULTICAST_LOOP;
433 if (getsockopt(handle->socket(),
level, optname,
reinterpret_cast<char*
>(&on),
435 *enabled = (on == 1);
444 SocketHandle* handle =
reinterpret_cast<SocketHandle*
>(fd);
445 int on = enabled ? 1 : 0;
448 : IPV6_MULTICAST_LOOP;
449 return setsockopt(handle->socket(),
level, optname,
450 reinterpret_cast<char*
>(&on),
sizeof(on)) == 0;
454 SocketHandle* handle =
reinterpret_cast<SocketHandle*
>(fd);
456 socklen_t
len =
sizeof(v);
459 : IPV6_MULTICAST_HOPS;
460 if (getsockopt(handle->socket(),
level, optname,
reinterpret_cast<char*
>(&v),
469 SocketHandle* handle =
reinterpret_cast<SocketHandle*
>(fd);
473 : IPV6_MULTICAST_HOPS;
474 return setsockopt(handle->socket(),
level, optname,
475 reinterpret_cast<char*
>(&v),
sizeof(v)) == 0;
479 SocketHandle* handle =
reinterpret_cast<SocketHandle*
>(fd);
481 socklen_t
len =
sizeof(on);
482 int err = getsockopt(handle->socket(), SOL_SOCKET, SO_BROADCAST,
483 reinterpret_cast<char*
>(&on), &
len);
485 *enabled = (on == 1);
491 SocketHandle* handle =
reinterpret_cast<SocketHandle*
>(fd);
492 int on = enabled ? 1 : 0;
493 return setsockopt(handle->socket(), SOL_SOCKET, SO_BROADCAST,
494 reinterpret_cast<char*
>(&on),
sizeof(on)) == 0;
502 SocketHandle* handle =
reinterpret_cast<SocketHandle*
>(fd);
511 SocketHandle* handle =
reinterpret_cast<SocketHandle*
>(fd);
512 int optlen =
static_cast<int>(*length);
513 auto result = getsockopt(handle->socket(),
level, option,
data, &optlen);
514 *
length =
static_cast<unsigned int>(optlen);
521 int interfaceIndex) {
522 SocketHandle* handle =
reinterpret_cast<SocketHandle*
>(fd);
523 int proto =
addr.addr.sa_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
524 struct group_req mreq;
525 mreq.gr_interface = interfaceIndex;
527 return setsockopt(handle->socket(), proto, MCAST_JOIN_GROUP,
528 reinterpret_cast<char*
>(&mreq),
sizeof(mreq)) == 0;
534 int interfaceIndex) {
535 SocketHandle* handle =
reinterpret_cast<SocketHandle*
>(fd);
536 int proto =
addr.addr.sa_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
537 struct group_req mreq;
538 mreq.gr_interface = interfaceIndex;
540 return setsockopt(handle->socket(), proto, MCAST_LEAVE_GROUP,
541 reinterpret_cast<char*
>(&mreq),
sizeof(mreq)) == 0;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static EventHandlerImplementation * delegate()
static int16_t FromType(int type)
static void SetAddrPort(RawAddr *addr, intptr_t port)
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 LeaveMulticast(intptr_t fd, const RawAddr &addr, const RawAddr &interface, int interfaceIndex)
static bool AvailableDatagram(intptr_t fd, void *buffer, intptr_t num_bytes)
static int GetType(intptr_t fd)
static AddressList< SocketAddress > * LookupAddress(const char *host, int type, OSError **os_error)
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 void GetError(intptr_t fd, OSError *os_error)
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 SetMulticastLoop(intptr_t fd, intptr_t protocol, bool enabled)
static bool GetOption(intptr_t fd, int level, int option, char *data, unsigned int *length)
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 bool JoinMulticast(intptr_t fd, const RawAddr &addr, const RawAddr &interface, int interfaceIndex)
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 Write(intptr_t fd, const void *buffer, intptr_t num_bytes, SocketOpKind sync)
static intptr_t GetPort(intptr_t fd)
bool is_file_descriptors_control_message()
static StdHandle * Stdin(HANDLE handle)
static char * WideToUtf8(wchar_t *wide, intptr_t len=-1, intptr_t *result_len=nullptr)
FlutterSemanticsFlag flags
std::unique_ptr< wchar_t[]> Utf8ToWideChar(const char *path)
void * malloc(size_t size)
DART_EXPORT uint8_t * Dart_ScopeAllocate(intptr_t size)
static int8_t data[kExtLength]
COMPILE_ASSERT(kUnreachableReference==WeakTable::kNoValue)
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 INVALID_HANDLE_VALUE
WINBASEAPI VOID WINAPI SetLastError(_In_ DWORD dwErrCode)
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)