The short answer here is that for the iostream transport all of the run loop functionality is a stock boost asio io_service. You can look at the boost asio documentation for more detail about how it works. WebSocket++ endpoints using the asio transport wrap a number of the more commonly used io_service methods for convenience. You can also access the io_service directly or use an external io_service that you manage completely.
Some notes / tips about io_service use in WebSocket++
- stopped() will test whether or not the run loop has stopped / run out of work
- stop() will stop a running endpoint
- If an endpoint is stopped then all connections are/have been forcibly/uncleanly closed
- reset() will reset a stopped io_service and get it ready to call run() again. There is no other endpoint state that needs to be changed or reset.
- after calling reset() and before calling run() you will need to push at least one WebSocket operation into the endpoint. For servers this is usually listen(), for clients connect(). If you don't, run() will return immediately because it has nothing to do.
- Servers will listen forever. As of version 0.3.0-alpha3 there is no way to stop listening in a graceful way. This is functionality that I intend to add but haven't gotten to yet.
- There is no built in way to request that all connections cleanly close, you may keep a list of all connections and call endpoint::close on each of them and wait until all close handlers have been called. I have not decided whether this functionality should be provided by the library. In order to do so the library would need to keep a centrally managed data structure of all connections. This has performance and thread safety implications.
- You may add your own non-WebSocket++ tasks to the io_service.
For the workflow that you describe below you can either call reset(), connect(), then run() after each time or you can use another technique that keeps the io_service running even if it has no work to do. See the following article from the asio documentation for more details.:
At some point this functionality may be added to the library, but for now it can easily be done manually.
Peter