This project is just for me to experiment with Boost Asio and Boost Beast.
Here are some self-imposed 'rules' that I think are worth abiding by when it comes to Boost Asio/Beast.
- Model different async objects as finite state machines. Each state is a completion handler for an async operation, and when performed, launches other async calls.
- State completion handlers should not throw exceptions. When something bad happens, it's probably useful to log it somewhere, and then the object can destroy itself by simply not transitioning to a new state.
- There is an interesting distinction between objects which expose some async APIs (in this case,
server::Server
andwebsocket::Session
) and those which don't. Those which don't can often be represented usingstd::unique_ptr
, and basically have no function other thanmake_and_run
. Those which do will probably have to be represented using astd::shared_ptr
, and will need to serialise their operations via astrand
(as the async ops could be called from anywhere.) Moreover, these are the only objects which will need to return themselves frommake_and_run
. - How to bring async testing into this? We'll probably need template parameters for all stream/connection-like objects. Doing this is probably quite intrusive, but very useful and necessary.