summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimportd/ctrlTelnet.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-21 21:41:22 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-21 21:41:22 (GMT)
commitb917755aab166ebb59ebdb5356114d373ce5cb91 (patch)
tree72d74a4a8989e0ba3cde5f83bd08ffb00bdde446 /src/helsinki.at/rhimportd/ctrlTelnet.go
parent0912ca15a61bc9eba102fc967367f8c1665842dc (diff)
improved error handling and reporting, canceling running requests when telnet client leaves
Diffstat (limited to 'src/helsinki.at/rhimportd/ctrlTelnet.go')
-rw-r--r--src/helsinki.at/rhimportd/ctrlTelnet.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlTelnet.go b/src/helsinki.at/rhimportd/ctrlTelnet.go
index 41ac7f2..b47d2a1 100644
--- a/src/helsinki.at/rhimportd/ctrlTelnet.go
+++ b/src/helsinki.at/rhimportd/ctrlTelnet.go
@@ -283,15 +283,13 @@ func telnet_cmd_run(ctx rhimport.ImportContext, out chan<- string) {
out <- fmt.Sprintf("\nimporting file '%s'\n", ctx.SourceFile)
if res, err := rhimport.ImportFile(&ctx); err != nil {
- out <- fmt.Sprintf("import file error: %s\n", err)
+ out <- fmt.Sprintf("\nimport file error: %s\n", err)
return
} else {
if res.ResponseCode == http.StatusOK {
out <- fmt.Sprintf("\nFile got succesfully imported into Cart/Cut %d/%d\n", res.Cart, res.Cut)
- rhl.Printf("File got succesfully imported into Cart/Cut %d/%d", res.Cart, res.Cut)
} else {
- out <- fmt.Sprintf("Fileimport has failed (Cart/Cut %d/%d): %s\n", res.Cart, res.Cut, res.ErrorString)
- rhl.Printf("Fileimport has failed (Cart/Cut %d/%d): %s", res.Cart, res.Cut, res.ErrorString)
+ out <- fmt.Sprintf("\nFileimport has failed (Cart/Cut %d/%d): %s\n", res.Cart, res.Cut, res.ErrorString)
}
}
}
@@ -362,7 +360,7 @@ func (c *TelnetClient) handle_iac(iac []byte, cancel chan<- bool) bool {
case IP:
select {
case cancel <- true:
- default: // process got canceled already
+ default: // process got canceled already
}
return false
default:
@@ -454,6 +452,13 @@ func (c *TelnetClient) handle() {
done := make(chan bool)
cancel := make(chan bool, 1)
+ defer func() { // make sure to cancel possible running job when closing connection
+ select {
+ case cancel <- true:
+ default:
+ }
+ }()
+
c.write_string(prompt)
for {
select {