RetryAfter

class RetryAfter(val maxWait: Duration = DEFAULT_MAX_WAIT, val maxAttempts: Int = DEFAULT_MAX_ATTEMPTS)(source)

Sends a request again when the server asks to be asked later, as RFC 8516 §4 has a client do: while the answer is 4.29 Too Many Requests, or 5.03 Service Unavailable with the same meaning for an overload of all clients (RFC 7252 §5.9.3.4), it waits as long as the response's Max-Age says (CoapResponse.retryAfter, 60 seconds without one) and sends the request again, maxAttempts times at most in all.

  • It never sends earlier than the server asked (RFC 8516 §4: SHOULD NOT): a wait longer than maxWait is not waited out, and the refusal is returned at once for the caller to decide.

  • The wait is a coroutine delay, so cancelling the caller ends it, and nothing more is sent.

  • A 4.29 that no security protocol authenticated may be forged to make a client wait (RFC 8516 §5); maxWait bounds what that costs. With message security the client acts only on verified responses (ADR 0008).

  • Each attempt is a new request, with a new token and Message ID, since the server answered the last one.

val response = RetryAfter(maxWait = 30.seconds).request(client, CoapRequest(CoapCode.GET, CoapUri.parse(uri)))

Constructors

Link copied to clipboard
constructor(maxWait: Duration = DEFAULT_MAX_WAIT, maxAttempts: Int = DEFAULT_MAX_ATTEMPTS)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

how many times the request is sent at most, the first included; at least 1.

Link copied to clipboard

the longest wait it takes on; at least zero.

Functions

Link copied to clipboard
suspend fun request(client: CoapClient, request: CoapRequest): CoapResponse

Sends request with client, again after each 4.29 or 5.03 as the class describes, and returns the last response: one of another code, a refusal whose wait is longer than maxWait, or the answer to the last attempt.

Link copied to clipboard
open override fun toString(): String