diff --git a/source/eventcore/driver.d b/source/eventcore/driver.d index 62410ea..794c58f 100644 --- a/source/eventcore/driver.d +++ b/source/eventcore/driver.d @@ -540,6 +540,9 @@ interface EventDriverFiles { */ bool isValid(FileFD handle) const @nogc; + /// Determines if the given file's reference count equals one. + bool isUnique(FileFD descriptor) const; + /** Increments the reference count of the given file. */ void addRef(FileFD descriptor); diff --git a/source/eventcore/drivers/threadedfile.d b/source/eventcore/drivers/threadedfile.d index 2e0663c..7dc85f9 100644 --- a/source/eventcore/drivers/threadedfile.d +++ b/source/eventcore/drivers/threadedfile.d @@ -417,6 +417,12 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents, Core : EventDriv return m_files[handle.value].validationCounter == handle.validationCounter; } + final override bool isUnique(FileFD handle) + const { + if (!isValid(handle)) return false; + return m_files[handle.value].refCount == 1; + } + final override void addRef(FileFD descriptor) { if (!isValid(descriptor)) return; diff --git a/source/eventcore/drivers/winapi/files.d b/source/eventcore/drivers/winapi/files.d index dcdd791..a00853f 100644 --- a/source/eventcore/drivers/winapi/files.d +++ b/source/eventcore/drivers/winapi/files.d @@ -309,6 +309,14 @@ final class WinAPIEventDriverFiles : EventDriverFiles { return false; } + override bool isUnique(FileFD handle) + const { + if (!isValid(handle)) return false; + if (auto ps = idToHandle(handle) in m_core.m_handles) + return ps.refCount == 1; + return false; + } + override void addRef(FileFD descriptor) { if (!isValid(descriptor)) return;