Worker-side handler for Controller<>Worker network API
We currently want the Worker to run a server and the Controller to connect to the worker (rather than the other way around). This is desirable during development, because it means we can iterate on controller design without having to tear down workers.
Implement a server for the worker side of the Controller<>Worker network API.
The implementation will resemble the example server in worker_net.cpp.
As in the example server, it will contain a server and a connection class:
Server:
- A tcp server, similar to
tcp_server
, that accepts connections. For now, the server will only maintain a single active connection. If a new connection is accepted, the old connection must be destroyed. - The tcp server maintains the queue of outgoing responses. If nobody is connected, then the queue just accumulates responses. If a new connection is established, queued responses get sent. (See #4 (closed) )
- The tcp server implements the
workerapi::Controller
interface. WhensendResults
is called, a response message is created and added to the outgoing response queue. - The tcp server internally has a thread to run the IO service, in a similar way to the logic in
main
in theworker_net
example. The thread will need a way to initiate an orderly shutdown.
Connection:
- Similar to
clockwork_server_conn
in theworker_net
example. A connection receives messages off the network from a connected client. - The connection's constructor should receive the request queue from the tcp server, as well as a
workerapi::Worker
argument. - When an action is received off the network, the worker's
sendActions
method will be called. Actions are only ever received one-at-a-time, sosendActions
will only receive a vector with a single action in it.
Edited by Jonathan Mace