Remove EventDriverFiles.createTemp() and add adopt() instead.

The rationale is to keep the event loop abstraction at a minimal size. createTemp(), to be generally useful, would also require a getFilename(fd) method and possibly more. adopt() on the other hand is frequently useful for wrapping other libraries.
This commit is contained in:
Sönke Ludwig 2016-12-10 15:59:03 +01:00
parent de89a5a9e1
commit 7e9031439c
2 changed files with 9 additions and 4 deletions

View file

@ -119,7 +119,7 @@ interface EventDriverDNS {
interface EventDriverFiles {
@safe: /*@nogc:*/ nothrow:
FileFD open(string path, FileOpenMode mode);
FileFD createTemp();
FileFD adopt(int system_file_handle);
void close(FileFD file);
ulong getSize(FileFD file);

View file

@ -142,12 +142,17 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents) : EventDriverFil
}
auto fd = () @trusted { return .open(path.toStringz(), flags, amode); } ();
if (fd < 0) return FileFD.init;
return FileFD(fd);
return adopt(fd);
}
final override FileFD createTemp()
final override FileFD adopt(int system_file_handle)
{
assert(false, "TODO!");
auto flags = () @trusted { return fcntl(system_file_handle, F_GETFD); } ();
if (flags == -1) return FileFD.invalid;
if (m_files[system_file_handle].refCount > 0) return FileFD.invalid;
m_files[system_file_handle] = FileInfo.init;
m_files[system_file_handle].refCount = 1;
return FileFD(system_file_handle);
}
void close(FileFD file)