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 #ifndef BIN_FDUTILS_H_ | 5 #ifndef BIN_FDUTILS_H_ |
6 #define BIN_FDUTILS_H_ | 6 #define BIN_FDUTILS_H_ |
7 | 7 |
8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
10 | 10 |
11 class FDUtils { | 11 class FDUtils { |
12 public: | 12 public: |
13 static bool SetNonBlocking(intptr_t fd); | 13 static bool SetNonBlocking(intptr_t fd); |
| 14 static bool SetBlocking(intptr_t fd); |
14 | 15 |
15 // Checks whether the file descriptor is blocking. If the function | 16 // Checks whether the file descriptor is blocking. If the function |
16 // returns true the value pointed to by is_blocking will be set to | 17 // returns true the value pointed to by is_blocking will be set to |
17 // the blocking state of the file descriptor. If the function | 18 // the blocking state of the file descriptor. If the function |
18 // returns false the system call for checking the file descriptor | 19 // returns false the system call for checking the file descriptor |
19 // failed and the value pointed to by is_blocking is not modified. | 20 // failed and the value pointed to by is_blocking is not modified. |
20 static bool IsBlocking(intptr_t fd, bool* is_blocking); | 21 static bool IsBlocking(intptr_t fd, bool* is_blocking); |
21 | 22 |
22 static intptr_t AvailableBytes(intptr_t fd); | 23 static intptr_t AvailableBytes(intptr_t fd); |
23 | 24 |
24 // Reads the requested number of bytes from a file descriptor. This | 25 // Reads the requested number of bytes from a file descriptor. This |
25 // function will only return on short reads if an error occours in | 26 // function will only return on short reads if an error occours in |
26 // which case it returns -1 and errno is still valid. The file | 27 // which case it returns -1 and errno is still valid. The file |
27 // descriptor must be in blocking mode. | 28 // descriptor must be in blocking mode. |
28 static ssize_t ReadFromBlocking(int fd, void* buffer, size_t count); | 29 static ssize_t ReadFromBlocking(int fd, void* buffer, size_t count); |
29 | 30 |
30 // Writes the requested number of bytes to a file descriptor. This | 31 // Writes the requested number of bytes to a file descriptor. This |
31 // function will only return on short writes if an error occours in | 32 // function will only return on short writes if an error occours in |
32 // which case it returns -1 and errno is still valid. The file | 33 // which case it returns -1 and errno is still valid. The file |
33 // descriptor must be in blocking mode. | 34 // descriptor must be in blocking mode. |
34 static ssize_t WriteToBlocking(int fd, const void* buffer, size_t count); | 35 static ssize_t WriteToBlocking(int fd, const void* buffer, size_t count); |
35 | 36 |
36 private: | 37 private: |
37 DISALLOW_ALLOCATION(); | 38 DISALLOW_ALLOCATION(); |
38 DISALLOW_IMPLICIT_CONSTRUCTORS(FDUtils); | 39 DISALLOW_IMPLICIT_CONSTRUCTORS(FDUtils); |
39 }; | 40 }; |
40 | 41 |
41 #endif // BIN_FDUTILS_H_ | 42 #endif // BIN_FDUTILS_H_ |
OLD | NEW |