kernel+libc: Add O_NONBLOCK
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
41514d9ad2
commit
51f0bdff0e
@ -21,7 +21,12 @@ Result<u64> sys_read(Registers*, SyscallArgs args)
|
|||||||
|
|
||||||
if (!descriptor.is_readable()) return err(EBADF);
|
if (!descriptor.is_readable()) return err(EBADF);
|
||||||
|
|
||||||
while (descriptor.inode->blocking()) { kernel_sleep(10); }
|
while (descriptor.inode->blocking())
|
||||||
|
{
|
||||||
|
if (descriptor.should_block()) kernel_sleep(10);
|
||||||
|
else
|
||||||
|
return err(EAGAIN);
|
||||||
|
}
|
||||||
|
|
||||||
usize nread = TRY(descriptor.inode->read(buf, descriptor.offset, size));
|
usize nread = TRY(descriptor.inode->read(buf, descriptor.offset, size));
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <bits/open-flags.h>
|
#include <bits/open-flags.h>
|
||||||
|
|
||||||
// These flags are needed after open(), the rest only affect open().
|
// These flags are needed after open(), the rest only affect open().
|
||||||
constexpr int FLAGS_TO_KEEP = O_RDWR | O_APPEND;
|
constexpr int FLAGS_TO_KEEP = O_RDWR | O_APPEND | O_NONBLOCK;
|
||||||
|
|
||||||
Result<u64> sys_open(Registers*, SyscallArgs args)
|
Result<u64> sys_open(Registers*, SyscallArgs args)
|
||||||
{
|
{
|
||||||
|
@ -50,6 +50,11 @@ bool FileDescriptor::should_append()
|
|||||||
return flags & O_APPEND;
|
return flags & O_APPEND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileDescriptor::should_block()
|
||||||
|
{
|
||||||
|
return flags & O_NONBLOCK;
|
||||||
|
}
|
||||||
|
|
||||||
bool FileDescriptor::is_readable()
|
bool FileDescriptor::is_readable()
|
||||||
{
|
{
|
||||||
return flags & O_RDONLY;
|
return flags & O_RDONLY;
|
||||||
|
@ -29,6 +29,7 @@ struct FileDescriptor
|
|||||||
int flags { 0 };
|
int flags { 0 };
|
||||||
|
|
||||||
bool should_append();
|
bool should_append();
|
||||||
|
bool should_block();
|
||||||
bool is_writable();
|
bool is_writable();
|
||||||
bool is_readable();
|
bool is_readable();
|
||||||
};
|
};
|
||||||
|
@ -10,5 +10,6 @@
|
|||||||
#define O_CREAT 8
|
#define O_CREAT 8
|
||||||
#define O_EXCL 16
|
#define O_EXCL 16
|
||||||
#define O_TRUNC 32
|
#define O_TRUNC 32
|
||||||
|
#define O_NONBLOCK 64
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user