Allow you do explicitly close stream, vfs

This commit is contained in:
2025-09-29 03:53:54 -05:00
parent d785508571
commit 234ec372a4
19 changed files with 54 additions and 7 deletions

View File

@@ -39,7 +39,6 @@ namespace Tesses::Framework::Filesystem
void Chmod(VFSPath path, uint32_t mode); void Chmod(VFSPath path, uint32_t mode);
}; };
extern std::shared_ptr<LocalFilesystem> LocalFS; extern std::shared_ptr<LocalFilesystem> LocalFS;
} }

View File

@@ -94,6 +94,7 @@ namespace Tesses::Framework::Filesystem
VFSPath SystemToVFSPath(std::string path); VFSPath SystemToVFSPath(std::string path);
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess); void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess); void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
~MemoryFilesystem(); ~MemoryFilesystem();
}; };
}; };

View File

@@ -57,5 +57,6 @@ namespace Tesses::Framework::Filesystem
void Chmod(VFSPath path, uint32_t mode); void Chmod(VFSPath path, uint32_t mode);
void Close();
}; };
} }

View File

@@ -153,5 +153,7 @@ namespace Tesses::Framework::Filesystem
virtual void Chmod(VFSPath path, uint32_t mode); virtual void Chmod(VFSPath path, uint32_t mode);
virtual ~VFS(); virtual ~VFS();
virtual void Close();
}; };
} }

View File

@@ -20,6 +20,7 @@ namespace Tesses::Framework::Streams
size_t Write(const uint8_t* buff, size_t sz); size_t Write(const uint8_t* buff, size_t sz);
~BufferedStream(); ~BufferedStream();
void Close();
}; };
} }

View File

@@ -23,6 +23,6 @@ namespace Tesses::Framework::Streams
void Flush(); void Flush();
void Seek(int64_t pos, SeekOrigin whence); void Seek(int64_t pos, SeekOrigin whence);
~FileStream(); ~FileStream();
void Close();
}; };
} }

View File

@@ -17,6 +17,6 @@ namespace Tesses::Framework::Streams
int64_t GetLength(); int64_t GetLength();
int64_t GetPosition(); int64_t GetPosition();
void Seek(int64_t pos, SeekOrigin whence); void Seek(int64_t pos, SeekOrigin whence);
void Close();
}; };
} }

View File

@@ -53,5 +53,6 @@ namespace Tesses::Framework::Streams
static std::vector<std::pair<std::string,std::string>> GetIPs(bool ipV6=false); static std::vector<std::pair<std::string,std::string>> GetIPs(bool ipV6=false);
~NetworkStream(); ~NetworkStream();
void SetNoDelay(bool noDelay); void SetNoDelay(bool noDelay);
void Close();
}; };
} }

View File

@@ -25,5 +25,6 @@ namespace Tesses::Framework::Streams
void Resize(WindowSize sz); void Resize(WindowSize sz);
WindowSize GetWindowSize(); WindowSize GetWindowSize();
~PtyStream(); ~PtyStream();
void Close();
}; };
} }

View File

@@ -24,6 +24,7 @@ namespace Tesses::Framework::Streams
virtual void Flush(); virtual void Flush();
virtual void Seek(int64_t pos, SeekOrigin whence); virtual void Seek(int64_t pos, SeekOrigin whence);
void CopyTo(std::shared_ptr<Stream> strm, size_t buffSize=1024); void CopyTo(std::shared_ptr<Stream> strm, size_t buffSize=1024);
virtual void Close();
virtual ~Stream(); virtual ~Stream();
}; };
} }

View File

