Polyphase Game Engine
Loading...
Searching...
No Matches
WebSocketTransport.h
Go to the documentation of this file.
1#pragma once
2
4
5#if !defined(POLYPHASE_PLATFORM_ADDON)
6
7// ---------------------------------------------------------------------------
8// Internal transport interface. Two flavours:
9//
10// byte transport raw TCP via NET_. The engine does the RFC 6455
11// handshake and framing on top (WebSocketHandshake /
12// WebSocketFraming).
13// message transport WinHTTP / libcurl. The platform owns the handshake and
14// the framing; we only push and pull whole messages.
15//
16// Not exported and not included by any public header - WsConnection is the
17// only thing gameplay code ever sees.
18// ---------------------------------------------------------------------------
20{
21public:
22
23 virtual ~WsTransport() {}
24
25 virtual bool IsMessageTransport() const = 0;
26
27 // Advance IO. Must never block.
28 virtual void Tick() = 0;
29
30 // Connecting -> usable. For a message transport this means the handshake
31 // has completed.
32 virtual bool IsConnected() const = 0;
33
34 virtual bool HasFailed() const = 0;
35 virtual WsError GetError() const = 0;
36 virtual const std::string& GetErrorMessage() const = 0;
37
38 // True once the peer closed the stream and everything buffered has been
39 // handed over.
40 virtual bool IsEndOfStream() const = 0;
41
42 virtual void Shutdown() = 0;
43
44 // -- Byte transports ---------------------------------------------------
45 // Queue bytes for sending. Returns false only on a dead transport.
46 virtual bool SendBytes(const uint8_t* /*data*/, uint32_t /*size*/) { return false; }
47 // Move everything received since the last call into outBytes.
48 virtual bool TakeReceivedBytes(std::vector<uint8_t>& /*outBytes*/) { return false; }
49
50 // Bytes accepted but not yet handed to the OS. Drives the outgoing-queue
51 // cap; message transports report the size of their pending message queue.
52 virtual uint32_t GetPendingSendBytes() const { return 0; }
53
54 // -- Message transports ------------------------------------------------
55 // NOT "SendMessage" - <windows.h> macro-expands that to SendMessageA/W.
56 virtual bool SendWholeMessage(const uint8_t* /*data*/, uint32_t /*size*/, bool /*binary*/) { return false; }
57 virtual bool TakeMessage(WsMessage& /*outMessage*/) { return false; }
58 // Fills the close code/reason once the peer has closed. Returns false
59 // while none has arrived.
60 virtual bool TakeClose(uint16_t& /*outCode*/, std::string& /*outReason*/) { return false; }
61 virtual void StartClose(uint16_t /*code*/, const char* /*reason*/) {}
62
63 virtual const std::string& GetSelectedProtocol() const = 0;
64};
65
66// Secure (wss://) message transport. Implemented per platform in
67// WebSocketWss_Windows.cpp / WebSocketWss_Linux.cpp; WebSocketClient.cpp
68// carries the "no TLS here" fallback for every other target.
70const char* WsSecureUnavailableMessage();
71WsTransport* WsCreateSecureTransport(const WsUrl& url, const WsConnectOptions& options, std::string& outError);
72
73#endif // !POLYPHASE_PLATFORM_ADDON
WsTransport * WsCreateSecureTransport(const WsUrl &url, const WsConnectOptions &options, std::string &outError)
Definition WebSocketClient.cpp:763
bool WsIsSecureSupported()
Definition WebSocketClient.cpp:753
const char * WsSecureUnavailableMessage()
Definition WebSocketClient.cpp:758
WsError
Definition WebSocketTypes.h:25
Definition WebSocketTransport.h:20
virtual bool HasFailed() const =0
virtual bool TakeMessage(WsMessage &)
Definition WebSocketTransport.h:57
virtual bool IsConnected() const =0
virtual bool IsMessageTransport() const =0
virtual void Tick()=0
virtual void Shutdown()=0
virtual bool TakeReceivedBytes(std::vector< uint8_t > &)
Definition WebSocketTransport.h:48
virtual uint32_t GetPendingSendBytes() const
Definition WebSocketTransport.h:52
virtual bool IsEndOfStream() const =0
virtual bool SendBytes(const uint8_t *, uint32_t)
Definition WebSocketTransport.h:46
virtual const std::string & GetErrorMessage() const =0
virtual WsError GetError() const =0
virtual ~WsTransport()
Definition WebSocketTransport.h:23
virtual const std::string & GetSelectedProtocol() const =0
virtual bool TakeClose(uint16_t &, std::string &)
Definition WebSocketTransport.h:60
virtual bool SendWholeMessage(const uint8_t *, uint32_t, bool)
Definition WebSocketTransport.h:56
virtual void StartClose(uint16_t, const char *)
Definition WebSocketTransport.h:61
Definition WebSocketTypes.h:61
Definition WebSocketTypes.h:69
Definition WebSocketTypes.h:52