Skip to content

Commit 59f49e2

Browse files
committed
Add is_blocking() method to FileHandle
There was no way to check current blocking state, so no way to modify and restore status. Also have default FileHandle::set_blocking() used by real files return a correct error code when asked for non-blocking, and success when asked for blocking. These were minor omissions that are required to implement POSIX fcntl properly. fixup! Add `is_blocking()` method to FileHandle
1 parent c8d72c5 commit 59f49e2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

drivers/UARTSerial.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ class UARTSerial : private SerialBase, public FileHandle, private NonCopyable<UA
142142
return 0;
143143
}
144144

145+
/** Check current blocking or non-blocking mode for file operations.
146+
*
147+
* @return true for blocking mode, false for non-blocking mode.
148+
*/
149+
virtual bool is_blocking() const
150+
{
151+
return _blocking;
152+
}
153+
145154
/** Register a callback on state change of the file.
146155
*
147156
* The specified callback will be called on state changes such as when

platform/FileHandle.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,16 @@ class FileHandle : private NonCopyable<FileHandle> {
192192
*/
193193
virtual int set_blocking(bool blocking)
194194
{
195-
return -1;
195+
return blocking ? 0 : -ENOTTY;
196+
}
197+
198+
/** Check current blocking or non-blocking mode for file operations.
199+
*
200+
* @return true for blocking mode, false for non-blocking mode.
201+
*/
202+
virtual bool is_blocking() const
203+
{
204+
return true;
196205
}
197206

198207
/** Check for poll event flags

0 commit comments

Comments
 (0)