Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

36 rindas
732B

  1. package icecast
  2. import "time"
  3. type ReconnectConfig struct {
  4. Enabled bool
  5. InitialBackoffMs int
  6. MaxBackoffMs int
  7. }
  8. func (c ReconnectConfig) nextBackoff(attempt int) time.Duration {
  9. if !c.Enabled {
  10. return 0
  11. }
  12. initial := c.InitialBackoffMs
  13. if initial <= 0 {
  14. initial = 1000
  15. }
  16. max := c.MaxBackoffMs
  17. if max <= 0 {
  18. max = 15000
  19. }
  20. maxD := time.Duration(max) * time.Millisecond
  21. d := time.Duration(initial) * time.Millisecond
  22. // BUG-E fix: check d <= 0 (overflow) as well as d >= max.
  23. // int64 overflow after ~63 doublings caused d to go negative,
  24. // producing spurious short backoffs before recovering.
  25. for i := 1; i < attempt; i++ {
  26. d *= 2
  27. if d <= 0 || d >= maxD {
  28. return maxD
  29. }
  30. }
  31. return d
  32. }