@@ -3,6 +3,7 @@
namespace Tesses::Framework::Filesystem namespace Tesses::Framework::Filesystem
{ {
MemoryFilesystemStream::MemoryFilesystemStream(std::shared_ptr<Tesses::Framework::Threading::Mutex> mtx, std::shared_ptr<MemoryFileData> data,bool canRead, bool canWrite, bool canSeek) MemoryFilesystemStream::MemoryFilesystemStream(std::shared_ptr<Tesses::Framework::Threading::Mutex> mtx, std::shared_ptr<MemoryFileData> data,bool canRead, bool canWrite, bool canSeek)
{ {
this->mtx = mtx; this->mtx = mtx;

View File

@@ -21,6 +21,13 @@ namespace Tesses::Framework::Filesystem
for(auto item : this->directories) delete item; for(auto item : this->directories) delete item;
} }
void MountableFilesystem::Close()
{
this->root=nullptr;
for(auto item : this->directories) delete item;
this->directories.clear();
}
void MountableFilesystem::GetFS(VFSPath srcPath, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs) void MountableFilesystem::GetFS(VFSPath srcPath, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs)
{ {

View File

@@ -517,5 +517,7 @@ namespace Tesses::Framework::Filesystem
void VFS::Chmod(VFSPath path, uint32_t mode) { void VFS::Chmod(VFSPath path, uint32_t mode) {
} }
void VFS::Close() {
} }
}

View File

@@ -58,4 +58,9 @@ namespace Tesses::Framework::Streams {
{ {
delete buffer; delete buffer;
} }
void BufferedStream::Close()
{
this->strm->Close();
}
} }

View File

@@ -104,7 +104,10 @@ namespace Tesses::Framework::Streams
} }
FileStream::~FileStream() FileStream::~FileStream()
{ {
Close();
}
void FileStream::Close()
{
if(!f) return; if(!f) return;
if(this->owns) if(this->owns)
fclose(this->f); fclose(this->f);

View File

@@ -67,4 +67,8 @@ namespace Tesses::Framework::Streams
break; break;
} }
} }
void MemoryStream::Close()
{
this->buffer.clear();
}
} }

View File

@@ -771,10 +771,15 @@ namespace Tesses::Framework::Streams {
if(sz2 < 0) return 0; if(sz2 < 0) return 0;
return (size_t)sz2; return (size_t)sz2;
} }
NetworkStream::~NetworkStream() void NetworkStream::Close()
{ {
if(this->owns && this->success) if(this->owns && this->success)
NETWORK_CLOSE(this->sock); NETWORK_CLOSE(this->sock);
this->success=0;
}
NetworkStream::~NetworkStream()
{
Close();
} }
void NetworkStream::SetNoDelay(bool noDelay) void NetworkStream::SetNoDelay(bool noDelay)
{ {
@@ -888,6 +893,10 @@ NetworkStream::~NetworkStream()
void NetworkStream::SetNoDelay(bool noDelay) void NetworkStream::SetNoDelay(bool noDelay)
{ {
}
void NetworkStream::Close()
{
} }
uint16_t NetworkStream::GetPort() uint16_t NetworkStream::GetPort()
{ {

View File

@@ -122,6 +122,11 @@ namespace Tesses::Framework::Streams {
} }
PtyStream::~PtyStream() PtyStream::~PtyStream()
{ {
Close();
}
void PtyStream::Close()
{
if(this->eos) return;
this->eos=true; this->eos=true;
#if !defined(GEKKO) && !defined(__PS2__) && !defined(_WIN32) && !defined(__SWITCH__) && !defined(__FreeBSD__) && defined(TESSESFRAMEWORK_ENABLE_PROCESS) #if !defined(GEKKO) && !defined(__PS2__) && !defined(_WIN32) && !defined(__SWITCH__) && !defined(__FreeBSD__) && defined(TESSESFRAMEWORK_ENABLE_PROCESS)
close(this->socket); close(this->socket);

View File

@@ -91,6 +91,10 @@ namespace Tesses::Framework::Streams {
void Stream::Seek(int64_t pos, SeekOrigin whence) void Stream::Seek(int64_t pos, SeekOrigin whence)
{ {
}
void Stream::Close()
{
} }
void Stream::CopyTo(std::shared_ptr<Stream> strm, size_t buffSize) void Stream::CopyTo(std::shared_ptr<Stream> strm, size_t buffSize)