mirror of https://github.com/jetkvm/kvm.git
feat: panic on max restart attempts
This commit is contained in:
parent
afd8ab75bc
commit
6e9d846471
|
|
@ -33,6 +33,7 @@ type NativeOptions struct {
|
||||||
AppVersion *semver.Version
|
AppVersion *semver.Version
|
||||||
DisplayRotation uint16
|
DisplayRotation uint16
|
||||||
DefaultQualityFactor float64
|
DefaultQualityFactor float64
|
||||||
|
MaxRestartAttempts uint
|
||||||
OnVideoStateChange func(state VideoState)
|
OnVideoStateChange func(state VideoState)
|
||||||
OnVideoFrameReceived func(frame []byte, duration time.Duration)
|
OnVideoFrameReceived func(frame []byte, duration time.Duration)
|
||||||
OnIndevEvent func(event string)
|
OnIndevEvent func(event string)
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxFrameSize = 1920 * 1080 / 2
|
maxFrameSize = 1920 * 1080 / 2
|
||||||
|
defaultMaxRestartAttempts uint = 5
|
||||||
)
|
)
|
||||||
|
|
||||||
type nativeProxyOptions struct {
|
type nativeProxyOptions struct {
|
||||||
|
|
@ -55,6 +56,10 @@ func randomId(binaryLength int) string {
|
||||||
func (n *NativeOptions) toProxyOptions() *nativeProxyOptions {
|
func (n *NativeOptions) toProxyOptions() *nativeProxyOptions {
|
||||||
// random 16 bytes hex string
|
// random 16 bytes hex string
|
||||||
handshakeMessage := randomId(16)
|
handshakeMessage := randomId(16)
|
||||||
|
maxRestartAttempts := defaultMaxRestartAttempts
|
||||||
|
if n.MaxRestartAttempts > 0 {
|
||||||
|
maxRestartAttempts = n.MaxRestartAttempts
|
||||||
|
}
|
||||||
return &nativeProxyOptions{
|
return &nativeProxyOptions{
|
||||||
Disable: n.Disable,
|
Disable: n.Disable,
|
||||||
SystemVersion: n.SystemVersion,
|
SystemVersion: n.SystemVersion,
|
||||||
|
|
@ -67,6 +72,7 @@ func (n *NativeOptions) toProxyOptions() *nativeProxyOptions {
|
||||||
OnVideoStateChange: n.OnVideoStateChange,
|
OnVideoStateChange: n.OnVideoStateChange,
|
||||||
OnNativeRestart: n.OnNativeRestart,
|
OnNativeRestart: n.OnNativeRestart,
|
||||||
HandshakeMessage: handshakeMessage,
|
HandshakeMessage: handshakeMessage,
|
||||||
|
MaxRestartAttempts: maxRestartAttempts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -405,6 +411,10 @@ func (p *NativeProxy) restartProcess() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.restarts++
|
p.restarts++
|
||||||
|
if p.restarts >= p.options.MaxRestartAttempts {
|
||||||
|
p.logger.Fatal().Msg("max restart attempts reached, exiting")
|
||||||
|
return fmt.Errorf("max restart attempts reached")
|
||||||
|
}
|
||||||
|
|
||||||
if err := p.start(); err != nil {
|
if err := p.start(); err != nil {
|
||||||
return fmt.Errorf("failed to start native process: %w", err)
|
return fmt.Errorf("failed to start native process: %w", err)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue