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>
21class WebSocketChannel;
158 friend class WebSocketService;
159 friend class WebSocketServlet;
186 {
return *_service; }
191 {
return *_service; }
198 {
return _protocol; }
256 void beginPing(
const char* payload = 0, std::size_t n = 0);
274 const std::string& reason = std::string());
335 virtual void onPong(
const std::string& payload);
340 void onOutputReady();
342 void onChannelPingReady();
344 void onChannelShutdownReady();
346 void onChannelClosed();
349 WebSocketService* _service;
350 WebSocketChannel* _channel;
351 std::string _protocol;
Connectable()
Default constructor.
Progress of an asynchronous HTTP send or receive.
Definition Message.h:337
HTTP reply message.
Definition Reply.h:64
One HTTP stream on a connection.
Definition Stream.h:92
Payload of one text or binary WebSocket message.
Definition WebSocketMessage.h:110
Mapped service and factory for WebSocket sessions.
Definition WebSocketService.h:132
WebSocketSession(WebSocketService &service, Stream &stream, const Reply &reply)
Binds stream for service.
virtual void onInput()=0
Called when data bytes were received.
virtual void onShutdownReady()
Reports that the shutdown operation completed.
unsigned closeCode() const
Returns the close status code of the handshake that ended the stream.
virtual void onPong(const std::string &payload)
Reports a received pong.
virtual void onOutput()=0
Called when data bytes were sent.
void endPing()
Completes the ping started by beginPing().
~WebSocketSession()
Closes the stream.
const std::string & closeReason() const
Returns the close reason of the handshake that ended the stream.
const std::string & protocol() const
Returns the protocol name selected on the 101.
Definition WebSocketSession.h:197
void beginSend(bool finished=true)
Begins sending outgoing().
const WebSocketService & service() const
Returns the service that created this session.
Definition WebSocketSession.h:190
void close()
Releases the stream and writes no frame.
WebSocketService & service()
Returns the service that created this session.
Definition WebSocketSession.h:185
void beginPing(const char *payload=0, std::size_t n=0)
Begins writing a ping with an optional payload of at most 125 bytes.
virtual void onClosed()
Reports that the engine has ended the protocol.
virtual void onPingReady()
Reports that the ping operation completed.
void beginReceive()
Begins receiving into incoming().
WebSocketMessage & outgoing()
Returns the outgoing message.
MessageProgress endReceive()
Completes the receive started by beginReceive().
void endShutdown()
Completes the shutdown started by beginShutdown().
MessageProgress endSend()
Completes the send started by beginSend().
WebSocketMessage & incoming()
Returns the incoming message.
void beginShutdown(unsigned code=1000, const std::string &reason=std::string())
Begins a close handshake.
HTTP clients and servers.
Core module.
Definition Allocator.h:33