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.
const std::vector< std::string > & protocols () const
 Returns accepted Sec-WebSocket-Protocol names in preference order.
void addProtocol (const std::string &name)
 Adds one accepted Sec-WebSocket-Protocol name.
void clearProtocols ()
 Drops every accepted protocol name.
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 pingInterval () const
 Returns the ping interval in milliseconds.
void setPingInterval (std::size_t ms)
 Sets the ping interval in milliseconds.
std::size_t pingTimeout () const
 Returns the ping timeout in milliseconds.
void setPingTimeout (std::size_t ms)
 Sets the ping timeout in milliseconds.
std::size_t closeTimeout () const
 Returns the close timeout in milliseconds.
void setCloseTimeout (std::size_t ms)
 Sets the close 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.
bool hasServlet () const
 True when a servlet is attached.
std::size_t socketCount () const
 Returns the number of counted sessions.
WebSocketSession * getSession (Stream &stream, const Request &request, const Reply &reply)
 Creates a session and counts a non-null result.
void releaseSession (WebSocketSession *session)
 Releases a session created by getSession().
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 (Stream &stream, const Request &, const Reply &reply)
 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, const Request &request, const Reply &reply) final
 Accepts or declines the upgraded stream.

Member Function Documentation

◆ onGetSession()

template<typename S, typename Alloc = Allocator>
virtual WebSocketSession * onGetSession ( Stream & stream,
const Request & request,
const Reply & reply )
protectedvirtual

Called by getSession(). The active WebSocketServlet owns a non-null result. request is the opening request and reply is the opening reply. Both are valid for this call. Copy any header the session must keep. Return null to decline the upgrade. A null return is not counted.

Implements WebSocketService.

◆ onReleaseSession()

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

Called by releaseSession() while this service is still fully constructed. The servlet has already removed the session from its list.

Implements WebSocketService.

◆ addProtocol()

void addProtocol ( const std::string & name)
inherited

Names are matched in the order they were added. An empty list accepts the upgrade and selects no name.

Exceptions
%std::invalid_argumentif name is empty or is not a single protocol token.

◆ maxSockets()

std::size_t maxSockets ( ) const
inherited

Zero means no limit. This is endpoint policy of this service. It applies before a servlet is constructed.

◆ setMaxSockets()

void setMaxSockets ( std::size_t n)
inherited

A handshake above this limit is answered with 503. Zero means no limit. A missing servlet is still 503 when this limit is zero. This is endpoint policy of this service. It applies before a servlet is constructed.

◆ idleTimeout()

std::size_t idleTimeout ( ) const
inherited

Zero means the idle timeout is disabled. This is endpoint policy of this service. It applies before a servlet is constructed.

◆ setIdleTimeout()

void setIdleTimeout ( std::size_t ms)
inherited

An accepted socket is closed after ms without an incoming frame. Incoming data, a received ping, and a received pong restart it. Sending does not. Zero disables it. This is endpoint policy of this service. It applies before a servlet is constructed.

◆ pingInterval()

std::size_t pingInterval ( ) const
inherited

Zero means the engine does not write keepalive pings. This is endpoint policy of this service. It applies before a servlet is constructed.

◆ setPingInterval()

void setPingInterval ( std::size_t ms)
inherited

An accepted socket writes a keepalive ping after ms without an incoming frame. Incoming data, a received ping, and a received pong restart it. Sending does not. Zero disables it. This is endpoint policy of this service. It applies before a servlet is constructed.

◆ pingTimeout()

std::size_t pingTimeout ( ) const
inherited

Zero means an unanswered ping has no deadline. This is endpoint policy of this service. It applies before a servlet is constructed.

◆ setPingTimeout()

void setPingTimeout ( std::size_t ms)
inherited

An accepted socket is closed if a ping is unanswered for ms. The wait starts at beginPing() and at a keepalive ping. Zero disables it. This is endpoint policy of this service. It applies before a servlet is constructed.

◆ closeTimeout()

std::size_t closeTimeout ( ) const
inherited

Zero leaves a close handshake unbounded. The default is ten seconds. This is endpoint policy of this service. It applies before a servlet is constructed.

◆ setCloseTimeout()

void setCloseTimeout ( std::size_t ms)
inherited

An accepted socket is closed if a close handshake is unanswered for ms. Zero leaves the wait unbounded. The default is ten seconds. This is endpoint policy of this service. It applies before a servlet is constructed.

◆ maxMessageSize()

std::size_t maxMessageSize ( ) const
inherited

Zero means the limit is disabled. This is endpoint policy of this service. It applies before a servlet is constructed.

◆ 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. This is endpoint policy of this service. It applies before a servlet is constructed.

◆ hasServlet()

bool hasServlet ( ) const
inherited

A missing servlet is a separate state from a zero maxSockets().

◆ socketCount()

std::size_t socketCount ( ) const
inherited

A session is counted when getSession() returns it, and dropped when releaseSession() releases it. A null return is not counted. Zero is not a reached limit. A missing servlet is a separate state, read with hasServlet().

◆ getSession()

WebSocketSession * getSession ( Stream & stream,
const Request & request,
const Reply & reply )
inherited

Calls onGetSession(). request is the opening request and reply is the opening reply. Both are valid until this call returns. A null return declines the upgrade and is not counted.

◆ releaseSession()

void releaseSession ( WebSocketSession * session)
inherited

Calls onReleaseSession() and drops the count. A null session is ignored. Called while this service is still fully constructed.

◆ onUpgrade()

virtual void onUpgrade ( Stream & stream,
const Request & request,
const Reply & reply )
finalprotectedvirtualinherited

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

Reimplemented from Service.