Hi,

I am trying to build the networking part of my application around vibe.d, given that the support for concurrency has been added, but I am having some issues. Perhaps some of you can help me with it...

What I want to achieve is to have a single server class that takes care of all the networking needs, i.e.
1) on request, it starts to listen on given addresses and ports
2) on request, it ceases to listen
3) on request, terminates some or all active connections
4) each accepted connection can do the request processing in the context of a fiber or serialize the request and send it to another thread for processing and wait until it is finished

For 1), let's say I have this code:

class Server {
  private void _listeningFn()
  {
    ...                                                                                       
  }
  
  public void run(string address, uint port)
  {
    _listeningThread = runTask(&_listeningFn);
  }
}

Given that runTask takes void delegate() as a parameter, what is the most appropriate way to pass the address and the port, so that the _listeningFn can use it?

  • set it as a Server variable and let the function use it?
  • pass it via send/receive mechanism of Task?
  • use task-local storage?

For 2), if I weren't using vibe.d, I would create connected socket that would be used to interrupt the select call. What should I do here? Create a connection that would trigger processing in _listeningFn and special-case it so that it breaks out of listening loop?

For 3), is there a way to signal to given/all connections that I want them to end, thus breaking them of their reads?

For 4), would this be a proper way to execute the work in some other thread?

{
  ...
  auto workerThread = spawn(&workerFn, getThis);
  workerThread.send(serializedData);
  receive(//wait for workerThread to finish its job)
}

The docs says that Tid is an alias for Task. Can I supply spawned function with Task and be able to receive properly from other thread?

Many thanks for reading this far.

Regards,
Martin