8 #ifndef WPIUTIL_WPI_WEBSOCKETSERVER_H_
9 #define WPIUTIL_WPI_WEBSOCKETSERVER_H_
12 #include <initializer_list>
17 #include "wpi/ArrayRef.h"
18 #include "wpi/HttpParser.h"
19 #include "wpi/Signal.h"
20 #include "wpi/SmallString.h"
21 #include "wpi/SmallVector.h"
22 #include "wpi/StringRef.h"
23 #include "wpi/WebSocket.h"
70 std::initializer_list<StringRef> protocols) {
85 bool IsUpgrade()
const {
return m_gotHost && m_websocket; }
93 bool m_gotHost =
false;
94 bool m_websocket =
false;
104 struct private_init {};
139 static std::shared_ptr<WebSocketServer>
Create(
141 const ServerOptions& options = ServerOptions{});
152 static std::shared_ptr<WebSocketServer>
Create(
153 uv::Stream& stream, std::initializer_list<StringRef> protocols,
169 ServerOptions m_options;
170 bool m_aborted =
false;
175 void Abort(uint16_t code,
StringRef reason);
180 #endif // WPIUTIL_WPI_WEBSOCKETSERVER_H_
static std::shared_ptr< WebSocketServer > Create(uv::Stream &stream, std::initializer_list< StringRef > protocols, const ServerOptions &options=ServerOptions{})
Starts a dedicated WebSocket server on the provided connection.
Definition: WebSocketServer.h:152
Stream handle.
Definition: Stream.h:69
Server options.
Definition: WebSocketServer.h:110
WebSocket HTTP server helper.
Definition: WebSocketServer.h:35
WebSocketServerHelper(HttpParser &req)
Constructor.
static std::shared_ptr< WebSocketServer > Create(uv::Stream &stream, ArrayRef< StringRef > protocols=ArrayRef< StringRef >{}, const ServerOptions &options=ServerOptions{})
Starts a dedicated WebSocket server on the provided connection.
static std::shared_ptr< WebSocket > CreateServer(uv::Stream &stream, StringRef key, StringRef version, StringRef protocol=StringRef{})
Starts a server connection by performing the initial server side handshake.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
std::pair< bool, StringRef > MatchProtocol(std::initializer_list< StringRef > protocols)
Try to find a match to the list of sub-protocols provided by the client.
Definition: WebSocketServer.h:69
sig::Signal upgrade
Upgrade event.
Definition: WebSocketServer.h:90
bool IsWebsocket() const
Get whether or not this was a websocket upgrade.
Definition: WebSocketServer.h:47
HTTP protocol parser.
Definition: HttpParser.h:25
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:447
std::pair< bool, StringRef > MatchProtocol(ArrayRef< StringRef > protocols)
Try to find a match to the list of sub-protocols provided by the client.
sig::Signal< StringRef, WebSocket & > connected
Connected event.
Definition: WebSocketServer.h:162
WPILib C++ utilities (wpiutil) namespace.
Definition: EventLoopRunner.h:17
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
std::function< bool(StringRef)> checkUrl
Checker for URL.
Definition: WebSocketServer.h:115
std::shared_ptr< WebSocket > Accept(uv::Stream &stream, StringRef protocol=StringRef{})
Accept the upgrade.
Definition: WebSocketServer.h:80
ScopedConnection is a RAII version of Connection It disconnects the slot from the signal upon destruc...
Definition: Signal.h:257
Dedicated WebSocket server.
Definition: WebSocketServer.h:103
std::function< bool(StringRef)> checkHost
Checker for Host header.
Definition: WebSocketServer.h:121
WebSocketServer(uv::Stream &stream, ArrayRef< StringRef > protocols, const ServerOptions &options, const private_init &)
Private constructor.
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495