1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 17:44:56 +09:00
ladybird/VirtualFileSystem/FileHandle.h
Andreas Kling c6f2890d8e Implement a basic way for read() to block.
FileHandle gets a hasDataAvailableForRead() getter.
If this returns true in sys$read(), the task will block(BlockedRead) + yield.
The fd blocked on is stored in Task::m_fdBlockedOnRead.
The scheduler then looks at the state of that fd during the unblock phase.

This makes "sh" restful. :^)

There's still some problem with the kernel not surviving the colonel task
getting scheduled. I need to figure that out and fix it.
2018-10-25 13:09:56 +02:00

43 lines
897 B
C++

#pragma once
#include "VirtualFileSystem.h"
#include <AK/ByteBuffer.h>
class FileHandle {
public:
explicit FileHandle(RetainPtr<VirtualFileSystem::Node>&&);
~FileHandle();
Unix::off_t seek(Unix::off_t, int whence);
Unix::ssize_t read(byte* buffer, Unix::size_t count);
int stat(Unix::stat*);
bool hasDataAvailableForRead();
ssize_t get_dir_entries(byte* buffer, Unix::size_t);
ByteBuffer readEntireFile();
String absolutePath() const;
#ifdef SERENITY
int fd() const { return m_fd; }
void setFD(int fd) { m_fd = fd; }
bool isBlocking() const { return m_isBlocking; }
void setBlocking(bool b) { m_isBlocking = b; }
#endif
private:
friend class VirtualFileSystem;
RetainPtr<VirtualFileSystem::Node> m_vnode;
Unix::off_t m_currentOffset { 0 };
#ifdef SERENITY
int m_fd { -1 };
bool m_isBlocking { true };
#endif
};