a1f87ebdb8
BUG= R=zra@google.com Review-Url: https://codereview.chromium.org/2803543006 .
78 lines
1.6 KiB
C++
78 lines
1.6 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.
|
|
|
|
#if !defined(DART_IO_DISABLED)
|
|
|
|
#include "platform/globals.h"
|
|
#if defined(HOST_OS_MACOS)
|
|
|
|
#include "bin/sync_socket.h"
|
|
|
|
#include <errno.h> // NOLINT
|
|
|
|
#include "bin/fdutils.h"
|
|
#include "platform/signal_blocker.h"
|
|
|
|
namespace dart {
|
|
namespace bin {
|
|
|
|
SynchronousSocket::SynchronousSocket(intptr_t fd) : fd_(fd) {}
|
|
|
|
|
|
void SynchronousSocket::SetClosedFd() {
|
|
fd_ = kClosedFd;
|
|
}
|
|
|
|
|
|
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, SocketAddress::GetAddrLength(addr)));
|
|
if (result == 0) {
|
|
return fd;
|
|
}
|
|
ASSERT(errno != EINPROGRESS);
|
|
FDUtils::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);
|
|
}
|
|
|
|
|
|
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));
|
|
}
|
|
|
|
} // namespace bin
|
|
} // namespace dart
|
|
|
|
#endif // defined(HOST_OS_MACOS)
|
|
|
|
#endif // !defined(DART_IO_DISABLED)
|