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
// 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:
// 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:
// 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:
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.