Expose payload to ping/pong events
This commit is contained in:
@@ -35,10 +35,10 @@ int main() {
|
||||
.drain = [](auto */*ws*/) {
|
||||
/* Check getBufferedAmount here */
|
||||
},
|
||||
.ping = [](auto */*ws*/) {
|
||||
.ping = [](auto */*ws*/, std::string_view) {
|
||||
|
||||
},
|
||||
.pong = [](auto */*ws*/) {
|
||||
.pong = [](auto */*ws*/, std::string_view) {
|
||||
|
||||
},
|
||||
.close = [](auto */*ws*/, int /*code*/, std::string_view /*message*/) {
|
||||
|
||||
@@ -37,10 +37,10 @@ int main() {
|
||||
.drain = [](auto */*ws*/) {
|
||||
/* Check ws->getBufferedAmount() here */
|
||||
},
|
||||
.ping = [](auto */*ws*/) {
|
||||
.ping = [](auto */*ws*/, std::string_view) {
|
||||
/* Not implemented yet */
|
||||
},
|
||||
.pong = [](auto */*ws*/) {
|
||||
.pong = [](auto */*ws*/, std::string_view) {
|
||||
/* Not implemented yet */
|
||||
},
|
||||
.close = [](auto */*ws*/, int /*code*/, std::string_view /*message*/) {
|
||||
|
||||
@@ -32,10 +32,10 @@ int main() {
|
||||
.drain = [](auto */*ws*/) {
|
||||
/* Check getBufferedAmount here */
|
||||
},
|
||||
.ping = [](auto */*ws*/) {
|
||||
.ping = [](auto */*ws*/, std::string_view) {
|
||||
|
||||
},
|
||||
.pong = [](auto */*ws*/) {
|
||||
.pong = [](auto */*ws*/, std::string_view) {
|
||||
|
||||
},
|
||||
.close = [](auto */*ws*/, int /*code*/, std::string_view /*message*/) {
|
||||
|
||||
@@ -106,10 +106,10 @@ int main() {
|
||||
.drain = [](auto */*ws*/) {
|
||||
/* Check ws->getBufferedAmount() here */
|
||||
},
|
||||
.ping = [](auto */*ws*/) {
|
||||
.ping = [](auto */*ws*/, std::string_view) {
|
||||
/* You don't need to handle this one, we automatically respond to pings as per standard */
|
||||
},
|
||||
.pong = [](auto */*ws*/) {
|
||||
.pong = [](auto */*ws*/, std::string_view) {
|
||||
/* You don't need to handle this one either */
|
||||
},
|
||||
.close = [](auto */*ws*/, int /*code*/, std::string_view /*message*/) {
|
||||
|
||||
@@ -59,10 +59,10 @@ int main() {
|
||||
.drain = [](auto */*ws*/) {
|
||||
/* Check ws->getBufferedAmount() here */
|
||||
},
|
||||
.ping = [](auto */*ws*/) {
|
||||
.ping = [](auto */*ws*/, std::string_view) {
|
||||
/* You don't need to handle this one, we automatically respond to pings as per standard */
|
||||
},
|
||||
.pong = [](auto */*ws*/) {
|
||||
.pong = [](auto */*ws*/, std::string_view) {
|
||||
/* You don't need to handle this one either */
|
||||
},
|
||||
.close = [](auto */*ws*/, int /*code*/, std::string_view /*message*/) {
|
||||
|
||||
@@ -155,8 +155,8 @@ public:
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *)> open = nullptr;
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *, std::string_view, OpCode)> message = nullptr;
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *)> drain = nullptr;
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *)> ping = nullptr;
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *)> pong = nullptr;
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *, std::string_view)> ping = nullptr;
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *, std::string_view)> pong = nullptr;
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *, int, std::string_view)> close = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -171,14 +171,14 @@ private:
|
||||
if (opCode == PING) {
|
||||
webSocket->send(std::string_view(data, length), (OpCode) OpCode::PONG);
|
||||
if (webSocketContextData->pingHandler) {
|
||||
webSocketContextData->pingHandler(webSocket);
|
||||
webSocketContextData->pingHandler(webSocket, {data, length});
|
||||
if (us_socket_is_closed(SSL, (us_socket_t *) s) || webSocketData->isShuttingDown) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (opCode == PONG) {
|
||||
if (webSocketContextData->pongHandler) {
|
||||
webSocketContextData->pongHandler(webSocket);
|
||||
webSocketContextData->pongHandler(webSocket, {data, length});
|
||||
if (us_socket_is_closed(SSL, (us_socket_t *) s) || webSocketData->isShuttingDown) {
|
||||
return true;
|
||||
}
|
||||
@@ -200,14 +200,14 @@ private:
|
||||
if (opCode == PING) {
|
||||
webSocket->send(std::string_view(controlBuffer, webSocketData->controlTipLength), (OpCode) OpCode::PONG);
|
||||
if (webSocketContextData->pingHandler) {
|
||||
webSocketContextData->pingHandler(webSocket);
|
||||
webSocketContextData->pingHandler(webSocket, std::string_view(controlBuffer, webSocketData->controlTipLength));
|
||||
if (us_socket_is_closed(SSL, (us_socket_t *) s) || webSocketData->isShuttingDown) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (opCode == PONG) {
|
||||
if (webSocketContextData->pongHandler) {
|
||||
webSocketContextData->pongHandler(webSocket);
|
||||
webSocketContextData->pongHandler(webSocket, std::string_view(controlBuffer, webSocketData->controlTipLength));
|
||||
if (us_socket_is_closed(SSL, (us_socket_t *) s) || webSocketData->isShuttingDown) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ public:
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *)> drainHandler = nullptr;
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, int, std::string_view)> closeHandler = nullptr;
|
||||
/* Todo: these should take message also; breaking change for v0.18 */
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *)> pingHandler = nullptr;
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *)> pongHandler = nullptr;
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view)> pingHandler = nullptr;
|
||||
MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view)> pongHandler = nullptr;
|
||||
|
||||
/* Settings for this context */
|
||||
size_t maxPayloadLength = 0;
|
||||
|
||||
Reference in New Issue
Block a user