From d74b86c30c73855a5eca084b3d690589bb0b4250 Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Tue, 20 Feb 2024 18:21:51 +0100 Subject: [PATCH] Properly handle lost connection. --- CHANGELOG.md | 2 ++ main.go | 2 +- stanzahandling.go | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8538daa..8d5d4a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## UNRELEASED +### Changed +- Properly handle lost connection. ## [v0.8.3] 2024-02-17 ### Changed diff --git a/main.go b/main.go index 7fc033c..45051c9 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/stanzahandling.go b/stanzahandling.go index 03bb9de..67fba04 100644 --- a/stanzahandling.go +++ b/stanzahandling.go @@ -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) {