mirror of
https://salsa.debian.org/mdosch/go-sendxmpp
synced 2024-11-18 21:25:31 +00:00
Properly quit connection in interactive mode.
This commit is contained in:
parent
48d50b5667
commit
b0e67b7ff0
@ -1,6 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
### Changed
|
||||
- Properly close connection to server if ^C is pressed in interactive mode.
|
||||
|
||||
## [v0.6.1] 2023-07-25
|
||||
### Changed
|
||||
|
11
main.go
11
main.go
@ -13,6 +13,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -314,7 +315,6 @@ func main() {
|
||||
iqc := make(chan xmpp.IQ, defaultBufferSize)
|
||||
msgc := make(chan xmpp.Chat, defaultBufferSize)
|
||||
go rcvStanzas(client, iqc, msgc)
|
||||
|
||||
for _, r := range getopt.Args() {
|
||||
var re recipientsType
|
||||
re.Jid = r
|
||||
@ -441,6 +441,15 @@ func main() {
|
||||
case *flagInteractive:
|
||||
// Send in endless loop (for usage with e.g. "tail -f").
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
// Quit if ^C is pressed.
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
go func() {
|
||||
for range c {
|
||||
client.Close()
|
||||
os.Exit(0)
|
||||
}
|
||||
}()
|
||||
for {
|
||||
message, err = reader.ReadString('\n')
|
||||
message = strings.TrimSuffix(message, "\n")
|
||||
|
Loading…
Reference in New Issue
Block a user