Properly handle lost connection.

no-tls
Martin Dosch 7 months ago
parent 5c8694d667
commit d74b86c30c
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D

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

@ -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

@ -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) {

Loading…
Cancel
Save