mirror of
https://github.com/stryan/mumble-discord-bridge.git
synced 2024-11-23 05:45:41 -05:00
close channels so that everything dies properly
This commit is contained in:
parent
77cf328955
commit
665d42fc51
19
bridge.go
19
bridge.go
@ -68,8 +68,20 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
|||||||
<-ticker.C
|
<-ticker.C
|
||||||
if mumble.State() != 2 {
|
if mumble.State() != 2 {
|
||||||
log.Println("Lost mumble connection " + strconv.Itoa(int(mumble.State())))
|
log.Println("Lost mumble connection " + strconv.Itoa(int(mumble.State())))
|
||||||
die <- true
|
select {
|
||||||
m.Close <- true
|
default:
|
||||||
|
close(die)
|
||||||
|
case <-die:
|
||||||
|
//die is already closed
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
default:
|
||||||
|
close(m.Close)
|
||||||
|
case <-m.Close:
|
||||||
|
//m.Close is already closed
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -81,6 +93,9 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
|||||||
log.Println("\nGot internal die request. Terminating Mumble-Bridge")
|
log.Println("\nGot internal die request. Terminating Mumble-Bridge")
|
||||||
dgv.Disconnect()
|
dgv.Disconnect()
|
||||||
det.Detach()
|
det.Detach()
|
||||||
|
close(die)
|
||||||
|
close(m.Close)
|
||||||
|
close(toMumble)
|
||||||
Bridge.Connected = false
|
Bridge.Connected = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
discord.go
10
discord.go
@ -137,8 +137,14 @@ func discordReceivePCM(v *discordgo.VoiceConnection, die chan bool) {
|
|||||||
lastReady = true
|
lastReady = true
|
||||||
readyTimeout.Stop()
|
readyTimeout.Stop()
|
||||||
}
|
}
|
||||||
|
var ok bool
|
||||||
p, ok := <-v.OpusRecv
|
var p *discordgo.Packet
|
||||||
|
select {
|
||||||
|
case p, ok = <-v.OpusRecv:
|
||||||
|
case <-die:
|
||||||
|
log.Println("killing discord ReceivePCM")
|
||||||
|
return
|
||||||
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Println("Opus not ok")
|
log.Println("Opus not ok")
|
||||||
continue
|
continue
|
||||||
|
8
main.go
8
main.go
@ -5,6 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@ -101,6 +102,13 @@ func main() {
|
|||||||
userCount := make(chan int)
|
userCount := make(chan int)
|
||||||
go pingMumble(*mumbleAddr, strconv.Itoa(*mumblePort), userCount)
|
go pingMumble(*mumbleAddr, strconv.Itoa(*mumblePort), userCount)
|
||||||
go discordStatusUpdate(discord, userCount)
|
go discordStatusUpdate(discord, userCount)
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
log.Println(runtime.NumGoroutine())
|
||||||
|
//pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
||||||
|
}
|
||||||
|
}()
|
||||||
if *autoMode {
|
if *autoMode {
|
||||||
Bridge.AutoChan = make(chan bool)
|
Bridge.AutoChan = make(chan bool)
|
||||||
go AutoBridge(discord)
|
go AutoBridge(discord)
|
||||||
|
Loading…
Reference in New Issue
Block a user