e50d3b98a3
Basic support for Unix domain sockets on Windows within the limitations of the operating system itself: no support for abstract addresses, datagram or packet sockets and ancillary data. This also fixes File::GetType on Windows to correctly identify reparse points representing AF_UNIX sockets as such, rather then identify them as links. Finally, it is worth noting that there is an existing discrepancy between POSIX OSes and Windows: on POSIX OSes File(sockPath).existsSync() returns true, but on Windows the same code returns false because Unix domain sockets are not considered regular files by stat. This CL does a bunch of refactoring around RawAddr class which surves as a wrapper around various structures in sockaddr_* family. Distinguishing anonymous AF_UNIX address from abstract AF_UNIX address requires passing around the length of the address structure. Thus we incorporate this information into RawAddr. This will also make possible to properly support full-range of abstract AF_UNIX addresses in the future because supporting these requires properly handling embedded NUL bytes. (See https://github.com/dart-lang/sdk/issues/46158). Fixes https://github.com/dart-lang/sdk/issues/41161 TEST=standalone/io/unix_socket Cq-Include-Trybots: luci.dart.try:vm-fuchsia-release-x64-try Change-Id: I016cb33ebdd62f0cac1ae97d822105366a6a6964 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457720 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Slava Egorov <vegorov@google.com>
95 lines
2.3 KiB
C++
95 lines
2.3 KiB
C++
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "platform/globals.h"
|
|
#if defined(DART_HOST_OS_MACOS)
|
|
|
|
#include "bin/sync_socket.h"
|
|
|
|
#include <errno.h> // NOLINT
|
|
|
|
#include "bin/fdutils.h"
|
|
#include "bin/socket_base.h"
|
|
#include "platform/signal_blocker.h"
|
|
|
|
namespace dart {
|
|
namespace bin {
|
|
|
|
bool SynchronousSocket::Initialize() {
|
|
// Nothing to do on Linux.
|
|
return true;
|
|
}
|
|
|
|
static intptr_t Create(const RawAddr& addr) {
|
|
intptr_t fd;
|
|
fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0));
|
|
if (fd < 0) {
|
|
return -1;
|
|
}
|
|
if (!FDUtils::SetCloseOnExec(fd)) {
|
|
FDUtils::SaveErrorAndClose(fd);
|
|
return -1;
|
|
}
|
|
return fd;
|
|
}
|
|
|
|
static intptr_t Connect(intptr_t fd, const RawAddr& addr) {
|
|
intptr_t result = TEMP_FAILURE_RETRY(connect(fd, &addr.addr, addr.size));
|
|
if (result == 0) {
|
|
return fd;
|
|
}
|
|
ASSERT(errno != EINPROGRESS);
|
|
FDUtils::SaveErrorAndClose(fd);
|
|
return -1;
|
|
}
|
|
|
|
intptr_t SynchronousSocket::CreateConnect(const RawAddr& addr) {
|
|
intptr_t fd = Create(addr);
|
|
if (fd < 0) {
|
|
return fd;
|
|
}
|
|
return Connect(fd, addr);
|
|
}
|
|
|
|
intptr_t SynchronousSocket::Available(intptr_t fd) {
|
|
return SocketBase::Available(fd);
|
|
}
|
|
|
|
intptr_t SynchronousSocket::GetPort(intptr_t fd) {
|
|
return SocketBase::GetPort(fd);
|
|
}
|
|
|
|
SocketAddress* SynchronousSocket::GetRemotePeer(intptr_t fd, intptr_t* port) {
|
|
return SocketBase::GetRemotePeer(fd, port);
|
|
}
|
|
|
|
intptr_t SynchronousSocket::Read(intptr_t fd,
|
|
void* buffer,
|
|
intptr_t num_bytes) {
|
|
return SocketBase::Read(fd, buffer, num_bytes, SocketBase::kSync);
|
|
}
|
|
|
|
intptr_t SynchronousSocket::Write(intptr_t fd,
|
|
const void* buffer,
|
|
intptr_t num_bytes) {
|
|
return SocketBase::Write(fd, buffer, num_bytes, SocketBase::kSync);
|
|
}
|
|
|
|
void SynchronousSocket::ShutdownRead(intptr_t fd) {
|
|
VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_RD));
|
|
}
|
|
|
|
void SynchronousSocket::ShutdownWrite(intptr_t fd) {
|
|
VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_WR));
|
|
}
|
|
|
|
void SynchronousSocket::Close(intptr_t fd) {
|
|
return SocketBase::Close(fd);
|
|
}
|
|
|
|
} // namespace bin
|
|
} // namespace dart
|
|
|
|
#endif // defined(DART_HOST_OS_MACOS)
|