fixes not disconnecting bug
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -306,8 +306,9 @@ func (sm *ShareManager) handleReleaseDevice(busID, fromClient string) {
|
||||
|
||||
// Notify client
|
||||
sm.client.SendJSON(&protocol.DeviceReleased{
|
||||
Type: protocol.MsgDeviceReleased,
|
||||
BusID: busID,
|
||||
Type: protocol.MsgDeviceReleased,
|
||||
BusID: busID,
|
||||
ClientID: sm.client.ID(),
|
||||
})
|
||||
|
||||
log.Printf("[share] device %s released", busID)
|
||||
|
||||
@@ -425,6 +425,38 @@ func (um *UseManager) handleDeviceDenied(msg *protocol.DeviceDenied) {
|
||||
|
||||
func (um *UseManager) handleDeviceReleased(msg *protocol.DeviceReleased) {
|
||||
log.Printf("[use] device released by share client: %s", msg.BusID)
|
||||
|
||||
um.mu.Lock()
|
||||
// Find and clean up any attached device matching this BusID (and ClientID if provided)
|
||||
for key, dev := range um.attached {
|
||||
if dev.BusID != msg.BusID {
|
||||
continue
|
||||
}
|
||||
if msg.ClientID != "" && dev.ClientID != msg.ClientID {
|
||||
continue
|
||||
}
|
||||
|
||||
// Clean up tunnel
|
||||
if tunnel, ok := um.tunnels[dev.TunnelID]; ok {
|
||||
close(tunnel.done)
|
||||
if tunnel.conn != nil {
|
||||
tunnel.conn.Close()
|
||||
}
|
||||
delete(um.tunnels, dev.TunnelID)
|
||||
}
|
||||
|
||||
// Detach from VHCI
|
||||
if dev.VHCIPort >= 0 {
|
||||
if err := usbip.DetachDevice(dev.VHCIPort); err != nil {
|
||||
log.Printf("[use] warning: VHCI detach error for force-released device: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
delete(um.attached, key)
|
||||
log.Printf("[use] device %s cleaned up (force-released by share client)", key)
|
||||
break
|
||||
}
|
||||
um.mu.Unlock()
|
||||
}
|
||||
|
||||
func (um *UseManager) handleTunnelData(tunnelID string, data []byte) {
|
||||
|
||||
@@ -106,8 +106,9 @@ type ReleaseDevice struct {
|
||||
|
||||
// DeviceReleased is sent when a device is released
|
||||
type DeviceReleased struct {
|
||||
Type string `json:"type"`
|
||||
BusID string `json:"bus_id"`
|
||||
Type string `json:"type"`
|
||||
BusID string `json:"bus_id"`
|
||||
ClientID string `json:"client_id,omitempty"`
|
||||
}
|
||||
|
||||
// ForceRelease is sent by use clients to force-release a device from another user
|
||||
|
||||
Reference in New Issue
Block a user