mirror of
https://salsa.debian.org/mdosch/go-sendxmpp
synced 2024-11-10 19:10:30 +00:00
Properly handle lost connection.
This commit is contained in:
parent
5c8694d667
commit
d74b86c30c
@ -1,6 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
## UNRELEASED
|
||||
### Changed
|
||||
- Properly handle lost connection.
|
||||
|
||||
## [v0.8.3] 2024-02-17
|
||||
### Changed
|
||||
|
2
main.go
2
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
|
||||
|
@ -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…
Reference in New Issue
Block a user