Merge pull request #97 from vibe-d/struct_handles

Define handles as properly named structs.
merged-on-behalf-of: Sönke Ludwig <s-ludwig@users.noreply.github.com>
This commit is contained in:
The Dlang Bot 2018-12-28 10:08:23 +01:00 committed by GitHub
commit 110030a4f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -789,14 +789,15 @@ struct FileChange {
bool isDirectory; bool isDirectory;
} }
struct Handle(string NAME, T, T invalid_value = T.init) { mixin template Handle(string NAME, T, T invalid_value = T.init) {
import std.traits : isInstanceOf; static if (is(T.BaseType)) alias BaseType = T.BaseType;
static if (isInstanceOf!(.Handle, T)) alias BaseType = T.BaseType;
else alias BaseType = T; else alias BaseType = T;
alias name = NAME; alias name = NAME;
enum invalid = Handle.init; enum invalid = typeof(this).init;
nothrow @nogc @safe:
T value = invalid_value; T value = invalid_value;
@ -817,15 +818,15 @@ struct Handle(string NAME, T, T invalid_value = T.init) {
alias ThreadCallback = void function(intptr_t param) @safe nothrow; alias ThreadCallback = void function(intptr_t param) @safe nothrow;
alias FD = Handle!("fd", size_t, size_t.max); struct FD { mixin Handle!("fd", size_t, size_t.max); }
alias SocketFD = Handle!("socket", FD); struct SocketFD { mixin Handle!("socket", FD); }
alias StreamSocketFD = Handle!("streamSocket", SocketFD); struct StreamSocketFD { mixin Handle!("streamSocket", SocketFD); }
alias StreamListenSocketFD = Handle!("streamListen", SocketFD); struct StreamListenSocketFD { mixin Handle!("streamListen", SocketFD); }
alias DatagramSocketFD = Handle!("datagramSocket", SocketFD); struct DatagramSocketFD { mixin Handle!("datagramSocket", SocketFD); }
alias FileFD = Handle!("file", FD); struct FileFD { mixin Handle!("file", FD); }
alias EventID = Handle!("event", FD); struct EventID { mixin Handle!("event", FD); }
alias TimerID = Handle!("timer", size_t, size_t.max); struct TimerID { mixin Handle!("timer", size_t, size_t.max); }
alias WatcherID = Handle!("watcher", size_t, size_t.max); struct WatcherID { mixin Handle!("watcher", size_t, size_t.max); }
alias EventWaitID = Handle!("eventWait", size_t, size_t.max); struct EventWaitID { mixin Handle!("eventWait", size_t, size_t.max); }
alias SignalListenID = Handle!("signal", size_t, size_t.max); struct SignalListenID { mixin Handle!("signal", size_t, size_t.max); }
alias DNSLookupID = Handle!("dns", size_t, size_t.max); struct DNSLookupID { mixin Handle!("dns", size_t, size_t.max); }