VIbe-d fiber question
Tristan Brice Velloza Kildaire
deavmi at redxen.eu
Mon Mar 13 06:24:15 UTC 2023
I have a piece of server-side software I am writing using Vibed's
web socket support.
I initially setup an HTTP server of which listens on a given
port, with the provided `HTTPServerSettings`
```d
// Setup where to listen
this.httpSettings = new HTTPServerSettings();
httpSettings.port = bindPort;
httpSettings.bindAddresses = bindAddresses;
```
I then later continue to setup a handler for web socket
connections using:
```d
// Setup a websocket negotiater with a handler attached
this.websocketNegotiater = handleWebSockets(&websocketHandler);
```
Then lastly I attach the web socket handler to a given route
which must allow web socket connections to it:
```d
// Handle `/` as the web socket path
this.router = new URLRouter();
router.get("/", this.websocketNegotiater);
```
All of this is pretty stock-standard.
---
However, here is the snatch (and consequently where my question
comes in). Because we are accepting connections by virtue of a
web socket handler which is called on web socket connections to
the `/` route, I can obviously handle each client by doing some
work in a loop, then when I am done calling `this.yield()` where
`this` is a `Connection : Fiber` (custom type of mine), this then
saving the stack context, the instruction address etc. for later
resumption with `conn1.call()`.
My question though, is, if there is a way to hook a
`pre-connection-accept()` function in, because currently the only
way I am able to propgress the other fibers is by yieling away
from the websocket connection handler, loop through all the
current fibers and calling `.call()` on them - this works but
then after which I have to exit the `websocketHandler()` method
such that the code can progress to the processing of any possible
new connections - but in such a case where there are none I
effectively hang on waiting for such an event instead of doing
something along the lines of:
```d
if(noNewConnections)
{
// Loop through all fibers and .call them
}
else
{
// Process new connection as per `websocketHandler()`
}
```
---
I hope I made my problem/scenario clear and would be interested
to hear what you guys have to say.
More information about the Digitalmars-d
mailing list