28#ifndef PT_HTTP_WEBSOCKET_H
29#define PT_HTTP_WEBSOCKET_H
31#include <Pt/Http/Api.h>
32#include <Pt/Connectable.h>
34#include <Pt/System/Timer.h>
35#include <Pt/System/IODevice.h>
36#include <Pt/System/MainLoop.h>
37#include <Pt/Net/TcpSocket.h>
38#include <Pt/Http/IOStream.h>
106 void beginConnect(
const std::string& url,
const std::string& origin = std::string(),
bool keepAlive =
true);
132 return _receiveframeMode;
144 void parseUrl(
const std::string& url,
const std::string& origin);
154 static std::string createKey();
160 virtual void onClose();
162 virtual void onSetTimeout(
size_t ms);
166 virtual std::size_t onRead(
char* buffer, std::size_t count,
bool& eof);
172 virtual std::size_t onWrite(
const char* buffer, std::size_t count);
188 void handleInput(
size_t size);
196 ReceivePayloadLenght,
203 void handleReceiveHeader(
const char* buffer);
205 void handleReceiveMask(
const char* buffer);
207 void handleReceivePayloadLenght(
const char* buffer);
212 std::string _protocol;
213 std::string _connectHeader;
214 unsigned short _port;
215 WebSocketStream* _ioStream;
217 WebSocketParser* _httpParser;
227 size_t _currentOffset;
228 char* _userReceiveBuffer;
229 size_t _userReceiveBufferLenght;
230 size_t _userSendBufferLenght;
231 std::vector<char> _buffer;
233 Frame _sendFrameMode;
234 Frame _receiveframeMode;
237 std::vector<char> _currentBuffer;
238 size_t _payloadLenghtType;
Connection Management for Signal and Slot Objects.
Definition Connectable.h:50
Stream of an upgraded HTTP connection.
Definition IOStream.h:53
void setSendFrame(Frame m)
Sets the opcode for the next send.
Definition WebSocket.h:123
virtual void onDetach(Pt::System::EventLoop &loop)
Detached from loop.
void endConnect()
Completes the client handshake.
Frame
WebSocket frame opcode.
Definition WebSocket.h:77
@ Text
Text data frame.
Definition WebSocket.h:79
@ Unknow
Unset frame type.
Definition WebSocket.h:78
@ Pong
Pong frame.
Definition WebSocket.h:82
@ Ping
Ping frame.
Definition WebSocket.h:81
@ Binary
Binary data frame.
Definition WebSocket.h:80
WebSocket(Pt::Http::IOStream *stream)
Creates a WebSocket that accepts stream.
virtual void onAttach(Pt::System::EventLoop &loop)
Attached to loop.
virtual void onCancel()
Blocks until operation has cancelled.
void sendPingFrame()
Sends a ping frame.
Pt::Signal< WebSocket & > & connected()
Returns the signal emitted when the handshake finishes.
Definition WebSocket.h:110
Frame receiveFrame() const
Returns the opcode of the last received frame.
Definition WebSocket.h:130
virtual bool onRun()
Check if ready and run.
Definition WebSocket.h:178
void accept(Pt::Http::IOStream *stream)
Accepts an upgraded connection stream.
void beginConnect(const std::string &url, const std::string &origin=std::string(), bool keepAlive=true)
Begins a client handshake to url.
WebSocket()
Creates a closed WebSocket.
void sendPongFrame()
Sends a pong frame.
virtual ~WebSocket()
Destructor.
Multicast Signal to call multiple slots.
Definition Signal.h:190
Event loop of a thread or process.
Definition EventLoop.h:83
Endpoint for I/O operations.
Definition IODevice.h:96
EventLoop * loop() const
Returns the used event loop.
Definition IODevice.h:240
Platform event loop.
Definition MainLoop.h:51
uint_type uint32_t
Unsigned 32-bit integer type.
Definition Api-Types.h:52
HTTP clients and servers.
Core module.
Definition Allocator.h:33