6#ifndef PT_HTTP_WEBSOCKET_H
7#define PT_HTTP_WEBSOCKET_H
9#include <Pt/Http/Api.h>
10#include <Pt/Http/WebSocketMessage.h>
11#include <Pt/Http/Message.h>
12#include <Pt/Connectable.h>
23class WebSocketChannel;
184 const std::string& origin = std::string());
202 {
return _protocol; }
207 {
return _connected; }
281 void beginPing(
const char* payload = 0, std::size_t n = 0);
300 const std::string& reason = std::string());
328 {
return _inputReady; }
333 {
return _outputReady; }
340 {
return _pingReady; }
348 {
return _shutdownReady; }
408 void parseUrl(
const std::string& url,
const std::string& origin);
410 static std::string createKey();
412 void finishHandshake(
bool failed);
414 void onRequestSent(
Client& client);
416 void onReply(
Client& client);
420 void onOutputReady();
424 void onShutdownReady();
428 void onPong(
const std::string& payload);
432 WebSocketChannel* _channel;
434 std::string _protocol;
435 std::vector<std::string> _protocols;
Connection Management for Signal and Slot Objects.
Definition Connectable.h:50
HTTP user agent.
Definition Client.h:196
Progress of an asynchronous HTTP send or receive.
Definition Message.h:337
Payload of one text or binary WebSocket message.
Definition WebSocketMessage.h:110
unsigned closeCode() const
Returns the close status code of the handshake that ended the stream.
void endConnect()
Completes the client handshake.
void endPing()
Completes the ping started by beginPing().
void setPingInterval(std::size_t ms)
Writes a keepalive ping after ms without an incoming frame.
Pt::Signal< WebSocket & > & outputReady()
Returns the signal emitted when data bytes were sent.
Definition WebSocket.h:332
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 echoed by the server.
Definition WebSocket.h:201
void beginSend(bool finished=true)
Begins sending outgoing().
void close()
Releases the stream and writes no frame.
Pt::Signal< WebSocket & > & connected()
Returns the signal emitted when the handshake finishes.
Definition WebSocket.h:206
void setMaxMessageSize(std::size_t maxSize)
Closes the stream when a data message exceeds maxSize.
void setCloseTimeout(std::size_t ms)
Closes the stream if a close handshake is unanswered for ms.
void beginPing(const char *payload=0, std::size_t n=0)
Begins writing a ping with an optional payload of at most 125 bytes.
void beginReceive()
Begins receiving into incoming().
WebSocketMessage & outgoing()
Returns the outgoing message.
void setIdleTimeout(std::size_t ms)
Closes the stream after ms without an incoming frame.
Pt::Signal< WebSocket & > & pingReady()
Returns the signal emitted when a ping operation completes.
Definition WebSocket.h:339
Pt::Signal< WebSocket & > & shutdownReady()
Returns the signal emitted when a shutdown operation completes.
Definition WebSocket.h:347
MessageProgress endReceive()
Completes the receive started by beginReceive().
Pt::Signal< WebSocket & > & inputReady()
Returns the signal emitted when data bytes were received.
Definition WebSocket.h:327
void endShutdown()
Completes the shutdown started by beginShutdown().
~WebSocket()
Calls close().
MessageProgress endSend()
Completes the send started by beginSend().
WebSocketMessage & incoming()
Returns the incoming message.
void addProtocol(const std::string &name)
Offers one Sec-WebSocket-Protocol name.
void setPingTimeout(std::size_t ms)
Closes the stream if a ping is unanswered for ms.
WebSocket(Client &client)
Creates a WebSocket that handshakes through client.
void beginConnect(const std::string &url, const std::string &origin=std::string())
Begins a client handshake for url.
Pt::Signal< WebSocket &, const std::string & > & pong()
Returns the signal emitted for a received pong.
Definition WebSocket.h:364
Pt::Signal< WebSocket & > & closed()
Returns the signal emitted when the engine has ended the protocol.
Definition WebSocket.h:355
void beginShutdown(unsigned code=1000, const std::string &reason=std::string())
Begins a close handshake.
Multicast Signal to call multiple slots.
Definition Signal.h:190
HTTP clients and servers.
Core module.
Definition Allocator.h:33