| 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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 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 #include "platform/signal_blocker.h" |
| 14 | 15 |
| 15 | 16 |
| 16 namespace dart { | 17 namespace dart { |
| 17 namespace bin { | 18 namespace bin { |
| 18 | 19 |
| 19 bool FDUtils::SetCloseOnExec(intptr_t fd) { | 20 bool FDUtils::SetCloseOnExec(intptr_t fd) { |
| 20 intptr_t status; | 21 intptr_t status; |
| 21 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD)); | 22 status = fcntl(fd, F_GETFD); |
| 22 if (status < 0) { | 23 if (status < 0) { |
| 23 return false; | 24 return false; |
| 24 } | 25 } |
| 25 status |= FD_CLOEXEC; | 26 status |= FD_CLOEXEC; |
| 26 if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, status)) < 0) { | 27 if (fcntl(fd, F_SETFD, status) < 0) { |
| 27 return false; | 28 return false; |
| 28 } | 29 } |
| 29 return true; | 30 return true; |
| 30 } | 31 } |
| 31 | 32 |
| 32 | 33 |
| 33 static bool SetBlockingHelper(intptr_t fd, bool blocking) { | 34 static bool SetBlockingHelper(intptr_t fd, bool blocking) { |
| 34 intptr_t status; | 35 intptr_t status; |
| 35 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); | 36 status = fcntl(fd, F_GETFL); |
| 36 if (status < 0) { | 37 if (status < 0) { |
| 37 return false; | 38 return false; |
| 38 } | 39 } |
| 39 status = blocking ? (status & ~O_NONBLOCK) : (status | O_NONBLOCK); | 40 status = blocking ? (status & ~O_NONBLOCK) : (status | O_NONBLOCK); |
| 40 if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFL, status)) < 0) { | 41 if (fcntl(fd, F_SETFL, status) < 0) { |
| 41 return false; | 42 return false; |
| 42 } | 43 } |
| 43 return true; | 44 return true; |
| 44 } | 45 } |
| 45 | 46 |
| 46 | 47 |
| 47 bool FDUtils::SetNonBlocking(intptr_t fd) { | 48 bool FDUtils::SetNonBlocking(intptr_t fd) { |
| 48 return SetBlockingHelper(fd, false); | 49 return SetBlockingHelper(fd, false); |
| 49 } | 50 } |
| 50 | 51 |
| 51 | 52 |
| 52 bool FDUtils::SetBlocking(intptr_t fd) { | 53 bool FDUtils::SetBlocking(intptr_t fd) { |
| 53 return SetBlockingHelper(fd, true); | 54 return SetBlockingHelper(fd, true); |
| 54 } | 55 } |
| 55 | 56 |
| 56 | 57 |
| 57 bool FDUtils::IsBlocking(intptr_t fd, bool* is_blocking) { | 58 bool FDUtils::IsBlocking(intptr_t fd, bool* is_blocking) { |
| 58 intptr_t status; | 59 intptr_t status; |
| 59 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); | 60 status = fcntl(fd, F_GETFL); |
| 60 if (status < 0) { | 61 if (status < 0) { |
| 61 return false; | 62 return false; |
| 62 } | 63 } |
| 63 *is_blocking = (status & O_NONBLOCK) == 0; | 64 *is_blocking = (status & O_NONBLOCK) == 0; |
| 64 return true; | 65 return true; |
| 65 } | 66 } |
| 66 | 67 |
| 67 | 68 |
| 68 intptr_t FDUtils::AvailableBytes(intptr_t fd) { | 69 intptr_t FDUtils::AvailableBytes(intptr_t fd) { |
| 69 int available; // ioctl for FIONREAD expects an 'int*' argument. | 70 int available; // ioctl for FIONREAD expects an 'int*' argument. |
| 70 int result = TEMP_FAILURE_RETRY(ioctl(fd, FIONREAD, &available)); | 71 int result = ioctl(fd, FIONREAD, &available); |
| 71 if (result < 0) { | 72 if (result < 0) { |
| 72 return result; | 73 return result; |
| 73 } | 74 } |
| 74 #ifdef DEBUG | 75 #ifdef DEBUG |
| 75 ASSERT(available >= 0); | 76 ASSERT(available >= 0); |
| 76 #endif | 77 #endif |
| 77 return static_cast<intptr_t>(available); | 78 return static_cast<intptr_t>(available); |
| 78 } | 79 } |
| 79 | 80 |
| 80 | 81 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 buffer_pos += bytes_written; | 132 buffer_pos += bytes_written; |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 return count; | 135 return count; |
| 135 } | 136 } |
| 136 | 137 |
| 137 } // namespace bin | 138 } // namespace bin |
| 138 } // namespace dart | 139 } // namespace dart |
| 139 | 140 |
| 140 #endif // defined(TARGET_OS_LINUX) | 141 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |