Skip to content

Commit

Permalink
emunwa: fix detector to reopen connection if closed due to error from…
Browse files Browse the repository at this point in the history
… EMULATOR_INFO response
  • Loading branch information
JamesDunne committed Apr 1, 2023
1 parent da1ee22 commit 765cd79
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions devices/snes/drivers/emunwa/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (d *Driver) Detect() (devs []devices.DeviceDescriptor, derr error) {
if detector.IsClosed() {
err = detector.Close()
if err != nil {
log.Printf("emunwa: error closing detector: %v\n", err)
log.Printf("emunwa: detect: detector[%d]: error closing detector: %v\n", i, err)
}
// refresh detector:
c := NewClient(detector.addr, fmt.Sprintf("emunwa[%d]", i), timing.Frame*4)
Expand All @@ -132,10 +132,13 @@ func (d *Driver) Detect() (devs []devices.DeviceDescriptor, derr error) {

// detect accidental loopback connections:
if detector.DetectLoopback(d.detectors) {
detector.Close()
if logDetector {
log.Printf("emunwa: detect: detector[%d]: loopback connection detected; breaking\n", i)
}
err = detector.Close()
if err != nil {
log.Printf("emunwa: detect: detector[%d]: error closing detector: %v\n", i, err)
}
return
}
}
Expand All @@ -152,6 +155,11 @@ func (d *Driver) Detect() (devs []devices.DeviceDescriptor, derr error) {
var bin []byte
bin, status, err = detector.SendCommandWaitReply("EMULATOR_INFO", time.Now().Add(timing.Frame*2))
if err != nil {
log.Printf("emunwa: detect: detector[%d]: EMULATOR_INFO error: %v; closing connection\n", i, err)
err = detector.Close()
if err != nil {
log.Printf("emunwa: detect: detector[%d]: error closing detector: %v\n", i, err)
}
return
}
if logDetector {
Expand Down

0 comments on commit 765cd79

Please sign in to comment.