Fix golangci-lint and Sonar: drop newZlibState, extract applyEncoding, inline stub comment

This commit is contained in:
Viktor Liu
2026-05-17 17:16:10 +02:00
parent 61ec8d67de
commit 2d0a54f31a
3 changed files with 49 additions and 42 deletions

View File

@@ -10,7 +10,8 @@ type vncServer interface{}
func (e *Engine) updateVNC(_ *mgmProto.SSHConfig) error { return nil }
// updateVNCServerAuth is a no-op on platforms without a VNC server.
func (e *Engine) updateVNCServerAuth(_ *mgmProto.VNCAuth) {}
func (e *Engine) updateVNCServerAuth(_ *mgmProto.VNCAuth) {
// no-op on platforms without a VNC server
}
func (e *Engine) stopVNCServer() error { return nil }

View File

@@ -671,10 +671,6 @@ type zlibState struct {
w *zlib.Writer
}
func newZlibState() *zlibState {
return newZlibStateLevel(zlib.BestSpeed)
}
func newZlibStateLevel(level int) *zlibState {
buf := &bytes.Buffer{}
w, _ := zlib.NewWriterLevel(buf, level)

View File

@@ -316,42 +316,8 @@ func (s *session) handleSetEncodings() error {
s.encMu.Lock()
for i := range int(numEnc) {
enc := int32(binary.BigEndian.Uint32(buf[i*4 : i*4+4]))
switch enc {
case encCopyRect:
s.useCopyRect = true
if s.copyRectDet == nil {
s.copyRectDet = newCopyRectDetector(tileSize)
}
encs = append(encs, "copyrect")
case pseudoEncDesktopSize:
s.clientSupportsDesktopSize = true
encs = append(encs, "desktop-size")
case pseudoEncExtendedDesktopSize:
s.clientSupportsExtendedDesktopSize = true
encs = append(encs, "ext-desktop-size")
case pseudoEncDesktopName:
s.clientSupportsDesktopName = true
encs = append(encs, "desktop-name")
case pseudoEncLastRect:
s.clientSupportsLastRect = true
encs = append(encs, "last-rect")
case pseudoEncQEMUExtendedKeyEvent:
s.clientSupportsQEMUKey = true
encs = append(encs, "qemu-key")
case pseudoEncExtendedClipboard:
s.clientSupportsExtClipboard = true
encs = append(encs, "ext-clipboard")
case encTight:
s.useTight = true
encs = append(encs, "tight")
}
switch {
case enc >= pseudoEncQualityLevelMin && enc <= pseudoEncQualityLevelMax:
s.clientJPEGQuality = int(enc - pseudoEncQualityLevelMin)
encs = append(encs, fmt.Sprintf("quality=%d", s.clientJPEGQuality))
case enc >= pseudoEncCompressLevelMin && enc <= pseudoEncCompressLevelMax:
s.clientZlibLevel = int(enc - pseudoEncCompressLevelMin)
encs = append(encs, fmt.Sprintf("compress=%d", s.clientZlibLevel))
if name := s.applyEncoding(enc); name != "" {
encs = append(encs, name)
}
}
if s.useTight && (s.tight == nil ||
@@ -375,6 +341,50 @@ func (s *session) handleSetEncodings() error {
return nil
}
// applyEncoding records a single encoding/pseudo-encoding from a SetEncodings
// message. Returns the short name used in the debug log, or "" if the value
// is one we don't recognise. Caller holds s.encMu.
func (s *session) applyEncoding(enc int32) string {
switch enc {
case encCopyRect:
s.useCopyRect = true
if s.copyRectDet == nil {
s.copyRectDet = newCopyRectDetector(tileSize)
}
return "copyrect"
case pseudoEncDesktopSize:
s.clientSupportsDesktopSize = true
return "desktop-size"
case pseudoEncExtendedDesktopSize:
s.clientSupportsExtendedDesktopSize = true
return "ext-desktop-size"
case pseudoEncDesktopName:
s.clientSupportsDesktopName = true
return "desktop-name"
case pseudoEncLastRect:
s.clientSupportsLastRect = true
return "last-rect"
case pseudoEncQEMUExtendedKeyEvent:
s.clientSupportsQEMUKey = true
return "qemu-key"
case pseudoEncExtendedClipboard:
s.clientSupportsExtClipboard = true
return "ext-clipboard"
case encTight:
s.useTight = true
return "tight"
}
if enc >= pseudoEncQualityLevelMin && enc <= pseudoEncQualityLevelMax {
s.clientJPEGQuality = int(enc - pseudoEncQualityLevelMin)
return fmt.Sprintf("quality=%d", s.clientJPEGQuality)
}
if enc >= pseudoEncCompressLevelMin && enc <= pseudoEncCompressLevelMax {
s.clientZlibLevel = int(enc - pseudoEncCompressLevelMin)
return fmt.Sprintf("compress=%d", s.clientZlibLevel)
}
return ""
}
// handleFBUpdateRequest parses the request and hands it to the encoder
// goroutine. It never blocks on capture/encode, so the input dispatch loop
// stays responsive even when a previous frame is still being encoded.