| 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <unistd.h> | 7 #include <unistd.h> |
| 8 #include <sys/ioctl.h> | 8 #include <sys/ioctl.h> |
| 9 | 9 |
| 10 #include "bin/fdutils.h" | 10 #include "bin/fdutils.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 } | 35 } |
| 36 *is_blocking = (status & O_NONBLOCK) == 0; | 36 *is_blocking = (status & O_NONBLOCK) == 0; |
| 37 return true; | 37 return true; |
| 38 } | 38 } |
| 39 | 39 |
| 40 | 40 |
| 41 intptr_t FDUtils::AvailableBytes(intptr_t fd) { | 41 intptr_t FDUtils::AvailableBytes(intptr_t fd) { |
| 42 int available; // ioctl for FIONREAD expects an 'int*' argument. | 42 int available; // ioctl for FIONREAD expects an 'int*' argument. |
| 43 int result = TEMP_FAILURE_RETRY(ioctl(fd, FIONREAD, &available)); | 43 int result = TEMP_FAILURE_RETRY(ioctl(fd, FIONREAD, &available)); |
| 44 if (result < 0) { | 44 if (result < 0) { |
| 45 perror("ioctl FIONREAD failed"); |
| 45 return result; | 46 return result; |
| 46 } | 47 } |
| 47 #ifdef DEBUG | 48 #ifdef DEBUG |
| 48 ASSERT(available >= 0); | 49 ASSERT(available >= 0); |
| 49 #endif | 50 #endif |
| 50 return static_cast<intptr_t>(available); | 51 return static_cast<intptr_t>(available); |
| 51 } | 52 } |
| 52 | 53 |
| 53 | 54 |
| 54 ssize_t FDUtils::ReadFromBlocking(int fd, void* buffer, size_t count) { | 55 ssize_t FDUtils::ReadFromBlocking(int fd, void* buffer, size_t count) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 ASSERT(errno != EWOULDBLOCK); | 100 ASSERT(errno != EWOULDBLOCK); |
| 100 return -1; | 101 return -1; |
| 101 } else { | 102 } else { |
| 102 ASSERT(bytes_written > 0); | 103 ASSERT(bytes_written > 0); |
| 103 remaining -= bytes_written; | 104 remaining -= bytes_written; |
| 104 buffer_pos += bytes_written; | 105 buffer_pos += bytes_written; |
| 105 } | 106 } |
| 106 } | 107 } |
| 107 return count; | 108 return count; |
| 108 } | 109 } |
| OLD | NEW |