Pass UserData when upgrading

This commit is contained in:
Alex Hultman
2020-06-02 12:55:05 +02:00
parent cb48712b3d
commit 6735bad79c
3 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -31,7 +31,7 @@ int main() {
.upgrade = [](auto *res, auto *req, auto *context) {
/* Immediate path */
res->template upgrade<PerSocketData>(req->getHeader("sec-websocket-key"),
res->template upgrade<PerSocketData>({.something = 13}, req->getHeader("sec-websocket-key"),
req->getHeader("sec-websocket-protocol"),
req->getHeader("sec-websocket-extensions"),
context);
@@ -69,7 +69,7 @@ int main() {
if (!*aborted) {
// this should get some kind of ticket
res->template upgrade<PerSocketData>(secWebSocketKey,
res->template upgrade<PerSocketData>({}, secWebSocketKey,
secWebSocketProtocol,
secWebSocketExtensions,
context);
+1 -1
View File
@@ -179,7 +179,7 @@ public:
std::string_view secWebSocketProtocol = req->getHeader("sec-websocket-protocol");
std::string_view secWebSocketExtensions = req->getHeader("sec-websocket-extensions");
res->template upgrade<UserData>(secWebSocketKey, secWebSocketProtocol, secWebSocketExtensions, (struct us_socket_context_t *) webSocketContext);
res->template upgrade<UserData>({}, secWebSocketKey, secWebSocketProtocol, secWebSocketExtensions, (struct us_socket_context_t *) webSocketContext);
}
/* Emit open event and start the timeout */
+2 -2
View File
@@ -171,7 +171,7 @@ private:
public:
/* This call is identical to end, but will never write content-length and is thus suitable for upgrades */
template <typename UserData>
void upgrade(std::string_view secWebSocketKey, std::string_view secWebSocketProtocol,
void upgrade(UserData &&userData, std::string_view secWebSocketKey, std::string_view secWebSocketProtocol,
std::string_view secWebSocketExtensions,
struct us_socket_context_t *webSocketContext) {
@@ -266,7 +266,7 @@ public:
us_socket_timeout(SSL, (us_socket_t *) webSocket, /*behavior.*/idleTimeout);
/* Default construct the UserData right before calling open handler */
new (webSocket->getUserData()) UserData;
new (webSocket->getUserData()) UserData(std::move(userData));
/* Emit open event and start the timeout */
if (webSocketContextData->openHandler) {