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>
22class WebSocketConnection;
153 const std::string& origin = std::string());
158 {
return _connected; }
208 void ping(
const char* payload = 0, std::size_t n = 0);
219 const std::string& reason = std::string());
232 {
return _inputReady; }
237 {
return _outputReady; }
271 void parseUrl(
const std::string& url,
const std::string& origin);
273 static std::string createKey();
275 void finishHandshake(
bool failed);
277 void onRequestSent(
Client& client);
279 void onReply(
Client& client);
283 void onOutputReady();
289 WebSocketConnection* _connection;
Connection Management for Signal and Slot Objects.
Definition Connectable.h:50
HTTP user agent.
Definition Client.h:195
Progress of an asynchronous HTTP send or receive.
Definition Message.h:337
Payload of one text or binary WebSocket message.
Definition WebSocketMessage.h:71
void beginSend()
Begins sending outgoing().
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.
void endConnect()
Completes the client handshake.
Pt::Signal< WebSocket & > & outputReady()
Returns the signal emitted when data bytes were sent.
Definition WebSocket.h:236
const std::string & closeReason() const
Returns the close reason of the handshake that ended the stream.
void setTimeout(std::size_t timeout)
Sets the stream timeout in milliseconds.
void close(unsigned code=1000, const std::string &reason=std::string())
Enqueues a close frame and ends the stream after the close handshake.
Pt::Signal< WebSocket & > & connected()
Returns the signal emitted when the handshake finishes.
Definition WebSocket.h:157
void setMaxMessageSize(std::size_t maxSize)
Closes the stream when a data message exceeds maxSize.
void beginReceive()
Begins receiving into incoming().
WebSocketMessage & outgoing()
Returns the outgoing message.
void setIdleTimeout(std::size_t ms)
Closes the stream after ms without a finished transfer.
MessageProgress endReceive()
Completes the receive started by beginReceive().
Pt::Signal< WebSocket & > & inputReady()
Returns the signal emitted when data bytes were received.
Definition WebSocket.h:231
MessageProgress endSend()
Completes the send started by beginSend().
WebSocketMessage & incoming()
Returns the incoming message.
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 & > & closed()
Returns the signal emitted when the stream ends.
Definition WebSocket.h:247
Multicast Signal to call multiple slots.
Definition Signal.h:190
HTTP clients and servers.
Core module.
Definition Allocator.h:33