BasicWebSocketService< S, Alloc > Class Template Reference

#include <Pt/Http/WebSocketService.h>

WebSocket service for one session type.

Inherits WebSocketService.

Public Member Functions

 BasicWebSocketService ()
 Default constructor.
 ~BasicWebSocketService ()
 Destructor.
std::size_t maxSockets () const
 Returns the maximum number of live sessions.
void setMaxSockets (std::size_t n)
 Sets the maximum number of live sessions.
std::size_t idleTimeout () const
 Returns the idle timeout in milliseconds.
void setIdleTimeout (std::size_t ms)
 Sets the idle timeout in milliseconds.
std::size_t maxMessageSize () const
 Returns the maximum data message size in bytes.
void setMaxMessageSize (std::size_t n)
 Sets the maximum data message size in bytes.
Responder * getResponder (const Request &)
 Creates a responder to handle request received by a server.
void releaseResponder (Responder *)
 Destroys a responder created by a server.

Protected Member Functions

virtual WebSocketSession * onGetSession (WebSocketServlet &servlet, System::EventLoop &loop, Stream &stream)
 Creates the session for stream.
virtual void onReleaseSession (WebSocketSession *session)
 Destroys a session created by onGetSession().
virtual Responder * onGetResponder (const Request &)
 Creates the handshake responder.
virtual void onReleaseResponder (Responder *responder)
 Destroys the handshake responder.
virtual void onUpgrade (Stream &stream) final
 Accepts or declines the upgraded stream.

Member Function Documentation

◆ onGetSession()

template<typename S, typename Alloc = Allocator>
virtual WebSocketSession * onGetSession ( WebSocketServlet & servlet,
System::EventLoop & loop,
Stream & stream )
protectedvirtual

servlet holds the returned session. loop serializes stream. Return null to decline the upgrade.

Implements WebSocketService.

◆ onReleaseSession()

template<typename S, typename Alloc = Allocator>
virtual void onReleaseSession ( WebSocketSession * session)
protectedvirtual

Called by the WebSocketServlet that holds the session, while this service is still fully constructed.

Implements WebSocketService.

◆ maxSockets()

std::size_t maxSockets ( ) const
inherited

Zero means no limit.

◆ setMaxSockets()

void setMaxSockets ( std::size_t n)
inherited

A handshake above this limit is answered with 503. Zero means no limit.

◆ setIdleTimeout()

void setIdleTimeout ( std::size_t ms)
inherited

An accepted socket is closed after ms without a finished transfer. A finished send or receive restarts the timeout. Zero disables it.

◆ setMaxMessageSize()

void setMaxMessageSize ( std::size_t n)
inherited

A larger data message closes the socket. Zero disables the limit. The count is the declared payload from the first data opcode to FIN.

◆ onUpgrade()

virtual void onUpgrade ( Stream & stream)
finalprotectedvirtualinherited

Implemented by this class. A derived service uses onGetSession() instead.

Reimplemented from Service.