On Wed, 21 Feb 2018 13:01:20 GMT, gallafrancesco wrote:

We have another question regarding this specification in the wiki:

support letting a connection "sleep" (no task allocated while waiting for the next request)

For this reason we were thinking of an event based approach that leverages the existing listenTCP function that currently states:

  • 'connection_callback' will be called for each client that connects to the server socket. Each new connection gets its own fiber. The stream parameter then allows to perform blocking I/O on the client socket.

If the callback can be called every time the socket is triggered (instead of just "new connection event") there is no need to keep a task allocated while waiting for new data.
This means exposing an API to add events to the event loop or adding every socket that gets accepted to the event loop and removing it accordingly.

Do you think this is the right approach? Did you have something else in mind?

What I had in mind was a new method TCPConnection.waitForDataAsync(void delegate(bool)) that would work just like waitForData, just that it doesn't call asyncAwaitAny, but instead directly calls eventDriver.sockets.read and performs the rest of the functionality from the passed callback (which would be called as runTask(callback, ...)).

With this, the connection handler could then simply call waitForDataAsync after handling all immediately available requests and can then return to the caller immediately. The internal reference counting should make sure that the connection stays alive as long as necessary.

This would only be implemented for vibe-core, we don't have to care for backwards compatibility with vibe-d:core.