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

Side by Side Diff: runtime/bin/sync_socket_macos.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 unified diff | Download patch
« no previous file with comments | « runtime/bin/sync_socket_linux.cc ('k') | runtime/bin/sync_socket_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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_MACOS)
9
10 #include "bin/sync_socket.h"
11
12 #include <errno.h> // NOLINT
13
14 #include "bin/fdutils.h"
15 #include "platform/signal_blocker.h"
16
17 namespace dart {
18 namespace bin {
19
20 SynchronousSocket::SynchronousSocket(intptr_t fd) : fd_(fd) {}
21
22
23 void SynchronousSocket::SetClosedFd() {
24 fd_ = kClosedFd;
25 }
26
27
28 static intptr_t Create(const RawAddr& addr) {
29 intptr_t fd;
30 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0));
31 if (fd < 0) {
32 return -1;
33 }
34 if (!FDUtils::SetCloseOnExec(fd)) {
35 FDUtils::SaveErrorAndClose(fd);
36 return -1;
37 }
38 return fd;
39 }
40
41
42 static intptr_t Connect(intptr_t fd, const RawAddr& addr) {
43 intptr_t result = TEMP_FAILURE_RETRY(
44 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr)));
45 if (result == 0) {
46 return fd;
47 }
48 ASSERT(errno != EINPROGRESS);
49 FDUtils::FDUtils::SaveErrorAndClose(fd);
50 return -1;
51 }
52
53
54 intptr_t SynchronousSocket::CreateConnect(const RawAddr& addr) {
55 intptr_t fd = Create(addr);
56 if (fd < 0) {
57 return fd;
58 }
59 return Connect(fd, addr);
60 }
61
62
63 void SynchronousSocket::ShutdownRead(intptr_t fd) {
64 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_RD));
65 }
66
67
68 void SynchronousSocket::ShutdownWrite(intptr_t fd) {
69 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_WR));
70 }
71
72 } // namespace bin
73 } // namespace dart
74
75 #endif // defined(HOST_OS_MACOS)
76
77 #endif // !defined(DART_IO_DISABLED)
OLDNEW
« no previous file with comments | « runtime/bin/sync_socket_linux.cc ('k') | runtime/bin/sync_socket_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698