Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
dart::bin::Socket Class Reference

#include <socket.h>

Inheritance diagram for dart::bin::Socket:
dart::bin::ReferenceCounted< Socket >

Public Types

enum  SocketRequest { kLookupRequest = 0 , kListInterfacesRequest = 1 , kReverseLookupRequest = 2 }
 
enum  SocketFinalizer { kFinalizerNormal , kFinalizerListening , kFinalizerStdio , kFinalizerSignal }
 
enum  SocketType { kTcpSocket = 18 , kUdpSocket = 19 , kInternalSocket = 20 , kInternalSignalSocket = 21 }
 

Public Member Functions

 Socket (intptr_t fd)
 
intptr_t fd () const
 
void CloseFd ()
 
void SetClosedFd ()
 
Dart_Port isolate_port () const
 
Dart_Port port () const
 
void set_port (Dart_Port port)
 
uint8_t * udp_receive_buffer () const
 
void set_udp_receive_buffer (uint8_t *buffer)
 
- Public Member Functions inherited from dart::bin::ReferenceCounted< Socket >
 ReferenceCounted ()
 
virtual ~ReferenceCounted ()
 
void Retain ()
 
void Release ()
 

Static Public Member Functions

static bool Initialize ()
 
static intptr_t CreateConnect (const RawAddr &addr)
 
static intptr_t CreateUnixDomainConnect (const RawAddr &addr)
 
static intptr_t CreateBindConnect (const RawAddr &addr, const RawAddr &source_addr)
 
static intptr_t CreateUnixDomainBindConnect (const RawAddr &addr, const RawAddr &source_addr)
 
static intptr_t CreateBindDatagram (const RawAddr &addr, bool reuseAddress, bool reusePort, int ttl=1)
 
static CObjectLookupRequest (const CObjectArray &request)
 
static CObjectListInterfacesRequest (const CObjectArray &request)
 
static CObjectReverseLookupRequest (const CObjectArray &request)
 
static Dart_Port GetServicePort ()
 
static void SetSocketIdNativeField (Dart_Handle handle, intptr_t id, SocketFinalizer finalizer)
 
static void ReuseSocketIdNativeField (Dart_Handle handle, Socket *socket, SocketFinalizer finalizer)
 
static SocketGetSocketIdNativeField (Dart_Handle socket)
 
static bool short_socket_read ()
 
static void set_short_socket_read (bool short_socket_read)
 
static bool short_socket_write ()
 
static void set_short_socket_write (bool short_socket_write)
 
static bool IsSignalSocketFlag (intptr_t flag)
 

Friends

class ReferenceCounted< Socket >
 

Detailed Description

Definition at line 27 of file socket.h.

Member Enumeration Documentation

◆ SocketFinalizer

Enumerator
kFinalizerNormal 
kFinalizerListening 
kFinalizerStdio 
kFinalizerSignal 

Definition at line 35 of file socket.h.

◆ SocketRequest

Enumerator
kLookupRequest 
kListInterfacesRequest 
kReverseLookupRequest 

Definition at line 29 of file socket.h.

29 {
33 };
@ kReverseLookupRequest
Definition: socket.h:32
@ kListInterfacesRequest
Definition: socket.h:31

◆ SocketType

Enumerator
kTcpSocket 
kUdpSocket 
kInternalSocket 
kInternalSignalSocket 

Definition at line 43 of file socket.h.

43 {
44 kTcpSocket = 18,
45 kUdpSocket = 19,
46 kInternalSocket = 20,
48 };
@ kInternalSignalSocket
Definition: socket.h:47

Constructor & Destructor Documentation

◆ Socket()

dart::bin::Socket::Socket ( intptr_t  fd)
explicit

Member Function Documentation

◆ CloseFd()

void dart::bin::Socket::CloseFd ( )

◆ CreateBindConnect()

static intptr_t dart::bin::Socket::CreateBindConnect ( const RawAddr addr,
const RawAddr source_addr 
)
static

◆ CreateBindDatagram()

static intptr_t dart::bin::Socket::CreateBindDatagram ( const RawAddr addr,
bool  reuseAddress,
bool  reusePort,
int  ttl = 1 
)
static

◆ CreateConnect()

static intptr_t dart::bin::Socket::CreateConnect ( const RawAddr addr)
static

◆ CreateUnixDomainBindConnect()

