OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include <errno.h> // NOLINT | 8 #include <errno.h> // NOLINT |
9 #include <fcntl.h> // NOLINT | 9 #include <fcntl.h> // NOLINT |
10 #include <unistd.h> // NOLINT | 10 #include <unistd.h> // NOLINT |
11 #include <sys/ioctl.h> // NOLINT | 11 #include <sys/ioctl.h> // NOLINT |
12 | 12 |
13 #include "bin/fdutils.h" | 13 #include "bin/fdutils.h" |
14 | 14 |
| 15 #include "platform/signal_blocker.h" |
| 16 |
15 | 17 |
16 namespace dart { | 18 namespace dart { |
17 namespace bin { | 19 namespace bin { |
18 | 20 |
19 bool FDUtils::SetCloseOnExec(intptr_t fd) { | 21 bool FDUtils::SetCloseOnExec(intptr_t fd) { |
20 intptr_t status; | 22 intptr_t status; |
21 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD)); | 23 status = NO_RETRY_EXPECTED(fcntl(fd, F_GETFD)); |
22 if (status < 0) { | 24 if (status < 0) { |
23 return false; | 25 return false; |
24 } | 26 } |
25 status |= FD_CLOEXEC; | 27 status |= FD_CLOEXEC; |
26 if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, status)) < 0) { | 28 if (NO_RETRY_EXPECTED(fcntl(fd, F_SETFD, status)) < 0) { |
27 return false; | 29 return false; |
28 } | 30 } |
29 return true; | 31 return true; |
30 } | 32 } |
31 | 33 |
32 | 34 |
33 static bool SetBlockingHelper(intptr_t fd, bool blocking) { | 35 static bool SetBlockingHelper(intptr_t fd, bool blocking) { |
34 intptr_t status; | 36 intptr_t status; |
35 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); | 37 status = NO_RETRY_EXPECTED(fcntl(fd, F_GETFL)); |
36 if (status < 0) { | 38 if (status < 0) { |
37 return false; | 39 return false; |
38 } | 40 } |
39 status = blocking ? (status & ~O_NONBLOCK) : (status | O_NONBLOCK); | 41 status = blocking ? (status & ~O_NONBLOCK) : (status | O_NONBLOCK); |
40 if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFL, status)) < 0) { | 42 if (NO_RETRY_EXPECTED(fcntl(fd, F_SETFL, status)) < 0) { |
41 return false; | 43 return false; |
42 } | 44 } |
43 return true; | 45 return true; |
44 } | 46 } |
45 | 47 |
46 | 48 |
47 bool FDUtils::SetNonBlocking(intptr_t fd) { | 49 bool FDUtils::SetNonBlocking(intptr_t fd) { |
48 return SetBlockingHelper(fd, false); | 50 return SetBlockingHelper(fd, false); |
49 } | 51 } |
50 | 52 |
51 | 53 |
52 bool FDUtils::SetBlocking(intptr_t fd) { | 54 bool FDUtils::SetBlocking(intptr_t fd) { |
53 return SetBlockingHelper(fd, true); | 55 return SetBlockingHelper(fd, true); |
54 } | 56 } |
55 | 57 |
56 | 58 |
57 bool FDUtils::IsBlocking(intptr_t fd, bool* is_blocking) { | 59 bool FDUtils::IsBlocking(intptr_t fd, bool* is_blocking) { |
58 intptr_t status; | 60 intptr_t status; |
59 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); | 61 status = NO_RETRY_EXPECTED(fcntl(fd, F_GETFL)); |
60 if (status < 0) { | 62 if (status < 0) { |
61 return false; | 63 return false; |
62 } | 64 } |
63 *is_blocking = (status & O_NONBLOCK) == 0; | 65 *is_blocking = (status & O_NONBLOCK) == 0; |
64 return true; | 66 return true; |
65 } | 67 } |
66 | 68 |
67 | 69 |
68 intptr_t FDUtils::AvailableBytes(intptr_t fd) { | 70 intptr_t FDUtils::AvailableBytes(intptr_t fd) { |
69 int available; // ioctl for FIONREAD expects an 'int*' argument. | 71 int available; // ioctl for FIONREAD expects an 'int*' argument. |
70 int result = TEMP_FAILURE_RETRY(ioctl(fd, FIONREAD, &available)); | 72 int result = NO_RETRY_EXPECTED(ioctl(fd, FIONREAD, &available)); |
71 if (result < 0) { | 73 if (result < 0) { |
72 return result; | 74 return result; |
73 } | 75 } |
74 #ifdef DEBUG | 76 #ifdef DEBUG |
75 ASSERT(available >= 0); | 77 ASSERT(available >= 0); |
76 #endif | 78 #endif |
77 return static_cast<intptr_t>(available); | 79 return static_cast<intptr_t>(available); |
78 } | 80 } |
79 | 81 |
80 | 82 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 buffer_pos += bytes_written; | 133 buffer_pos += bytes_written; |
132 } | 134 } |
133 } | 135 } |
134 return count; | 136 return count; |
135 } | 137 } |
136 | 138 |
137 } // namespace bin | 139 } // namespace bin |
138 } // namespace dart | 140 } // namespace dart |
139 | 141 |
140 #endif // defined(TARGET_OS_MACOS) | 142 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |