5#ifndef PT_HTTP_WEBSOCKETSESSION_H
6#define PT_HTTP_WEBSOCKETSESSION_H
8#include <Pt/Http/Api.h>
9#include <Pt/Http/WebSocketMessage.h>
10#include <Pt/Http/Message.h>
11#include <Pt/Connectable.h>
26class WebSocketConnection;
127 friend class WebSocketServlet;
149 {
return *_service; }
154 {
return *_service; }
196 void ping(
const char* payload = 0, std::size_t n = 0);
201 const std::string& reason = std::string());
232 void onOutputReady();
238 WebSocketServlet* _servlet;
240 WebSocketConnection* _connection;
Connectable()
Default constructor.
Progress of an asynchronous HTTP send or receive.
Definition Message.h:337
One HTTP stream on a connection.
Definition Stream.h:90
Payload of one text or binary WebSocket message.
Definition WebSocketMessage.h:71
Factory and endpoint policy for WebSocket sessions.
Definition WebSocketService.h:107
Release scope of the sessions one WebSocket service creates.
Definition WebSocketServlet.h:66
void beginSend()
Begins sending outgoing().
virtual void onInput()=0
Called when data bytes were received.
unsigned closeCode() const
Returns the close status code of the handshake that ended the stream.
void ping(const char *payload=0, std::size_t n=0)
Enqueues a ping with an optional payload of at most 125 bytes.
virtual void onOutput()=0
Called when data bytes were sent.
System::EventLoop & loop()
Returns the loop that serializes this stream.
Definition WebSocketSession.h:158
~WebSocketSession()
Closes the stream.
const std::string & closeReason() const
Returns the close reason of the handshake that ended the stream.
void close(unsigned code=1000, const std::string &reason=std::string())
Enqueues a close frame and ends the stream after the close handshake.
const WebSocketService & service() const
Returns the service that created this session.
Definition WebSocketSession.h:153
WebSocketService & service()
Returns the service that created this session.
Definition WebSocketSession.h:148
WebSocketSession(WebSocketServlet &servlet, System::EventLoop &loop, Stream &stream)
Binds stream on loop.
void beginReceive()
Begins receiving into incoming().
WebSocketMessage & outgoing()
Returns the outgoing message.
const System::EventLoop & loop() const
Returns the loop that serializes this stream.
Definition WebSocketSession.h:163
MessageProgress endReceive()
Completes the receive started by beginReceive().
MessageProgress endSend()
Completes the send started by beginSend().
WebSocketMessage & incoming()
Returns the incoming message.
virtual void onClose()=0
Called when the stream has ended.
Event loop of a thread or process.
Definition EventLoop.h:83
HTTP clients and servers.
System programming
Definition Connection.h:26
Core module.
Definition Allocator.h:33