static intptr_t dart::bin::Socket::CreateUnixDomainBindConnect ( const RawAddr addr,
const RawAddr source_addr 
)
static

◆ CreateUnixDomainConnect()

static intptr_t dart::bin::Socket::CreateUnixDomainConnect ( const RawAddr addr)
static

◆ fd()

intptr_t dart::bin::Socket::fd ( ) const
inline

Definition at line 52 of file socket.h.

52{ return fd_; }

◆ GetServicePort()

static Dart_Port dart::bin::Socket::GetServicePort ( )
static

◆ GetSocketIdNativeField()

Socket * dart::bin::Socket::GetSocketIdNativeField ( Dart_Handle  socket)
static

Definition at line 1496 of file socket.cc.

1496 {
1497 intptr_t id;
1498 Dart_Handle err =
1500 if (Dart_IsError(err)) {
1502 }
1503 Socket* socket = reinterpret_cast<Socket*>(id);
1504 if (socket == nullptr) {
1506 DartUtils::NewInternalError("No native peer")));
1507 }
1508 return socket;
1509}
static Dart_Handle NewInternalError(const char *message)
Definition: dartutils.cc:781
Socket(intptr_t fd)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
static constexpr int kSocketIdNativeField
Definition: socket.cc:26
DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, int index, intptr_t *value)
DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception)
DART_EXPORT void Dart_PropagateError(Dart_Handle handle)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
const uintptr_t id

◆ Initialize()

static bool dart::bin::Socket::Initialize ( )
static

◆ isolate_port()

Dart_Port dart::bin::Socket::isolate_port ( ) const
inline

Definition at line 61 of file socket.h.

61{ return isolate_port_; }

◆ IsSignalSocketFlag()

static bool dart::bin::Socket::IsSignalSocketFlag ( intptr_t  flag)
inlinestatic

Definition at line 111 of file socket.h.

111 {
112 return ((flag & (0x1 << kInternalSignalSocket)) != 0);
113 }
FlutterSemanticsFlag flag

◆ ListInterfacesRequest()

CObject * dart::bin::Socket::ListInterfacesRequest ( const CObjectArray request)
static

Definition at line 1134 of file socket.cc.

1134 {
1135 if ((request.Length() == 1) && request[0]->IsInt32()) {
1136 CObjectInt32 type(request[0]);
1137 CObject* result = nullptr;
1138 OSError* os_error = nullptr;
1139 AddressList<InterfaceSocketAddress>* addresses =
1140 SocketBase::ListInterfaces(type.Value(), &os_error);
1141 if (addresses != nullptr) {
1142 CObjectArray* array =
1143 new CObjectArray(CObject::NewArray(addresses->count() + 1));
1144 array->SetAt(0, new CObjectInt32(CObject::NewInt32(0)));
1145 for (intptr_t i = 0; i < addresses->count(); i++) {
1146 InterfaceSocketAddress* interface = addresses->GetAt(i);
1147 SocketAddress* addr = interface->socket_address();
1148 CObjectArray* entry = new CObjectArray(CObject::NewArray(5));
1149
1150 CObjectInt32* type =
1151 new CObjectInt32(CObject::NewInt32(addr->GetType()));
1152 entry->SetAt(0, type);
1153
1154 CObjectString* as_string =
1155 new CObjectString(CObject::NewString(addr->as_string()));
1156 entry->SetAt(1, as_string);
1157
1158 RawAddr raw = addr->addr();
1159 CObjectUint8Array* data = SocketAddress::ToCObject(raw);
1160 entry->SetAt(2, data);
1161
1162 CObjectString* interface_name =
1163 new CObjectString(CObject::NewString(interface->interface_name()));
1164 entry->SetAt(3, interface_name);
1165
1166 CObjectInt64* interface_index =
1167 new CObjectInt64(CObject::NewInt64(interface->interface_index()));
1168 entry->SetAt(4, interface_index);
1169
1170 array->SetAt(i + 1, entry);
1171 }
1172 result = array;
1173 delete addresses;
1174 } else {
1175 result = CObject::NewOSError(os_error);
1176 delete os_error;
1177 }
1178 return result;
1179 }
1181}
GLenum type
static Dart_CObject * NewString(const char *str)
Definition: dartutils.cc:927
static CObject * IllegalArgumentError()
Definition: dartutils.cc:1026
static Dart_CObject * NewArray(intptr_t length)
Definition: dartutils.cc:936
static Dart_CObject * NewInt32(int32_t value)
Definition: dartutils.cc:902
static Dart_CObject * NewInt64(int64_t value)
Definition: dartutils.cc:908
static CObject * NewOSError()
Definition: dartutils.cc:1038
static CObjectUint8Array * ToCObject(const RawAddr &addr)
Definition: socket_base.cc:220
static AddressList< InterfaceSocketAddress > * ListInterfaces(int type, OSError **os_error)
GAsyncResult * result
static int8_t data[kExtLength]

