OLD | NEW |
---|---|
(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_MACOS) | |
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_macos.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 static intptr_t Create(const RawAddr& addr) { | |
41 intptr_t fd; | |
42 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0)); | |
43 if (fd < 0) { | |
44 return -1; | |
45 } | |
46 if (!FDUtils::SetCloseOnExec(fd)) { | |
47 FDUtils::SaveErrorAndClose(fd); | |
48 return -1; | |
49 } | |
50 return fd; | |
51 } | |
52 | |
53 | |
54 static intptr_t Connect(intptr_t fd, const RawAddr& addr) { | |
55 intptr_t result = TEMP_FAILURE_RETRY( | |
56 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr))); | |
57 if ((result == 0) || (errno == EINPROGRESS)) { | |
zra
2017/04/07 16:29:40
No EINPROGRESS.
bkonyi
2017/04/10 19:20:05
Done.
| |
58 return fd; | |
59 } | |
60 FDUtils::FDUtils::SaveErrorAndClose(fd); | |
61 return -1; | |
62 } | |
63 | |
64 | |
65 intptr_t SynchronousSocket::CreateConnect(const RawAddr& addr) { | |
66 intptr_t fd = Create(addr); | |
67 if (fd < 0) { | |
68 return fd; | |
69 } | |
70 return Connect(fd, addr); | |
71 } | |
72 | |
73 | |
74 void SynchronousSocket::ShutdownRead(intptr_t fd) { | |
75 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_RD)); | |
76 } | |
77 | |
78 | |
79 void SynchronousSocket::ShutdownWrite(intptr_t fd) { | |
80 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_WR)); | |
81 } | |
82 | |
83 } // namespace bin | |
84 } // namespace dart | |
85 | |
86 #endif // defined(HOST_OS_MACOS) | |
87 | |
88 #endif // !defined(DART_IO_DISABLED) | |
OLD | NEW |