Properly handle lost connection.

This commit is contained in:
Martin Dosch 2024-02-20 18:21:51 +01:00
parent 5c8694d667
commit d74b86c30c
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D
3 changed files with 5 additions and 3 deletions

View File

@ -1,6 +1,8 @@
# Changelog
## UNRELEASED
### Changed
- Properly handle lost connection.
## [v0.8.3] 2024-02-17
### Changed

View File

@ -318,7 +318,7 @@ func main() {
iqc := make(chan xmpp.IQ, defaultBufferSize)
msgc := make(chan xmpp.Chat, defaultBufferSize)
ctx, cancel := context.WithCancel(context.Background())
go rcvStanzas(client, iqc, msgc, ctx)
go rcvStanzas(client, iqc, msgc, ctx, cancel)
for _, r := range getopt.Args() {
var re recipientsType
re.Jid = r

View File

@ -38,7 +38,7 @@ func getIQ(id string, c chan xmpp.IQ, iqc chan xmpp.IQ) {
}
}
func rcvStanzas(client *xmpp.Client, iqc chan xmpp.IQ, msgc chan xmpp.Chat, ctx context.Context) {
func rcvStanzas(client *xmpp.Client, iqc chan xmpp.IQ, msgc chan xmpp.Chat, ctx context.Context, cancel context.CancelFunc) {
for {
received, err := client.Recv()
// Don't print errors if the program is getting shut down,
@ -49,7 +49,7 @@ func rcvStanzas(client *xmpp.Client, iqc chan xmpp.IQ, msgc chan xmpp.Chat, ctx
return
default:
if err != nil {
log.Println(err)
closeAndExit(client, cancel, err)
}
}
switch v := received.(type) {