Chromium Code Reviews| 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 20 matching lines...) Expand all Loading... | |
| 31 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); | 31 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); |
| 32 if (status < 0) { | 32 if (status < 0) { |
| 33 perror("fcntl F_GETFL failed"); | 33 perror("fcntl F_GETFL failed"); |
| 34 return false; | 34 return false; |
| 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) { |
|
Søren Gjesse
2012/01/12 07:32:47
I have it on my TODO list to change all these uses
siva
2012/01/12 19:30:50
Ok.
On 2012/01/12 07:32:47, Søren Gjesse wrote:
| |
| 42 size_t available; | 42 int32_t available; |
|
Søren Gjesse
2012/01/12 07:32:47
Shouldn't we just use int here as that is what is
siva
2012/01/12 19:30:50
I would prefer int32_t as opposed to int as it mak
| |
| 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 return result; | 45 return result; |
| 46 } | 46 } |
| 47 return available; | 47 return static_cast<intptr_t>(available); |
| 48 } | 48 } |
| 49 | 49 |
| 50 | 50 |
| 51 ssize_t FDUtils::ReadFromBlocking(int fd, void* buffer, size_t count) { | 51 ssize_t FDUtils::ReadFromBlocking(int fd, void* buffer, size_t count) { |
| 52 #ifdef DEBUG | 52 #ifdef DEBUG |
| 53 bool is_blocking = false; | 53 bool is_blocking = false; |
| 54 ASSERT(FDUtils::IsBlocking(fd, &is_blocking)); | 54 ASSERT(FDUtils::IsBlocking(fd, &is_blocking)); |
| 55 ASSERT(is_blocking); | 55 ASSERT(is_blocking); |
| 56 #endif | 56 #endif |
| 57 size_t remaining = count; | 57 size_t remaining = count; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 ASSERT(errno != EWOULDBLOCK); | 96 ASSERT(errno != EWOULDBLOCK); |
| 97 return -1; | 97 return -1; |
| 98 } else { | 98 } else { |
| 99 ASSERT(bytes_written > 0); | 99 ASSERT(bytes_written > 0); |
| 100 remaining -= bytes_written; | 100 remaining -= bytes_written; |
| 101 buffer_pos += bytes_written; | 101 buffer_pos += bytes_written; |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 return count; | 104 return count; |
| 105 } | 105 } |
| OLD | NEW |