6#if defined(DART_HOST_OS_MACOS)
23 udp_receive_buffer_(nullptr) {}
25void Socket::CloseFd() {
29void Socket::SetClosedFd() {
39 if (!FDUtils::SetCloseOnExec(fd)) {
40 FDUtils::SaveErrorAndClose(fd);
43 if (!FDUtils::SetNonBlocking(fd)) {
44 FDUtils::SaveErrorAndClose(fd);
51 setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &optval,
sizeof(optval)));
55static intptr_t Connect(intptr_t fd,
const RawAddr&
addr) {
57 connect(fd, &
addr.addr, SocketAddress::GetAddrLength(
addr)));
58 if ((
result == 0) || (errno == EINPROGRESS)) {
61 FDUtils::SaveErrorAndClose(fd);
65intptr_t Socket::CreateConnect(
const RawAddr&
addr) {
71 return Connect(fd,
addr);
74intptr_t Socket::CreateUnixDomainConnect(
const RawAddr&
addr) {
79 return Connect(fd,
addr);
82intptr_t Socket::CreateBindConnect(
const RawAddr&
addr,
83 const RawAddr& source_addr) {
90 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr)));
92 FDUtils::SaveErrorAndClose(fd);
96 return Connect(fd,
addr);
99intptr_t Socket::CreateUnixDomainBindConnect(
const RawAddr&
addr,
100 const RawAddr& source_addr) {
107 bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr)));
109 FDUtils::SaveErrorAndClose(fd);
113 return Connect(fd,
addr);
116intptr_t Socket::CreateBindDatagram(
const RawAddr&
addr,
127 if (!FDUtils::SetCloseOnExec(fd)) {
128 FDUtils::SaveErrorAndClose(fd);
135 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval,
sizeof(optval)));
141 setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &optval,
sizeof(optval)));
144 if (!SocketBase::SetMulticastHops(fd,
145 addr.addr.sa_family == AF_INET
146 ? SocketAddress::TYPE_IPV4
147 : SocketAddress::TYPE_IPV6,
149 FDUtils::SaveErrorAndClose(fd);
157 setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &optval,
sizeof(optval)));
160 bind(fd, &
addr.addr, SocketAddress::GetAddrLength(
addr))) < 0) {
161 FDUtils::SaveErrorAndClose(fd);
165 if (!FDUtils::SetNonBlocking(fd)) {
166 FDUtils::SaveErrorAndClose(fd);
172intptr_t ServerSocket::CreateBindListen(
const RawAddr&
addr,
182 if (!FDUtils::SetCloseOnExec(fd)) {
183 FDUtils::SaveErrorAndClose(fd);
189 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval,
sizeof(optval)));
195 setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &optval,
sizeof(optval)));
197 if (
addr.ss.ss_family == AF_INET6) {
198 optval = v6_only ? 1 : 0;
200 setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &optval,
sizeof(optval)));
204 bind(fd, &
addr.addr, SocketAddress::GetAddrLength(
addr))) < 0) {
205 FDUtils::SaveErrorAndClose(fd);
210 if ((SocketAddress::GetAddrPort(
addr) == 0) &&
211 (SocketBase::GetPort(fd) == 65535)) {
214 intptr_t new_fd = CreateBindListen(
addr, backlog, v6_only);
215 FDUtils::SaveErrorAndClose(fd);
220 FDUtils::SaveErrorAndClose(fd);
224 if (!FDUtils::SetNonBlocking(fd)) {
225 FDUtils::SaveErrorAndClose(fd);
231intptr_t ServerSocket::CreateUnixDomainBindListen(
const RawAddr&
addr,
239 if (!FDUtils::SetCloseOnExec(fd)) {
240 FDUtils::SaveErrorAndClose(fd);
245 bind(fd, &
addr.addr, SocketAddress::GetAddrLength(
addr))) < 0) {
246 FDUtils::SaveErrorAndClose(fd);
251 FDUtils::SaveErrorAndClose(fd);
255 if (!FDUtils::SetNonBlocking(fd)) {
256 FDUtils::SaveErrorAndClose(fd);
262bool ServerSocket::StartAccept(intptr_t fd) {
267intptr_t ServerSocket::Accept(intptr_t fd) {
269 struct sockaddr clientaddr;
270 socklen_t addrlen =
sizeof(clientaddr);
273 if (errno == EAGAIN) {
277 ASSERT(kTemporaryFailure != -1);
278 socket = kTemporaryFailure;
281 if (!FDUtils::SetCloseOnExec(socket)) {
282 FDUtils::SaveErrorAndClose(socket);
285 if (!FDUtils::SetNonBlocking(socket)) {
286 FDUtils::SaveErrorAndClose(socket);
static sk_sp< Effect > Create()
DART_EXPORT Dart_Port Dart_GetMainPortId()
#define NO_RETRY_EXPECTED(expression)
#define VOID_NO_RETRY_EXPECTED(expression)
#define TEMP_FAILURE_RETRY(expression)