Make it optional to wait for error replies.

check-errors
Martin Dosch 3 years ago
parent e8b3364c5b
commit 6eb65b9edc

@ -232,6 +232,7 @@ func main() {
flagSkipVerify := getopt.BoolLong("no-tls-verify", 'n',
"Skip verification of TLS certificates (not recommended).")
flagRaw := getopt.BoolLong("raw", 0, "Send raw XML.")
flagCheckErrors := getopt.BoolLong("check-errors", 0, "Wait for 0,5 s whether there are error replies.")
// Parse command line flags.
getopt.Parse()
@ -346,24 +347,26 @@ func main() {
*flagHttpUpload)
}
// Use a goroutine to check whether there is an error reply.
var messageErrors int
go func() {
for {
chat, err := client.Recv()
if err != nil {
log.Fatal(err)
}
switch v := chat.(type) {
case xmpp.Chat:
if strings.ToLower(v.Type) == "error" {
messageErrors++
log.Println("Error: Received error reply from",
v.Remote)
if *flagCheckErrors {
// Use a goroutine to check whether there is an error reply.
go func() {
for {
chat, err := client.Recv()
if err != nil {
log.Fatal(err)
}
switch v := chat.(type) {
case xmpp.Chat:
if strings.ToLower(v.Type) == "error" {
messageErrors++
log.Println("Error: Received error reply from",
v.Remote)
}
}
}
}
}()
}()
}
// Skip reading message if '-i' or '--interactive' is set to work with e.g. 'tail -f'.
if !*flagInteractive {
@ -533,17 +536,23 @@ func main() {
}
}
// Wait for 1s whether there will be incoming errors.
time.Sleep(1 * time.Second)
// Log if there were message errors reported.
switch messageErrors {
case 0:
break
case 1:
log.Fatal("There was one error reply.")
default:
log.Fatal("There were ", messageErrors, " error replies.")
if *flagCheckErrors {
// Wait for 0,5s whether there will be incoming errors.
time.Sleep(500 * time.Millisecond)
// Log if there were message errors reported.
switch messageErrors {
case 0:
break
case 1:
log.Fatal("There was one error reply.")
default:
log.Fatal("There were ", messageErrors, " error replies.")
}
} else {
// Wait for a short time as some messages are not delievered by the server
// if the connection is closed immediately after sending a message.
time.Sleep(100 * time.Millisecond)
}
// Close XMPP connection

Loading…
Cancel
Save