Remove redundancies from API function names.

This commit is contained in:
Sönke Ludwig 2016-10-05 14:09:51 +02:00
parent 80ce62aacb
commit b95c9e5bbc
7 changed files with 149 additions and 125 deletions

View file

@ -89,7 +89,7 @@ struct StreamConnectionImpl {
@property bool empty() @property bool empty()
{ {
reader.start(); reader.start();
eventDriver.sockets.waitSocketData(m_socket, &onData); eventDriver.sockets.waitForData(m_socket, &onData);
reader.wait(); reader.wait();
return m_empty; return m_empty;
} }
@ -98,7 +98,7 @@ struct StreamConnectionImpl {
{ {
reader.start(); reader.start();
if (m_readBufferFill >= 2) onReadLineData(m_socket, IOStatus.ok, 0); if (m_readBufferFill >= 2) onReadLineData(m_socket, IOStatus.ok, 0);
else eventDriver.sockets.readSocket(m_socket, m_readBuffer[m_readBufferFill .. $], IOMode.once, &onReadLineData); else eventDriver.sockets.read(m_socket, m_readBuffer[m_readBufferFill .. $], IOMode.once, &onReadLineData);
reader.wait(); reader.wait();
auto ln = m_line; auto ln = m_line;
m_line = null; m_line = null;
@ -108,7 +108,7 @@ struct StreamConnectionImpl {
void write(const(ubyte)[] data) void write(const(ubyte)[] data)
{ {
writer.start(); writer.start();
eventDriver.sockets.writeSocket(m_socket, data, IOMode.all, &onWrite); eventDriver.sockets.write(m_socket, data, IOMode.all, &onWrite);
writer.wait(); writer.wait();
} }
@ -160,7 +160,7 @@ struct StreamConnectionImpl {
reader.finish(); reader.finish();
} else if (m_readBuffer.length - m_readBufferFill > 0) { } else if (m_readBuffer.length - m_readBufferFill > 0) {
eventDriver.sockets.readSocket(m_socket, m_readBuffer[m_readBufferFill .. $], IOMode.once, &onReadLineData); eventDriver.sockets.read(m_socket, m_readBuffer[m_readBufferFill .. $], IOMode.once, &onReadLineData);
} else { } else {
reader.finish(exh); reader.finish(exh);
} }

View file

@ -49,7 +49,7 @@ struct ClientHandler {
{ {
onLine = on_line; onLine = on_line;
if (linefill >= 2) onReadData(client, IOStatus.ok, 0); if (linefill >= 2) onReadData(client, IOStatus.ok, 0);
else eventDriver.sockets.readSocket(client, linebuf[linefill .. $], IOMode.once, &onReadData); else eventDriver.sockets.read(client, linebuf[linefill .. $], IOMode.once, &onReadData);
} }
void onRequestLine(ubyte[] ln) void onRequestLine(ubyte[] ln)
@ -57,7 +57,7 @@ struct ClientHandler {
//print("Request: %s", cast(char[])ln); //print("Request: %s", cast(char[])ln);
if (ln.length == 0) { if (ln.length == 0) {
//print("Error: empty request line"); //print("Error: empty request line");
eventDriver.sockets.shutdownSocket(client); eventDriver.sockets.shutdown(client);
eventDriver.sockets.releaseRef(client); eventDriver.sockets.releaseRef(client);
} }
@ -68,7 +68,7 @@ struct ClientHandler {
{ {
if (ln.length == 0) { if (ln.length == 0) {
auto reply = cast(const(ubyte)[])"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 13\r\nKeep-Alive: timeout=10\r\n\r\nHello, World!"; auto reply = cast(const(ubyte)[])"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 13\r\nKeep-Alive: timeout=10\r\n\r\nHello, World!";
eventDriver.sockets.writeSocket(client, reply, IOMode.all, &onWriteFinished); eventDriver.sockets.write(client, reply, IOMode.all, &onWriteFinished);
} else readLine(&onHeaderLine); } else readLine(&onHeaderLine);
} }
@ -83,7 +83,7 @@ struct ClientHandler {
if (status != IOStatus.ok) { if (status != IOStatus.ok) {
print("Client disconnect"); print("Client disconnect");
eventDriver.sockets.shutdownSocket(client); eventDriver.sockets.shutdown(client);
eventDriver.sockets.releaseRef(client); eventDriver.sockets.releaseRef(client);
return; return;
} }
@ -102,11 +102,11 @@ struct ClientHandler {
onLine(linebuf[linefill + idx + 2 .. linefill + idx + 2 + idx]); onLine(linebuf[linefill + idx + 2 .. linefill + idx + 2 + idx]);
} else if (linebuf.length - linefill > 0) { } else if (linebuf.length - linefill > 0) {
eventDriver.sockets.readSocket(client, linebuf[linefill .. $], IOMode.once, &onReadData); eventDriver.sockets.read(client, linebuf[linefill .. $], IOMode.once, &onReadData);
} else { } else {
// ERROR: header line too long // ERROR: header line too long
print("Header line too long"); print("Header line too long");
eventDriver.sockets.shutdownSocket(client); eventDriver.sockets.shutdown(client);
eventDriver.sockets.releaseRef(client); eventDriver.sockets.releaseRef(client);
} }
} }

View file

@ -10,7 +10,7 @@ interface EventDriver {
@property EventDriverCore core(); @property EventDriverCore core();
@property EventDriverFiles files(); @property EventDriverFiles files();
@property EventDriverSockets sockets(); @property EventDriverSockets sockets();
@property EventDriverTimers udp(); @property EventDriverTimers timers();
@property EventDriverEvents events(); @property EventDriverEvents events();
@property EventDriverSignals signals(); @property EventDriverSignals signals();
@property EventDriverWatchers watchers(); @property EventDriverWatchers watchers();
@ -80,6 +80,18 @@ interface EventDriverCore {
interface EventDriverSockets { interface EventDriverSockets {
@safe: /*@nogc:*/ nothrow: @safe: /*@nogc:*/ nothrow:
StreamSocketFD connectStream(scope Address peer_address, ConnectCallback on_connect);
StreamListenSocketFD listenStream(scope Address bind_address, AcceptCallback on_accept);
void waitForConnections(StreamListenSocketFD sock, AcceptCallback on_accept);
ConnectionState getConnectionState(StreamSocketFD sock);
void setTCPNoDelay(StreamSocketFD socket, bool enable);
void read(StreamSocketFD socket, ubyte[] buffer, IOMode mode, IOCallback on_read_finish);
void write(StreamSocketFD socket, const(ubyte)[] buffer, IOMode mode, IOCallback on_write_finish);
void waitForData(StreamSocketFD socket, IOCallback on_data_available);
void shutdown(StreamSocketFD socket, bool shut_read = true, bool shut_write = true);
void cancelRead(StreamSocketFD socket);
void cancelWrite(StreamSocketFD socket);
/** /**
Increments the reference count of the given resource. Increments the reference count of the given resource.
*/ */
@ -91,22 +103,17 @@ interface EventDriverSockets {
freed and the resource descriptor gets invalidated. freed and the resource descriptor gets invalidated.
*/ */
void releaseRef(SocketFD descriptor); void releaseRef(SocketFD descriptor);
StreamSocketFD connectStream(scope Address peer_address, ConnectCallback on_connect);
StreamListenSocketFD listenStream(scope Address bind_address, AcceptCallback on_accept);
void waitForConnections(StreamListenSocketFD sock, AcceptCallback on_accept);
ConnectionState getConnectionState(StreamSocketFD sock);
void setTCPNoDelay(StreamSocketFD socket, bool enable);
void readSocket(StreamSocketFD socket, ubyte[] buffer, IOMode mode, IOCallback on_read_finish);
void writeSocket(StreamSocketFD socket, const(ubyte)[] buffer, IOMode mode, IOCallback on_write_finish);
void waitSocketData(StreamSocketFD socket, IOCallback on_data_available);
void shutdownSocket(StreamSocketFD socket, bool shut_read = true, bool shut_write = true);
void cancelRead(StreamSocketFD socket);
void cancelWrite(StreamSocketFD socket);
} }
interface EventDriverFiles { interface EventDriverFiles {
@safe: /*@nogc:*/ nothrow: @safe: /*@nogc:*/ nothrow:
FileFD open(string path, FileOpenMode mode);
FileFD createTemp();
void write(FileFD file, ulong offset, ubyte[] buffer, IOCallback on_write_finish);
void read(FileFD file, ulong offset, ubyte[] buffer, IOCallback on_read_finish);
void cancelWrite(FileFD file);
void cancelRead(FileFD file);
/** /**
Increments the reference count of the given resource. Increments the reference count of the given resource.
*/ */
@ -118,17 +125,16 @@ interface EventDriverFiles {
freed and the resource descriptor gets invalidated. freed and the resource descriptor gets invalidated.
*/ */
void releaseRef(FileFD descriptor); void releaseRef(FileFD descriptor);
FileFD openFile(string path, FileOpenMode mode);
FileFD createTempFile();
void write(FileFD file, ulong offset, ubyte[] buffer, IOCallback on_write_finish);
void read(FileFD file, ulong offset, ubyte[] buffer, IOCallback on_read_finish);
void cancelWrite(FileFD file);
void cancelRead(FileFD file);
} }
interface EventDriverEvents { interface EventDriverEvents {
@safe: /*@nogc:*/ nothrow: @safe: /*@nogc:*/ nothrow:
EventID create();
void trigger(EventID event, bool notify_all = true);
void trigger(EventID event, bool notify_all = true) shared;
void wait(EventID event, EventCallback on_event);
void cancelWait(EventID event, EventCallback on_event);
/** /**
Increments the reference count of the given resource. Increments the reference count of the given resource.
*/ */
@ -140,22 +146,24 @@ interface EventDriverEvents {
freed and the resource descriptor gets invalidated. freed and the resource descriptor gets invalidated.
*/ */
void releaseRef(EventID descriptor); void releaseRef(EventID descriptor);
EventID createEvent();
void triggerEvent(EventID event, bool notify_all = true);
void triggerEvent(EventID event, bool notify_all = true) shared;
void waitForEvent(EventID event, EventCallback on_event);
void cancelWaitForEvent(EventID event, EventCallback on_event);
} }
interface EventDriverSignals { interface EventDriverSignals {
@safe: /*@nogc:*/ nothrow: @safe: /*@nogc:*/ nothrow:
void waitForSignal(int sig, SignalCallback on_signal); void wait(int sig, SignalCallback on_signal);
void cancelWaitForSignal(int sig); void cancelWait(int sig);
} }
interface EventDriverTimers { interface EventDriverTimers {
@safe: /*@nogc:*/ nothrow: @safe: /*@nogc:*/ nothrow:
TimerID create();
void set(TimerID timer, Duration timeout, Duration repeat = Duration.zero);
void stop(TimerID timer);
bool isPending(TimerID timer);
bool isPeriodic(TimerID timer);
void wait(TimerID timer, TimerCallback callback);
void cancelWait(TimerID timer, TimerCallback callback);
/** /**
Increments the reference count of the given resource. Increments the reference count of the given resource.
*/ */
@ -167,21 +175,25 @@ interface EventDriverTimers {
freed and the resource descriptor gets invalidated. freed and the resource descriptor gets invalidated.
*/ */
void releaseRef(TimerID descriptor); void releaseRef(TimerID descriptor);
TimerID createTimer();
void setTimer(TimerID timer, Duration timeout, Duration repeat = Duration.zero);
void stopTimer(TimerID timer);
bool isTimerPending(TimerID timer);
bool isTimerPeriodic(TimerID timer);
void waitTimer(TimerID timer, TimerCallback callback);
void cancelTimerWait(TimerID timer, TimerCallback callback);
} }
interface EventDriverWatchers { interface EventDriverWatchers {
@safe: /*@nogc:*/ nothrow: @safe: /*@nogc:*/ nothrow:
WatcherID watchDirectory(string path, bool recursive); WatcherID watchDirectory(string path, bool recursive);
void waitForChanges(WatcherID watcher, FileChangesCallback callback); void wait(WatcherID watcher, FileChangesCallback callback);
void cancelWaitForChanges(WatcherID watcher); void cancelWait(WatcherID watcher);
/**
Increments the reference count of the given resource.
*/
void addRef(WatcherID descriptor);
/**
Decrements the reference count of the given resource.
Once the reference count reaches zero, all associated resources will be
freed and the resource descriptor gets invalidated.
*/
void releaseRef(WatcherID descriptor);
} }

View file

@ -33,7 +33,7 @@ final class EpollEventDriver : PosixEventDriver {
override @property EpollEventDriver core() { return this; } override @property EpollEventDriver core() { return this; }
override @property EpollEventDriver files() { return this; } override @property EpollEventDriver files() { return this; }
override @property EpollEventDriver sockets() { return this; } override @property EpollEventDriver sockets() { return this; }
override @property EpollEventDriver udp() { return this; } override @property EpollEventDriver timers() { return this; }
override @property EpollEventDriver events() { return this; } override @property EpollEventDriver events() { return this; }
override @property EpollEventDriver signals() { return this; } override @property EpollEventDriver signals() { return this; }
override @property EpollEventDriver watchers() { return this; } override @property EpollEventDriver watchers() { return this; }

View file

@ -61,7 +61,7 @@ abstract class PosixEventDriver : EventDriver,
abstract override @property PosixEventDriver core(); abstract override @property PosixEventDriver core();
abstract override @property PosixEventDriver files(); abstract override @property PosixEventDriver files();
abstract override @property PosixEventDriver sockets(); abstract override @property PosixEventDriver sockets();
abstract override @property PosixEventDriver udp(); abstract override @property PosixEventDriver timers();
abstract override @property PosixEventDriver events(); abstract override @property PosixEventDriver events();
abstract override @property PosixEventDriver signals(); abstract override @property PosixEventDriver signals();
abstract override @property PosixEventDriver watchers(); abstract override @property PosixEventDriver watchers();
@ -244,7 +244,7 @@ abstract class PosixEventDriver : EventDriver,
() @trusted { setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, cast(char*)&opt, opt.sizeof); } (); () @trusted { setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, cast(char*)&opt, opt.sizeof); } ();
} }
final override void readSocket(StreamSocketFD socket, ubyte[] buffer, IOMode mode, IOCallback on_read_finish) final override void read(StreamSocketFD socket, ubyte[] buffer, IOMode mode, IOCallback on_read_finish)
{ {
if (buffer.length == 0) { if (buffer.length == 0) {
on_read_finish(socket, IOStatus.ok, 0); on_read_finish(socket, IOStatus.ok, 0);
@ -340,7 +340,7 @@ abstract class PosixEventDriver : EventDriver,
} }
} }
final override void writeSocket(StreamSocketFD socket, const(ubyte)[] buffer, IOMode mode, IOCallback on_write_finish) final override void write(StreamSocketFD socket, const(ubyte)[] buffer, IOMode mode, IOCallback on_write_finish)
{ {
if (buffer.length == 0) { if (buffer.length == 0) {
on_write_finish(socket, IOStatus.ok, 0); on_write_finish(socket, IOStatus.ok, 0);
@ -432,7 +432,7 @@ abstract class PosixEventDriver : EventDriver,
} }
} }
final override void waitSocketData(StreamSocketFD socket, IOCallback on_data_available) final override void waitForData(StreamSocketFD socket, IOCallback on_data_available)
{ {
sizediff_t ret; sizediff_t ret;
ubyte dummy; ubyte dummy;
@ -489,17 +489,35 @@ abstract class PosixEventDriver : EventDriver,
} else finalize(ret ? IOStatus.ok : IOStatus.disconnected); } else finalize(ret ? IOStatus.ok : IOStatus.disconnected);
} }
final override void shutdownSocket(StreamSocketFD socket, bool shut_read, bool shut_write) final override void shutdown(StreamSocketFD socket, bool shut_read, bool shut_write)
{ {
// TODO! // TODO!
} }
final override FileFD openFile(string path, FileOpenMode mode) final override void addRef(SocketFD fd)
{
auto pfd = &m_fds[fd];
assert(pfd.refCount > 0, "Adding reference to unreferenced socket FD.");
m_fds[fd].refCount++;
}
final override void releaseRef(SocketFD fd)
{
auto pfd = &m_fds[fd];
assert(pfd.refCount > 0, "Releasing reference to unreferenced socket FD.");
if (--m_fds[fd].refCount == 0) {
unregisterFD(fd);
clearFD(fd);
closeSocket(fd);
}
}
final override FileFD open(string path, FileOpenMode mode)
{ {
assert(false, "TODO!"); assert(false, "TODO!");
} }
final override FileFD createTempFile() final override FileFD createTemp()
{ {
assert(false, "TODO!"); assert(false, "TODO!");
} }
@ -524,7 +542,18 @@ abstract class PosixEventDriver : EventDriver,
assert(false, "TODO!"); assert(false, "TODO!");
} }
final override EventID createEvent() final override void addRef(FileFD descriptor)
{
assert(false);
}
final override void releaseRef(FileFD descriptor)
{
assert(false);
}
final override EventID create()
{ {
auto id = cast(EventID)eventfd(0, EFD_NONBLOCK); auto id = cast(EventID)eventfd(0, EFD_NONBLOCK);
initFD(id); initFD(id);
@ -534,7 +563,7 @@ abstract class PosixEventDriver : EventDriver,
return id; return id;
} }
final override void triggerEvent(EventID event, bool notify_all = true) final override void trigger(EventID event, bool notify_all = true)
{ {
assert(event < m_fds.length, "Invalid event ID passed to triggerEvent."); assert(event < m_fds.length, "Invalid event ID passed to triggerEvent.");
if (notify_all) { if (notify_all) {
@ -549,7 +578,7 @@ abstract class PosixEventDriver : EventDriver,
} }
} }
final override void triggerEvent(EventID event, bool notify_all = true) final override void trigger(EventID event, bool notify_all = true)
shared @trusted { shared @trusted {
import core.atomic : atomicStore; import core.atomic : atomicStore;
auto thisus = cast(PosixEventDriver)this; auto thisus = cast(PosixEventDriver)this;
@ -560,13 +589,13 @@ abstract class PosixEventDriver : EventDriver,
() @trusted { .write(event, &one, one.sizeof); } (); () @trusted { .write(event, &one, one.sizeof); } ();
} }
final override void waitForEvent(EventID event, EventCallback on_event) final override void wait(EventID event, EventCallback on_event)
{ {
assert(event < m_fds.length, "Invalid event ID passed to waitForEvent."); assert(event < m_fds.length, "Invalid event ID passed to waitForEvent.");
return m_fds[event].waiters.put(on_event); return m_fds[event].waiters.put(on_event);
} }
final override void cancelWaitForEvent(EventID event, EventCallback on_event) final override void cancelWait(EventID event, EventCallback on_event)
{ {
import std.algorithm.searching : countUntil; import std.algorithm.searching : countUntil;
import std.algorithm.mutation : remove; import std.algorithm.mutation : remove;
@ -581,44 +610,7 @@ abstract class PosixEventDriver : EventDriver,
() @trusted { .read(event, &cnt, cnt.sizeof); } (); () @trusted { .read(event, &cnt, cnt.sizeof); } ();
import core.atomic : cas; import core.atomic : cas;
auto all = cas(&m_fds[event].triggerAll, true, false); auto all = cas(&m_fds[event].triggerAll, true, false);
triggerEvent(cast(EventID)event, all); trigger(cast(EventID)event, all);
}
final override void waitForSignal(int sig, SignalCallback on_signal)
{
assert(false, "TODO!");
}
final override void cancelWaitForSignal(int sig)
{
assert(false, "TODO!");
}
final override WatcherID watchDirectory(string path, bool recursive)
{
assert(false, "TODO!");
}
final override void waitForChanges(WatcherID watcher, FileChangesCallback callback)
{
assert(false, "TODO!");
}
final override void cancelWaitForChanges(WatcherID watcher)
{
assert(false, "TODO!");
}
final override void addRef(SocketFD fd)
{
auto pfd = &m_fds[fd];
assert(pfd.refCount > 0, "Adding reference to unreferenced socket FD.");
m_fds[fd].refCount++;
}
final override void addRef(FileFD descriptor)
{
assert(false);
} }
final override void addRef(EventID descriptor) final override void addRef(EventID descriptor)
@ -628,22 +620,6 @@ abstract class PosixEventDriver : EventDriver,
m_fds[descriptor].refCount++; m_fds[descriptor].refCount++;
} }
final override void releaseRef(SocketFD fd)
{
auto pfd = &m_fds[fd];
assert(pfd.refCount > 0, "Releasing reference to unreferenced socket FD.");
if (--m_fds[fd].refCount == 0) {
unregisterFD(fd);
clearFD(fd);
closeSocket(fd);
}
}
final override void releaseRef(FileFD descriptor)
{
assert(false);
}
final override void releaseRef(EventID descriptor) final override void releaseRef(EventID descriptor)
{ {
auto pfd = &m_fds[descriptor]; auto pfd = &m_fds[descriptor];
@ -655,6 +631,42 @@ abstract class PosixEventDriver : EventDriver,
} }
} }
final override void wait(int sig, SignalCallback on_signal)
{
assert(false, "TODO!");
}
final override void cancelWait(int sig)
{
assert(false, "TODO!");
}
final override WatcherID watchDirectory(string path, bool recursive)
{
assert(false, "TODO!");
}
final override void wait(WatcherID watcher, FileChangesCallback callback)
{
assert(false, "TODO!");
}
final override void cancelWait(WatcherID watcher)
{
assert(false, "TODO!");
}
final override void addRef(WatcherID descriptor)
{
assert(false, "TODO!");
}
final override void releaseRef(WatcherID descriptor)
{
assert(false, "TODO!");
}
final override void* rawUserData(StreamSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy) final override void* rawUserData(StreamSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy)
@system { @system {
FDSlot* fds = &m_fds[descriptor]; FDSlot* fds = &m_fds[descriptor];

View file

@ -27,7 +27,7 @@ final class SelectEventDriver : PosixEventDriver {
override @property SelectEventDriver core() { return this; } override @property SelectEventDriver core() { return this; }
override @property SelectEventDriver files() { return this; } override @property SelectEventDriver files() { return this; }
override @property SelectEventDriver sockets() { return this; } override @property SelectEventDriver sockets() { return this; }
override @property SelectEventDriver udp() { return this; } override @property SelectEventDriver timers() { return this; }
override @property SelectEventDriver events() { return this; } override @property SelectEventDriver events() { return this; }
override @property SelectEventDriver signals() { return this; } override @property SelectEventDriver signals() { return this; }
override @property SelectEventDriver watchers() { return this; } override @property SelectEventDriver watchers() { return this; }

View file

@ -70,7 +70,7 @@ mixin template DefaultTimerImpl() {
return any_fired; return any_fired;
} }
final override TimerID createTimer() final override TimerID create()
@trusted { @trusted {
auto id = cast(TimerID)(++m_lastTimerID); auto id = cast(TimerID)(++m_lastTimerID);
TimerSlot* tm; TimerSlot* tm;
@ -83,11 +83,11 @@ mixin template DefaultTimerImpl() {
return id; return id;
} }
final override void setTimer(TimerID timer, Duration timeout, Duration repeat) final override void set(TimerID timer, Duration timeout, Duration repeat)
@trusted { @trusted {
scope (failure) assert(false); scope (failure) assert(false);
auto tm = m_timers[timer]; auto tm = m_timers[timer];
if (tm.pending) stopTimer(timer); if (tm.pending) stop(timer);
tm.timeout = Clock.currStdTime + timeout.total!"hnsecs"; tm.timeout = Clock.currStdTime + timeout.total!"hnsecs";
tm.repeatDuration = repeat.total!"hnsecs"; tm.repeatDuration = repeat.total!"hnsecs";
tm.pending = true; tm.pending = true;
@ -97,7 +97,7 @@ mixin template DefaultTimerImpl() {
catch (Exception e) { print("Failed to insert timer: %s", e.msg); } catch (Exception e) { print("Failed to insert timer: %s", e.msg); }
} }
final override void stopTimer(TimerID timer) final override void stop(TimerID timer)
@trusted { @trusted {
auto tm = m_timers[timer]; auto tm = m_timers[timer];
if (!tm.pending) return; if (!tm.pending) return;
@ -118,22 +118,22 @@ mixin template DefaultTimerImpl() {
} }
} }
final override bool isTimerPending(TimerID descriptor) final override bool isPending(TimerID descriptor)
{ {
return m_timers[descriptor].pending; return m_timers[descriptor].pending;
} }
final override bool isTimerPeriodic(TimerID descriptor) final override bool isPeriodic(TimerID descriptor)
{ {
return m_timers[descriptor].repeatDuration > 0; return m_timers[descriptor].repeatDuration > 0;
} }
final override void waitTimer(TimerID timer, TimerCallback callback) final override void wait(TimerID timer, TimerCallback callback)
{ {
m_timers[timer].callbacks ~= callback; m_timers[timer].callbacks ~= callback;
} }
final override void cancelTimerWait(TimerID timer, TimerCallback callback) final override void cancelWait(TimerID timer, TimerCallback callback)
{ {
import std.algorithm.mutation : remove; import std.algorithm.mutation : remove;
import std.algorithm.searching : countUntil; import std.algorithm.searching : countUntil;
@ -160,7 +160,7 @@ mixin template DefaultTimerImpl() {
auto tm = m_timers[descriptor]; auto tm = m_timers[descriptor];
if (!--tm.refCount) { if (!--tm.refCount) {
if (tm.pending) stopTimer(tm.id); if (tm.pending) stop(tm.id);
m_timers.remove(descriptor); m_timers.remove(descriptor);
() @trusted { scope (failure) assert(false); ms_allocator.dispose(tm); } (); () @trusted { scope (failure) assert(false); ms_allocator.dispose(tm); } ();
} }