◆ LookupRequest()

CObject * dart::bin::Socket::LookupRequest ( const CObjectArray request)
static

Definition at line 1057 of file socket.cc.

1057 {
1058 if ((request.Length() == 2) && request[0]->IsString() &&
1059 request[1]->IsInt32()) {
1060 CObjectString host(request[0]);
1061 CObjectInt32 type(request[1]);
1062 CObject* result = nullptr;
1063 OSError* os_error = nullptr;
1064 AddressList<SocketAddress>* addresses =
1065 SocketBase::LookupAddress(host.CString(), type.Value(), &os_error);
1066 if (addresses != nullptr) {
1067 CObjectArray* array =
1068 new CObjectArray(CObject::NewArray(addresses->count() + 1));
1069 array->SetAt(0, new CObjectInt32(CObject::NewInt32(0)));
1070 for (intptr_t i = 0; i < addresses->count(); i++) {
1071 SocketAddress* addr = addresses->GetAt(i);
1072 CObjectArray* entry = new CObjectArray(CObject::NewArray(4));
1073
1074 CObjectInt32* type =
1075 new CObjectInt32(CObject::NewInt32(addr->GetType()));
1076 entry->SetAt(0, type);
1077
1078 CObjectString* as_string =
1079 new CObjectString(CObject::NewString(addr->as_string()));
1080 entry->SetAt(1, as_string);
1081
1082 RawAddr raw = addr->addr();
1083 CObjectUint8Array* data = SocketAddress::ToCObject(raw);
1084 entry->SetAt(2, data);
1085
1086 CObjectInt64* scope_id = new CObjectInt64(
1088 entry->SetAt(3, scope_id);
1089
1090 array->SetAt(i + 1, entry);
1091 }
1092 result = array;
1093 delete addresses;
1094 } else {
1095 result = CObject::NewOSError(os_error);
1096 delete os_error;
1097 }
1098 return result;
1099 }
1101}
static intptr_t GetAddrScope(const RawAddr &addr)
Definition: socket_base.cc:237
static AddressList< SocketAddress > * LookupAddress(const char *host, int type, OSError **os_error)
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
Definition: switches.h:74

◆ port()

Dart_Port dart::bin::Socket::port ( ) const
inline

Definition at line 63 of file socket.h.

63{ return port_; }

◆ ReuseSocketIdNativeField()

void dart::bin::Socket::ReuseSocketIdNativeField ( Dart_Handle  handle,
Socket socket,
SocketFinalizer  finalizer 
)
static

Definition at line 1456 of file socket.cc.

1458 {
1460 handle, kSocketIdNativeField, reinterpret_cast<intptr_t>(socket));
1461 if (Dart_IsError(err)) {
1463 }
1465 switch (finalizer) {
1466 case kFinalizerNormal:
1468 break;
1471 break;
1472 case kFinalizerStdio:
1474 break;
1475 case kFinalizerSignal:
1477 break;
1478 default:
1479 callback = nullptr;
1480 UNREACHABLE();
1481 break;
1482 }
1483 if (callback != nullptr) {
1484 Dart_NewFinalizableHandle(handle, reinterpret_cast<void*>(socket),
1485 sizeof(Socket), callback);
1486 }
1487}
#define UNREACHABLE()
Definition: assert.h:248
void(* Dart_HandleFinalizer)(void *isolate_callback_data, void *peer)
Definition: dart_api.h:265
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static void StdioSocketFinalizer(void *isolate_data, void *data)
Definition: socket.cc:1439
static void SignalSocketFinalizer(void *isolate_data, void *data)
Definition: socket.cc:1447
static void NormalSocketFinalizer(void *isolate_data, void *data)
Definition: socket.cc:1421
static void ListeningSocketFinalizer(void *isolate_data, void *data)
Definition: socket.cc:1430
DART_EXPORT Dart_FinalizableHandle Dart_NewFinalizableHandle(Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, int index, intptr_t value)

