#include <Pt/Http/WebSocketServlet.h>
Owner of the sessions one WebSocket service creates. More...
Inherits NonCopyable.
Public Member Functions | |
| WebSocketServlet (WebSocketService &service) | |
| Attaches this servlet to service. | |
| ~WebSocketServlet () | |
| Detaches this servlet and releases its remaining sessions. | |
| WebSocketService & | service () |
| Returns the service this servlet was constructed with. | |
| const WebSocketService & | service () const |
| Returns the service this servlet was constructed with. | |
| std::size_t | size () const |
| Returns the number of live sessions. | |
WebSocketServlet owns the live sessions of one WebSocketService. The service owns the endpoint policy and the allocator, and stays the mapped HTTP service and the factory. Destroy this servlet before the service, so each remaining session is released while the derived service, its virtual release call, and its allocator are still available. It is not a server and does not map a URL. A URL mapping is still required so the handshake reaches the service.
The example registers the servlet before the server starts taking upgrades. The three setters are endpoint policy of the service. They apply before this servlet is constructed. Destroy the servlet before the service.
Construct it with the WebSocketService and destroy it before that service. The constructor attaches this servlet, so the handshake can accept upgrades. The destructor detaches it and releases every remaining session through releaseSession(). That order is required. The service destructor cannot release sessions, because by then the derived object is already gone.
One service has one active servlet. Constructing a second WebSocketServlet for the same service throws std::logic_error. With no servlet, the handshake answers the upgrade with 503 and opens no stream. The service owns setMaxSockets(), setIdleTimeout(), setPingInterval(), setPingTimeout(), setCloseTimeout() and setMaxMessageSize(). The handshake reads the session limit and socketCount() from the service. socketCount() is the number of sessions getSession() returned and releaseSession() has not yet released. The session base copies the idle, ping-interval, ping and close timeouts and the data-message limit from the service onto the connection before the derived constructor runs.
|
explicit |
| %std::logic_error | if service already has an active servlet. |