|
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 | +<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"> |
| 3 | +<head> |
| 4 | +<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
| 5 | +<meta http-equiv="X-UA-Compatible" content="IE=11"/> |
| 6 | +<meta name="generator" content="Doxygen 1.9.6"/> |
| 7 | +<meta name="viewport" content="width=device-width, initial-scale=1"/> |
| 8 | +<title>backoffAlgorithm: backoff_algorithm.c File Reference</title> |
| 9 | +<link href="tabs.css" rel="stylesheet" type="text/css"/> |
| 10 | +<script type="text/javascript" src="jquery.js"></script> |
| 11 | +<script type="text/javascript" src="dynsections.js"></script> |
| 12 | +<link href="navtree.css" rel="stylesheet" type="text/css"/> |
| 13 | +<script type="text/javascript" src="resize.js"></script> |
| 14 | +<script type="text/javascript" src="navtreedata.js"></script> |
| 15 | +<script type="text/javascript" src="navtree.js"></script> |
| 16 | +<link href="search/search.css" rel="stylesheet" type="text/css"/> |
| 17 | +<script type="text/javascript" src="search/searchdata.js"></script> |
| 18 | +<script type="text/javascript" src="search/search.js"></script> |
| 19 | +<script type="text/javascript"> |
| 20 | +/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ |
| 21 | + $(document).ready(function() { init_search(); }); |
| 22 | +/* @license-end */ |
| 23 | +</script> |
| 24 | +<link href="doxygen.css" rel="stylesheet" type="text/css" /> |
| 25 | +<link href="style.css" rel="stylesheet" type="text/css"/> |
| 26 | +</head> |
| 27 | +<body> |
| 28 | +<div id="top"><!-- do not remove this div, it is closed by doxygen! --> |
| 29 | +<div id="titlearea"> |
| 30 | +<table cellspacing="0" cellpadding="0"> |
| 31 | + <tbody> |
| 32 | + <tr id="projectrow"> |
| 33 | + <td id="projectalign"> |
| 34 | + <div id="projectname">backoffAlgorithm<span id="projectnumber"> v1.3.0</span> |
| 35 | + </div> |
| 36 | + <div id="projectbrief">Algorithmic library for calculating retry intervals using exponential backoff and jitter.</div> |
| 37 | + </td> |
| 38 | + <td> <div id="MSearchBox" class="MSearchBoxInactive"> |
| 39 | + <span class="left"> |
| 40 | + <span id="MSearchSelect" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()"> </span> |
| 41 | + <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S" |
| 42 | + onfocus="searchBox.OnSearchFieldFocus(true)" |
| 43 | + onblur="searchBox.OnSearchFieldFocus(false)" |
| 44 | + onkeyup="searchBox.OnSearchFieldChange(event)"/> |
| 45 | + </span><span class="right"> |
| 46 | + <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a> |
| 47 | + </span> |
| 48 | + </div> |
| 49 | +</td> |
| 50 | + </tr> |
| 51 | + </tbody> |
| 52 | +</table> |
| 53 | +</div> |
| 54 | +<!-- end header part --> |
| 55 | +<!-- Generated by Doxygen 1.9.6 --> |
| 56 | +<script type="text/javascript"> |
| 57 | +/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ |
| 58 | +var searchBox = new SearchBox("searchBox", "search/",'.html'); |
| 59 | +/* @license-end */ |
| 60 | +</script> |
| 61 | +</div><!-- top --> |
| 62 | +<div id="side-nav" class="ui-resizable side-nav-resizable"> |
| 63 | + <div id="nav-tree"> |
| 64 | + <div id="nav-tree-contents"> |
| 65 | + <div id="nav-sync" class="sync"></div> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + <div id="splitbar" style="-moz-user-select:none;" |
| 69 | + class="ui-resizable-handle"> |
| 70 | + </div> |
| 71 | +</div> |
| 72 | +<script type="text/javascript"> |
| 73 | +/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ |
| 74 | +$(document).ready(function(){initNavTree('backoff__algorithm_8c.html',''); initResizable(); }); |
| 75 | +/* @license-end */ |
| 76 | +</script> |
| 77 | +<div id="doc-content"> |
| 78 | +<!-- window showing the filter options --> |
| 79 | +<div id="MSearchSelectWindow" |
| 80 | + onmouseover="return searchBox.OnSearchSelectShow()" |
| 81 | + onmouseout="return searchBox.OnSearchSelectHide()" |
| 82 | + onkeydown="return searchBox.OnSearchSelectKey(event)"> |
| 83 | +</div> |
| 84 | + |
| 85 | +<!-- iframe showing the search results (closed by default) --> |
| 86 | +<div id="MSearchResultsWindow"> |
| 87 | +<div id="MSearchResults"> |
| 88 | +<div class="SRPage"> |
| 89 | +<div id="SRIndex"> |
| 90 | +<div id="SRResults"></div> |
| 91 | +<div class="SRStatus" id="Loading">Loading...</div> |
| 92 | +<div class="SRStatus" id="Searching">Searching...</div> |
| 93 | +<div class="SRStatus" id="NoMatches">No Matches</div> |
| 94 | +</div> |
| 95 | +</div> |
| 96 | +</div> |
| 97 | +</div> |
| 98 | + |
| 99 | +<div class="header"> |
| 100 | + <div class="summary"> |
| 101 | +<a href="#func-members">Functions</a> </div> |
| 102 | + <div class="headertitle"><div class="title">backoff_algorithm.c File Reference</div></div> |
| 103 | +</div><!--header--> |
| 104 | +<div class="contents"> |
| 105 | + |
| 106 | +<p>Implementation of the backoff algorithm API for a "Full Jitter" exponential backoff with jitter strategy. |
| 107 | +<a href="#details">More...</a></p> |
| 108 | +<div class="textblock"><code>#include <assert.h></code><br /> |
| 109 | +<code>#include <stddef.h></code><br /> |
| 110 | +<code>#include "<a class="el" href="backoff__algorithm_8h_source.html">backoff_algorithm.h</a>"</code><br /> |
| 111 | +</div><table class="memberdecls"> |
| 112 | +<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a> |
| 113 | +Functions</h2></td></tr> |
| 114 | +<tr class="memitem:ae9dc843e520435569f40e8832791ecbe"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__backoff__algorithm__enum__types.html#ga7b7f4051eb253599ffedd69285f5a89b">BackoffAlgorithmStatus_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="backoff__algorithm_8c.html#ae9dc843e520435569f40e8832791ecbe">BackoffAlgorithm_GetNextBackoff</a> (<a class="el" href="struct_backoff_algorithm_context__t.html">BackoffAlgorithmContext_t</a> *pRetryContext, uint32_t randomValue, uint16_t *pNextBackOff)</td></tr> |
| 115 | +<tr class="memdesc:ae9dc843e520435569f40e8832791ecbe"><td class="mdescLeft"> </td><td class="mdescRight">Simple exponential backoff and jitter function that provides the delay value for the next retry attempt. After a failure of an operation that needs to be retried, the application should use this function to obtain the backoff delay value for the next retry, and then wait for the backoff time period before retrying the operation. <br /></td></tr> |
| 116 | +<tr class="separator:ae9dc843e520435569f40e8832791ecbe"><td class="memSeparator" colspan="2"> </td></tr> |
| 117 | +<tr class="memitem:ac37ecab230cf5da8f70547ec63776a48"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="backoff__algorithm_8c.html#ac37ecab230cf5da8f70547ec63776a48">BackoffAlgorithm_InitializeParams</a> (<a class="el" href="struct_backoff_algorithm_context__t.html">BackoffAlgorithmContext_t</a> *pContext, uint16_t backOffBase, uint16_t maxBackOff, uint32_t maxAttempts)</td></tr> |
| 118 | +<tr class="memdesc:ac37ecab230cf5da8f70547ec63776a48"><td class="mdescLeft"> </td><td class="mdescRight">Initializes the context for using backoff algorithm. The parameters are required for calculating the next retry backoff delay. This function must be called by the application before the first new retry attempt. <br /></td></tr> |
| 119 | +<tr class="separator:ac37ecab230cf5da8f70547ec63776a48"><td class="memSeparator" colspan="2"> </td></tr> |
| 120 | +</table> |
| 121 | +<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2> |
| 122 | +<div class="textblock"><p>Implementation of the backoff algorithm API for a "Full Jitter" exponential backoff with jitter strategy. </p> |
| 123 | +</div><h2 class="groupheader">Function Documentation</h2> |
| 124 | +<a id="ae9dc843e520435569f40e8832791ecbe" name="ae9dc843e520435569f40e8832791ecbe"></a> |
| 125 | +<h2 class="memtitle"><span class="permalink"><a href="#ae9dc843e520435569f40e8832791ecbe">◆ </a></span>BackoffAlgorithm_GetNextBackoff()</h2> |
| 126 | + |
| 127 | +<div class="memitem"> |
| 128 | +<div class="memproto"> |
| 129 | + <table class="memname"> |
| 130 | + <tr> |
| 131 | + <td class="memname"><a class="el" href="group__backoff__algorithm__enum__types.html#ga7b7f4051eb253599ffedd69285f5a89b">BackoffAlgorithmStatus_t</a> BackoffAlgorithm_GetNextBackoff </td> |
| 132 | + <td>(</td> |
| 133 | + <td class="paramtype"><a class="el" href="struct_backoff_algorithm_context__t.html">BackoffAlgorithmContext_t</a> * </td> |
| 134 | + <td class="paramname"><em>pRetryContext</em>, </td> |
| 135 | + </tr> |
| 136 | + <tr> |
| 137 | + <td class="paramkey"></td> |
| 138 | + <td></td> |
| 139 | + <td class="paramtype">uint32_t </td> |
| 140 | + <td class="paramname"><em>randomValue</em>, </td> |
| 141 | + </tr> |
| 142 | + <tr> |
| 143 | + <td class="paramkey"></td> |
| 144 | + <td></td> |
| 145 | + <td class="paramtype">uint16_t * </td> |
| 146 | + <td class="paramname"><em>pNextBackOff</em> </td> |
| 147 | + </tr> |
| 148 | + <tr> |
| 149 | + <td></td> |
| 150 | + <td>)</td> |
| 151 | + <td></td><td></td> |
| 152 | + </tr> |
| 153 | + </table> |
| 154 | +</div><div class="memdoc"> |
| 155 | + |
| 156 | +<p>Simple exponential backoff and jitter function that provides the delay value for the next retry attempt. After a failure of an operation that needs to be retried, the application should use this function to obtain the backoff delay value for the next retry, and then wait for the backoff time period before retrying the operation. </p> |
| 157 | +<dl class="params"><dt>Parameters</dt><dd> |
| 158 | + <table class="params"> |
| 159 | + <tr><td class="paramdir">[in,out]</td><td class="paramname">pRetryContext</td><td>Structure containing parameters for the next backoff value calculation. </td></tr> |
| 160 | + <tr><td class="paramdir">[in]</td><td class="paramname">randomValue</td><td>The random value to use for calculation of the backoff period. The random value should be in the range of [0, UINT32_MAX]. </td></tr> |
| 161 | + <tr><td class="paramdir">[out]</td><td class="paramname">pNextBackOff</td><td>This will be populated with the backoff value (in milliseconds) for the next retry attempt. The value does not exceed the maximum backoff delay configured in the context.</td></tr> |
| 162 | + </table> |
| 163 | + </dd> |
| 164 | +</dl> |
| 165 | +<dl class="section note"><dt>Note</dt><dd>For generating a random number, it is recommended to use a Random Number Generator that is seeded with a device-specific entropy source so that possibility of collisions between multiple devices retrying the network operations can be mitigated.</dd></dl> |
| 166 | +<dl class="section return"><dt>Returns</dt><dd><a class="el" href="group__backoff__algorithm__enum__types.html#gga7b7f4051eb253599ffedd69285f5a89baecf422ba6b1201d8ffbfd61e5712d695" title="The function successfully calculated the next back-off value.">BackoffAlgorithmSuccess</a> after a successful sleep; <a class="el" href="group__backoff__algorithm__enum__types.html#gga7b7f4051eb253599ffedd69285f5a89ba4dd72a4822e0f93b5b98309453b774df" title="The function exhausted all retry attempts.">BackoffAlgorithmRetriesExhausted</a> when all attempts are exhausted. </dd></dl> |
| 167 | + |
| 168 | +</div> |
| 169 | +</div> |
| 170 | +<a id="ac37ecab230cf5da8f70547ec63776a48" name="ac37ecab230cf5da8f70547ec63776a48"></a> |
| 171 | +<h2 class="memtitle"><span class="permalink"><a href="#ac37ecab230cf5da8f70547ec63776a48">◆ </a></span>BackoffAlgorithm_InitializeParams()</h2> |
| 172 | + |
| 173 | +<div class="memitem"> |
| 174 | +<div class="memproto"> |
| 175 | + <table class="memname"> |
| 176 | + <tr> |
| 177 | + <td class="memname">void BackoffAlgorithm_InitializeParams </td> |
| 178 | + <td>(</td> |
| 179 | + <td class="paramtype"><a class="el" href="struct_backoff_algorithm_context__t.html">BackoffAlgorithmContext_t</a> * </td> |
| 180 | + <td class="paramname"><em>pContext</em>, </td> |
| 181 | + </tr> |
| 182 | + <tr> |
| 183 | + <td class="paramkey"></td> |
| 184 | + <td></td> |
| 185 | + <td class="paramtype">uint16_t </td> |
| 186 | + <td class="paramname"><em>backOffBase</em>, </td> |
| 187 | + </tr> |
| 188 | + <tr> |
| 189 | + <td class="paramkey"></td> |
| 190 | + <td></td> |
| 191 | + <td class="paramtype">uint16_t </td> |
| 192 | + <td class="paramname"><em>maxBackOff</em>, </td> |
| 193 | + </tr> |
| 194 | + <tr> |
| 195 | + <td class="paramkey"></td> |
| 196 | + <td></td> |
| 197 | + <td class="paramtype">uint32_t </td> |
| 198 | + <td class="paramname"><em>maxAttempts</em> </td> |
| 199 | + </tr> |
| 200 | + <tr> |
| 201 | + <td></td> |
| 202 | + <td>)</td> |
| 203 | + <td></td><td></td> |
| 204 | + </tr> |
| 205 | + </table> |
| 206 | +</div><div class="memdoc"> |
| 207 | + |
| 208 | +<p>Initializes the context for using backoff algorithm. The parameters are required for calculating the next retry backoff delay. This function must be called by the application before the first new retry attempt. </p> |
| 209 | +<dl class="params"><dt>Parameters</dt><dd> |
| 210 | + <table class="params"> |
| 211 | + <tr><td class="paramdir">[out]</td><td class="paramname">pContext</td><td>The context to initialize with parameters required for the next backoff delay calculation function. </td></tr> |
| 212 | + <tr><td class="paramdir">[in]</td><td class="paramname">maxBackOff</td><td>The maximum backoff delay (in milliseconds) between consecutive retry attempts. </td></tr> |
| 213 | + <tr><td class="paramdir">[in]</td><td class="paramname">backOffBase</td><td>The base value (in milliseconds) of backoff delay to use in the exponential backoff and jitter model. </td></tr> |
| 214 | + <tr><td class="paramdir">[in]</td><td class="paramname">maxAttempts</td><td>The maximum number of retry attempts. Set the value to <a class="el" href="group__backoff__algorithm__constants.html#ga89e511b4edee8a92050802a329753842" title="Constant to represent unlimited number of retry attempts.">BACKOFF_ALGORITHM_RETRY_FOREVER</a> to retry for ever. </td></tr> |
| 215 | + </table> |
| 216 | + </dd> |
| 217 | +</dl> |
| 218 | + |
| 219 | +</div> |
| 220 | +</div> |
| 221 | +</div><!-- contents --> |
| 222 | +</div><!-- doc-content --> |
| 223 | +<!-- start footer part --> |
| 224 | +<div id="nav-path" class="navpath"><!-- id is needed for treeview function! --> |
| 225 | + <ul> |
| 226 | + <li class="navelem"><a class="el" href="dir_b2f33c71d4aa5e7af42a1ca61ff5af1b.html">source</a></li><li class="navelem"><a class="el" href="backoff__algorithm_8c.html">backoff_algorithm.c</a></li> |
| 227 | + <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 </li> |
| 228 | + </ul> |
| 229 | +</div> |
| 230 | +</body> |
| 231 | +</html> |
0 commit comments