Skip to content

Commit fd5bf65

Browse files
committed
drivers/main.{c,h}: introduce may_log_reconnect_trying() for drivers that retain custom logging of reconnection details for now [#3541]
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent 0ee8833 commit fd5bf65

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

drivers/main.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,6 +2214,25 @@ void setup_signals(void)
22142214
}
22152215
#endif /* !WIN32*/
22162216

2217+
/* Return 1 if driver can now report custom reconnection start/progress details */
2218+
int may_log_reconnect_trying(int throttle_hit) {
2219+
if (reconnect_count > 0) {
2220+
/* Accounting reconnections already, no care about throttling - be quiet */
2221+
if (!throttle_hit || reconnect_report_freq < 1)
2222+
return 0;
2223+
2224+
/* At that point in throttling where we may talk */
2225+
if ((reconnect_count % reconnect_report_freq) == 0)
2226+
return 1;
2227+
2228+
/* Throttling - be quiet */
2229+
return 0;
2230+
}
2231+
2232+
/* Not counting yet, would be a first report */
2233+
return 1;
2234+
}
2235+
22172236
/* Called by a driver to either enter/continue a reconnection loop
22182237
* (trying=1), almost done (trying=2), or to end it (trying=0).
22192238
* Return how many attempts remain before driver exits (-1 if it won't).

drivers/main.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ typedef enum reconnect_state {
134134
*/
135135
int reconnect_trying(reconnect_state_t trying);
136136

137+
/** Return 1 if driver can now report custom reconnection start/progress
138+
* details, with common information to be logged by reconnect_trying(),
139+
* otherwise 0. If `throttle_hit!=0`, check if `reconnect_report_freq>0`
140+
* and `reconnect_count%reconnect_report_freq == 0` to allow a progress
141+
* report to be logged.
142+
*
143+
* This method should be called before reconnect_trying(RECONNECT_TRYING)
144+
* bumps the counters involved.
145+
*/
146+
int may_log_reconnect_trying(int throttle_hit);
147+
137148
/* Several helpers for driver configuration reloading follow:
138149
* * testval_reloadable() checks if we are currently reloading (or initially
139150
* loading) the configuration, and if strings oldval==newval or not,

0 commit comments

Comments
 (0)