Flutter Engine
The Flutter Engine
sync_socket_win.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_WINDOWS)
7
8#include "bin/socket_base.h"
9#include "bin/sync_socket.h"
10
11namespace dart {
12namespace bin {
13
16}
17
18static intptr_t Create(const RawAddr& addr) {
19 const intptr_t type = SOCK_STREAM;
20 SOCKET s = WSASocket(addr.ss.ss_family, type, 0, nullptr, 0, 0);
21 return (s == INVALID_SOCKET) ? -1 : s;
22}
23
24static intptr_t Connect(intptr_t fd, const RawAddr& addr) {
25 SOCKET socket = static_cast<SOCKET>(fd);
26 intptr_t result =
27 connect(socket, &addr.addr, SocketAddress::GetAddrLength(addr));
28 return (result == SOCKET_ERROR) ? -1 : socket;
29}
30
31intptr_t SynchronousSocket::CreateConnect(const RawAddr& addr) {
32 intptr_t fd = Create(addr);
33 return (fd < 0) ? fd : Connect(fd, addr);
34}
35
36intptr_t SynchronousSocket::Available(intptr_t fd) {
37 SOCKET socket = static_cast<SOCKET>(fd);
38 DWORD available;
39 intptr_t result = ioctlsocket(socket, FIONREAD, &available);
40 return (result == SOCKET_ERROR) ? -1 : static_cast<intptr_t>(available);
41}
42
43intptr_t SynchronousSocket::GetPort(intptr_t fd) {
44 SOCKET socket = static_cast<SOCKET>(fd);
45 RawAddr raw;
46 socklen_t size = sizeof(raw);
47 if (getsockname(socket, &raw.addr, &size) == SOCKET_ERROR) {
48 return 0;
49 }
51}
52
53SocketAddress* SynchronousSocket::GetRemotePeer(intptr_t fd, intptr_t* port) {
54 SOCKET socket = static_cast<SOCKET>(fd);
55 RawAddr raw;
56 socklen_t size = sizeof(raw);
57 if (getpeername(socket, &raw.addr, &size)) {
58 return nullptr;
59 }
61 // Clear the port before calling WSAAddressToString as WSAAddressToString
62 // includes the port in the formatted string.
64 return new SocketAddress(&raw.addr);
65}
66
67intptr_t SynchronousSocket::Read(intptr_t fd,
68 void* buffer,
69 intptr_t num_bytes) {
70 SOCKET socket = static_cast<SOCKET>(fd);
71 return recv(socket, reinterpret_cast<char*>(buffer), num_bytes, 0);
72}
73
74intptr_t SynchronousSocket::Write(intptr_t fd,
75 const void* buffer,
76 intptr_t num_bytes) {
77 SOCKET socket = static_cast<SOCKET>(fd);
78 return send(socket, reinterpret_cast<const char*>(buffer), num_bytes, 0);
79}
80
81void SynchronousSocket::ShutdownRead(intptr_t fd) {
82 SOCKET socket = static_cast<SOCKET>(fd);
83 shutdown(socket, SD_RECEIVE);
84}
85
86void SynchronousSocket::ShutdownWrite(intptr_t fd) {
87 SOCKET socket = static_cast<SOCKET>(fd);
88 shutdown(socket, SD_SEND);
89}
90
91void SynchronousSocket::Close(intptr_t fd) {
92 SOCKET socket = static_cast<SOCKET>(fd);
93 closesocket(socket);
94}
95
96} // namespace bin
97} // namespace dart
98
99#endif // defined(DART_HOST_OS_WINDOWS)
static sk_sp< Effect > Create()
Definition: RefCntTest.cpp:117
GLenum type
static void SetAddrPort(RawAddr *addr, intptr_t port)
Definition: socket_base.cc:177
static intptr_t GetAddrLength(const RawAddr &addr, bool unnamed_unix_socket=false)
Definition: socket_base.cc:39
static intptr_t GetAddrPort(const RawAddr &addr)
Definition: socket_base.cc:187
static bool Initialize()
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)
struct MyStruct s
GAsyncResult * result
Definition: dart_vm.cc:33
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
Definition: switches.h:87
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
Definition: switches.h:126
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
Definition: switches.h:259
unsigned long DWORD
Definition: windows_types.h:22