◆ ReverseLookupRequest()

CObject * dart::bin::Socket::ReverseLookupRequest ( const CObjectArray request)
static

Definition at line 1103 of file socket.cc.

1103 {
1104 if ((request.Length() == 1) && request[0]->IsTypedData()) {
1105 CObjectUint8Array addr_object(request[0]);
1106 RawAddr addr;
1107 int len = addr_object.Length();
1108 memset(reinterpret_cast<void*>(&addr), 0, sizeof(RawAddr));
1109 if (len == sizeof(in_addr)) {
1110 addr.in.sin_family = AF_INET;
1111 memmove(reinterpret_cast<void*>(&addr.in.sin_addr), addr_object.Buffer(),
1112 len);
1113 } else {
1114 ASSERT(len == sizeof(in6_addr));
1115 addr.in6.sin6_family = AF_INET6;
1116 memmove(reinterpret_cast<void*>(&addr.in6.sin6_addr),
1117 addr_object.Buffer(), len);
1118 }
1119
1120 OSError* os_error = nullptr;
1121 const intptr_t kMaxHostLength = 1025;
1122 char host[kMaxHostLength];
1123 if (SocketBase::ReverseLookup(addr, host, kMaxHostLength, &os_error)) {
1124 return new CObjectString(CObject::NewString(host));
1125 } else {
1126 CObject* result = CObject::NewOSError(os_error);
1127 delete os_error;
1128 return result;
1129 }
1130 }
1132}
static bool ReverseLookup(const RawAddr &addr, char *host, intptr_t host_len, OSError **os_error)
#define ASSERT(E)

◆ set_port()

void dart::bin::Socket::set_port ( Dart_Port  port)
inline

Definition at line 64 of file socket.h.

64{ port_ = port; }
Dart_Port port() const
Definition: socket.h:63

◆ set_short_socket_read()

static void dart::bin::Socket::set_short_socket_read ( bool  short_socket_read)
inlinestatic

Definition at line 103 of file socket.h.

103 {
104 short_socket_read_ = short_socket_read;
105 }
static bool short_socket_read()
Definition: socket.h:102

◆ set_short_socket_write()

static void dart::bin::Socket::set_short_socket_write ( bool  short_socket_write)
inlinestatic

Definition at line 107 of file socket.h.

107 {
108 short_socket_write_ = short_socket_write;
109 }
static bool short_socket_write()
Definition: socket.h:106

◆ set_udp_receive_buffer()

void dart::bin::Socket::set_udp_receive_buffer ( uint8_t *  buffer)
inline

Definition at line 67 of file socket.h.

67{ udp_receive_buffer_ = buffer; }
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

◆ SetClosedFd()

void dart::bin::Socket::SetClosedFd ( )

◆ SetSocketIdNativeField()

void dart::bin::Socket::SetSocketIdNativeField ( Dart_Handle  handle,
intptr_t  id,
SocketFinalizer  finalizer 
)
static

Definition at line 1489 of file socket.cc.

1491 {
1492 Socket* socket = new Socket(id);
1493 ReuseSocketIdNativeField(handle, socket, finalizer);
1494}
static void ReuseSocketIdNativeField(Dart_Handle handle, Socket *socket, SocketFinalizer finalizer)
Definition: socket.cc:1456

◆ short_socket_read()

static bool dart::bin::Socket::short_socket_read ( )
inlinestatic

Definition at line 102 of file socket.h.

102{ return short_socket_read_; }

◆ short_socket_write()

static bool dart::bin::Socket::short_socket_write ( )
inlinestatic

Definition at line 106 of file socket.h.

106{ return short_socket_write_; }

◆ udp_receive_buffer()

uint8_t * dart::bin::Socket::udp_receive_buffer ( ) const
inline

Definition at line 66 of file socket.h.

66{ return udp_receive_buffer_; }

Friends And Related Function Documentation

◆ ReferenceCounted< Socket >

friend class ReferenceCounted< Socket >
friend

Definition at line 130 of file socket.h.


The documentation for this class was generated from the following files: