xref: /aosp_15_r20/external/webrtc/net/dcsctp/public/timeout.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 #ifndef NET_DCSCTP_PUBLIC_TIMEOUT_H_
11 #define NET_DCSCTP_PUBLIC_TIMEOUT_H_
12 
13 #include <cstdint>
14 
15 #include "net/dcsctp/public/types.h"
16 
17 namespace dcsctp {
18 
19 // A very simple timeout that can be started and stopped. When started,
20 // it will be given a unique `timeout_id` which should be provided to
21 // `DcSctpSocket::HandleTimeout` when it expires.
22 class Timeout {
23  public:
24   virtual ~Timeout() = default;
25 
26   // Called to start time timeout, with the duration in milliseconds as
27   // `duration` and with the timeout identifier as `timeout_id`, which - if
28   // the timeout expires - shall be provided to `DcSctpSocket::HandleTimeout`.
29   //
30   // `Start` and `Stop` will always be called in pairs. In other words will
31   // ´Start` never be called twice, without a call to `Stop` in between.
32   virtual void Start(DurationMs duration, TimeoutID timeout_id) = 0;
33 
34   // Called to stop the running timeout.
35   //
36   // `Start` and `Stop` will always be called in pairs. In other words will
37   // ´Start` never be called twice, without a call to `Stop` in between.
38   //
39   // `Stop` will always be called prior to releasing this object.
40   virtual void Stop() = 0;
41 
42   // Called to restart an already running timeout, with the `duration` and
43   // `timeout_id` parameters as described in `Start`. This can be overridden by
44   // the implementation to restart it more efficiently.
Restart(DurationMs duration,TimeoutID timeout_id)45   virtual void Restart(DurationMs duration, TimeoutID timeout_id) {
46     Stop();
47     Start(duration, timeout_id);
48   }
49 };
50 
51 }  // namespace dcsctp
52 
53 #endif  // NET_DCSCTP_PUBLIC_TIMEOUT_H_
54