Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Unified Diff: runtime/bin/sync_socket_fuchsia.cc

Issue 2814773004: Various fixes for sync socket implementation. (Closed)
Patch Set: Various fixes for sync socket implementation. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/sync_socket_android.cc ('k') | runtime/bin/sync_socket_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/sync_socket_fuchsia.cc
diff --git a/runtime/bin/sync_socket_fuchsia.cc b/runtime/bin/sync_socket_fuchsia.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ec55e2c7908277786855deea5f333d8f1641371f
--- /dev/null
+++ b/runtime/bin/sync_socket_fuchsia.cc
@@ -0,0 +1,80 @@
+// 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_FUCHSIA)
+
+#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;
+}
+
+
+bool SynchronousSocket::Initialize() {
+ // Nothing to do on Fuchsia.
+ return true;
+}
+
+
+static intptr_t Create(const RawAddr& addr) {
+ intptr_t fd;
+ intptr_t type = SOCK_STREAM | SOCK_CLOEXEC;
+ fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, type, 0));
+ if (fd < 0) {
+ 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_FUCHSIA)
+
+#endif // !defined(DART_IO_DISABLED)
« no previous file with comments | « runtime/bin/sync_socket_android.cc ('k') | runtime/bin/sync_socket_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698