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:
parent
de89a5a9e1
commit
7e9031439c
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue