mqtt: send ping at upkeep interval

Closes #16975
This commit is contained in:
Christian Schmitz 2025-04-05 13:28:03 +02:00 committed by Daniel Stenberg
parent 56e40ae6a5
commit 8ad0243e1f
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 66 additions and 1 deletions

View file

@ -26,6 +26,10 @@ Example subscribe:
This sends an MQTT SUBSCRIBE packet for the topic `bedroom/temp` and listen in
for incoming PUBLISH packets.
You can set the upkeep interval ms option to make curl send MQTT ping requests to the
server at an internal, to prevent the connection to get closed because of idleness.
You might then need to use the progress callback to cancel the operation.
### Publishing
Command usage:

View file

@ -31,10 +31,13 @@ send some traffic on existing connections in order to keep them alive; this
can prevent connections from being closed due to overzealous firewalls, for
example.
Currently the only protocol with a connection upkeep mechanism is HTTP/2: when
For HTTP/2 we have an upkeep mechanism: when
the connection upkeep interval is exceeded and curl_easy_upkeep(3)
is called, an HTTP/2 PING frame is sent on the connection.
For MQTT the upkeep interval defines when to send ping requests to prevent the
server from disconnecting.
This function must be explicitly called in order to perform the upkeep work.
The connection upkeep interval is set with
CURLOPT_UPKEEP_INTERVAL_MS(3).