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" |
| 11 | 11 |
| 12 | 12 |
| 13 bool FDUtils::SetNonBlocking(intptr_t fd) { | 13 bool FDUtils::SetNonBlocking(intptr_t fd) { |
| 14 intptr_t status; | 14 intptr_t status; |
| 15 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); | 15 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); |
| 16 if (status < 0) { | 16 if (status < 0) { |
| 17 perror("fcntl F_GETFL failed"); | 17 perror("fcntl F_GETFL failed"); |
| 18 return false; | 18 return false; |
| 19 } | 19 } |
| 20 status = (status | O_NONBLOCK); | 20 status = (status | O_NONBLOCK); |
| 21 if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFL, status)) < 0) { | 21 if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFL, status)) < 0) { |
| 22 perror("fcntl F_SETFL failed"); | 22 perror("fcntl F_SETFL failed"); |
| 23 return false; | 23 return false; |
| 24 } | 24 } |
| 25 return true; | 25 return true; |
| 26 } | 26 } |
| 27 | 27 |
| 28 | 28 |
| 29 bool FDUtils::SetBlocking(intptr_t fd) { | |
| 30 intptr_t status; | |
| 31 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); | |
| 32 if (status < 0) { | |
| 33 perror("fcntl F_GETFL failed"); | |
| 34 return false; | |
| 35 } | |
| 36 status = (status & ~O_NONBLOCK); | |
| 37 if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFL, status)) < 0) { | |
| 38 perror("fcntl F_SETFL failed"); | |
| 39 return false; | |
| 40 } | |
| 41 return true; | |
|
siva
2012/05/03 22:52:08
Ditto comment regarding re factoring this.
I wond
hausner
2012/05/03 23:52:00
I was wondering too. They probably have a differen
| |
| 42 } | |
| 43 | |
| 44 | |
| 29 bool FDUtils::IsBlocking(intptr_t fd, bool* is_blocking) { | 45 bool FDUtils::IsBlocking(intptr_t fd, bool* is_blocking) { |
| 30 intptr_t status; | 46 intptr_t status; |
| 31 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); | 47 status = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFL)); |
| 32 if (status < 0) { | 48 if (status < 0) { |
| 33 perror("fcntl F_GETFL failed"); | 49 perror("fcntl F_GETFL failed"); |
| 34 return false; | 50 return false; |
| 35 } | 51 } |
| 36 *is_blocking = (status & O_NONBLOCK) == 0; | 52 *is_blocking = (status & O_NONBLOCK) == 0; |
| 37 return true; | 53 return true; |
| 38 } | 54 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 ASSERT(errno != EWOULDBLOCK); | 116 ASSERT(errno != EWOULDBLOCK); |
| 101 return -1; | 117 return -1; |
| 102 } else { | 118 } else { |
| 103 ASSERT(bytes_written > 0); | 119 ASSERT(bytes_written > 0); |
| 104 remaining -= bytes_written; | 120 remaining -= bytes_written; |
| 105 buffer_pos += bytes_written; | 121 buffer_pos += bytes_written; |
| 106 } | 122 } |
| 107 } | 123 } |
| 108 return count; | 124 return count; |
| 109 } | 125 } |
| OLD | NEW |