InterviewSolution
| 1. |
How Do I Negotiate Subprotocols? |
|
Answer» The Asio transport based clients and servers use the Asio LIBRARY's underlying io_service to handle asyncronous networking OPERATIONS. The standard behavior of the io_service is to run until there are no async operations left and then return. WebSocket++, when using the Asio transport, behaves like a standard Asio application. If you want your WebSocket++/Asio based program to stop network operations and cleanly close all sockets you will want to do the following:
WARNING: Asio's io_service has a method called stop. WebSocket++ wraps this method as websocketpp::transport::asio::endpoint::stop. While this operation has a benign sounding name, it is a powerful and destructive operation that should only be used in special cases. If you are using io_service::stop or endpoint::stop without a very good reason your program is likely BROKEN and may exhibit erratic behavior. SPECIFICALLY, io_service::stop stops the processing of events entirely. This does not give current operations (such as socket closing handshakes) the opportunity to finish. It will leave your sockets in a dangling state that may invoke operating system level timeouts or other errors. The Asio transport based clients and servers use the Asio library's underlying io_service to handle asyncronous networking operations. The standard behavior of the io_service is to run until there are no async operations left and then return. WebSocket++, when using the Asio transport, behaves like a standard Asio application. If you want your WebSocket++/Asio based program to stop network operations and cleanly close all sockets you will want to do the following: WARNING: Asio's io_service has a method called stop. WebSocket++ wraps this method as websocketpp::transport::asio::endpoint::stop. While this operation has a benign sounding name, it is a powerful and destructive operation that should only be used in special cases. If you are using io_service::stop or endpoint::stop without a very good reason your program is likely broken and may exhibit erratic behavior. Specifically, io_service::stop stops the processing of events entirely. This does not give current operations (such as socket closing handshakes) the opportunity to finish. It will leave your sockets in a dangling state that may invoke operating system level timeouts or other errors. |
|