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

Side by Side Diff: runtime/bin/sync_socket_fuchsia.cc

Issue 2803543006: Added synchronous socket implementation to dart:io. (Closed)
Patch Set: Small fix for MacOS 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
zra 2017/04/07 16:29:40 2017
bkonyi 2017/04/10 19:20:05 Done.
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #if !defined(DART_IO_DISABLED)
6
7 #include "platform/globals.h"
8 #if defined(HOST_OS_FUCHSIA)
9
10 #include "bin/sync_socket.h"
11
12 #include <errno.h> // NOLINT
13 #include <ifaddrs.h> // NOLINT
14 #include <net/if.h> // NOLINT
15 #include <netinet/tcp.h> // NOLINT
16 #include <poll.h> // NOLINT
17 #include <stdio.h> // NOLINT
18 #include <stdlib.h> // NOLINT
19 #include <string.h> // NOLINT
20 #include <sys/stat.h> // NOLINT
21 #include <unistd.h> // NOLINT
22
23 #include "bin/fdutils.h"
24 #include "bin/file.h"
25 #include "bin/socket_base_fuchsia.h"
26 #include "bin/thread.h"
27 #include "platform/signal_blocker.h"
28
29 namespace dart {
30 namespace bin {
31
32 SynchronousSocket::SynchronousSocket(intptr_t fd) : fd_(fd) {}
33
34
35 void SynchronousSocket::SetClosedFd() {
36 fd_ = kClosedFd;
37 }
38
39
40 bool SynchronousSocket::Initialize() {
41 // Nothing to do on Fuchsia.
42 return true;
43 }
44
45
46 static intptr_t Create(const RawAddr& addr) {
47 intptr_t fd;
48 intptr_t type = SOCK_STREAM | SOCK_CLOEXEC;
49 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, type, 0));
50 if (fd < 0) {
51 return -1;
52 }
53 return fd;
54 }
55
56
57 static intptr_t Connect(intptr_t fd, const RawAddr& addr) {
58 intptr_t result = TEMP_FAILURE_RETRY(
59 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr)));
60 if ((result == 0) || (errno == EINPROGRESS)) {
zra 2017/04/07 16:29:40 No EINPROGRESS.
bkonyi 2017/04/10 19:20:05 Done.
61 return fd;
62 }
63 FDUtils::FDUtils::SaveErrorAndClose(fd);
64 return -1;
65 }
66
67
68 intptr_t SynchronousSocket::CreateConnect(const RawAddr& addr) {
69 intptr_t fd = Create(addr);
70 if (fd < 0) {
71 return fd;
72 }
73 return Connect(fd, addr);
74 }
75
76
77 void SynchronousSocket::ShutdownRead(intptr_t fd) {
78 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_RD));
79 }
80
81
82 void SynchronousSocket::ShutdownWrite(intptr_t fd) {
83 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_WR));
84 }
85
86 } // namespace bin
87 } // namespace dart
88
89 #endif // defined(HOST_OS_FUCHSIA)
90
91 #endif // !defined(DART_IO_DISABLED)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698