Partially implement FileDescriptorStream.

Currently only works for waiting on read-readiness (eventcore is not exposing an analog function for write-readiness).
This commit is contained in:
Sönke Ludwig 2017-05-30 11:02:22 +02:00
parent 99a5b882d8
commit 698824e811
No known key found for this signature in database
GPG key ID: D95E8DB493EE314C

View file

@ -940,13 +940,31 @@ struct FileDescriptorEvent {
any = read|write /// Match any kind of event any = read|write /// Match any kind of event
} }
@safe nothrow: private {
StreamSocketFD m_socket;
Trigger m_trigger;
}
@safe:
private this(int fd, Trigger event_mask) private this(int fd, Trigger event_mask)
{ nothrow {
assert(false); m_socket = eventDriver.sockets.adoptStream(fd);
} }
this(this)
nothrow {
if (m_socket != StreamSocketFD.invalid)
eventDriver.sockets.addRef(m_socket);
}
~this()
nothrow {
if (m_socket != StreamSocketFD.invalid)
eventDriver.sockets.releaseRef(m_socket);
}
/** Waits for the selected event to occur. /** Waits for the selected event to occur.
Params: Params:
@ -964,7 +982,18 @@ struct FileDescriptorEvent {
/// ditto /// ditto
bool wait(Duration timeout, Trigger which = Trigger.any) bool wait(Duration timeout, Trigger which = Trigger.any)
{ {
assert(false); if ((which & m_trigger) == Trigger.none) return true;
assert((which & m_trigger) == Trigger.read, "Waiting for write event not yet supported.");
Waitable!(IOCallback,
cb => eventDriver.sockets.waitForData(m_socket, cb),
(cb) { assert(false, "timeout not supported."); }
) readwaiter;
asyncAwaitAny!true(timeout, readwaiter);
return true;
} }
} }