6#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
25 udp_receive_buffer_(nullptr) {}
27void Socket::CloseFd() {
31void Socket::SetClosedFd() {
37 intptr_t
type = SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC;
45static intptr_t Connect(intptr_t fd,
const RawAddr&
addr) {
47 connect(fd, &
addr.addr, SocketAddress::GetAddrLength(
addr)));
48 if ((
result == 0) || (errno == EINPROGRESS)) {
51 FDUtils::SaveErrorAndClose(fd);
55intptr_t Socket::CreateConnect(
const RawAddr&
addr) {
60 return Connect(fd,
addr);
63intptr_t Socket::CreateUnixDomainConnect(
const RawAddr&
addr) {
69 fd, (
struct sockaddr*)&
addr.un, SocketAddress::GetAddrLength(
addr)));
70 if (
result == 0 || errno == EAGAIN) {
73 FDUtils::SaveErrorAndClose(fd);
77intptr_t Socket::CreateBindConnect(
const RawAddr&
addr,
78 const RawAddr& source_addr) {
85 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr)));
87 FDUtils::SaveErrorAndClose(fd);
91 return Connect(fd,
addr);
94intptr_t Socket::CreateUnixDomainBindConnect(
const RawAddr&
addr,
95 const RawAddr& source_addr) {
102 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr)));
104 FDUtils::SaveErrorAndClose(fd);
109 SocketAddress::GetAddrLength(
addr)));
110 if (
result == 0 || errno == EAGAIN) {
113 FDUtils::SaveErrorAndClose(fd);
117intptr_t Socket::CreateBindDatagram(
const RawAddr&
addr,
124 SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
133 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval,
sizeof(optval)));
137#if !defined(DART_HOST_OS_ANDROID) && defined(SO_REUSEPORT)
139 int reuse_port_success =
140 setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &optval,
sizeof(optval));
143 if (reuse_port_success != 0) {
144 if (errno == EINTR) {
145 FATAL(
"Unexpected EINTR errno");
149 Syslog::PrintErr(
"Dart Socket ERROR: %s:%d: %s.", __FILE__, __LINE__,
154 "Dart Socket ERROR: %s:%d: `reusePort` not supported on this "
160 if (!SocketBase::SetMulticastHops(fd,
161 addr.addr.sa_family == AF_INET
162 ? SocketAddress::TYPE_IPV4
163 : SocketAddress::TYPE_IPV6,
165 FDUtils::SaveErrorAndClose(fd);
170 bind(fd, &
addr.addr, SocketAddress::GetAddrLength(
addr))) < 0) {
171 FDUtils::SaveErrorAndClose(fd);
177intptr_t ServerSocket::CreateBindListen(
const RawAddr&
addr,
183 socket(
addr.ss.ss_family, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0));
190 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval,
sizeof(optval)));
192 if (
addr.ss.ss_family == AF_INET6) {
193 optval = v6_only ? 1 : 0;
195 setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval,
sizeof(optval)));
199 bind(fd, &
addr.addr, SocketAddress::GetAddrLength(
addr))) < 0) {
200 FDUtils::SaveErrorAndClose(fd);
205 if ((SocketAddress::GetAddrPort(
addr) == 0) &&
206 (SocketBase::GetPort(fd) == 65535)) {
209 intptr_t new_fd = CreateBindListen(
addr, backlog, v6_only);
210 FDUtils::SaveErrorAndClose(fd);
215 FDUtils::SaveErrorAndClose(fd);
222intptr_t ServerSocket::CreateUnixDomainBindListen(
const RawAddr&
addr,
226 SocketAddress::GetAddrLength(
addr))) < 0) {
227 FDUtils::SaveErrorAndClose(fd);
231 FDUtils::SaveErrorAndClose(fd);
237bool ServerSocket::StartAccept(intptr_t fd) {
242static bool IsTemporaryAcceptError(
int error) {
245 return (
error == EAGAIN) || (
error == ENETDOWN) || (
error == EPROTO) ||
247 (
error == EHOSTUNREACH) || (
error == EOPNOTSUPP) ||
248 (
error == ENETUNREACH);
251intptr_t ServerSocket::Accept(intptr_t fd) {
253 struct sockaddr clientaddr;
254 socklen_t addrlen =
sizeof(clientaddr);
257 if (IsTemporaryAcceptError(errno)) {
261 ASSERT(kTemporaryFailure != -1);
262 socket = kTemporaryFailure;
265 if (!FDUtils::SetCloseOnExec(socket)) {
266 FDUtils::SaveErrorAndClose(socket);
269 if (!FDUtils::SetNonBlocking(socket)) {
270 FDUtils::SaveErrorAndClose(socket);
static sk_sp< Effect > Create()
static const size_t kBufferSize
const uint8_t uint32_t uint32_t GError ** error
DART_EXPORT Dart_Port Dart_GetMainPortId()
#define NO_RETRY_EXPECTED(expression)
#define VOID_NO_RETRY_EXPECTED(expression)
#define TEMP_FAILURE_RETRY(expression)