parent
9b118b3aaa
commit
4f9722a9ce
|
@ -14,6 +14,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -147,12 +148,8 @@ func main() {
|
||||||
d4.cka = *cka
|
d4.cka = *cka
|
||||||
d4.retry = *retry
|
d4.retry = *retry
|
||||||
|
|
||||||
// Output logging before closing if debug is enabled
|
s := make(chan os.Signal, 1)
|
||||||
if *debug == true {
|
signal.Notify(s, os.Interrupt, os.Kill)
|
||||||
d4.debug = true
|
|
||||||
defer fmt.Print(&buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
c := make(chan string)
|
c := make(chan string)
|
||||||
k := make(chan string)
|
k := make(chan string)
|
||||||
for {
|
for {
|
||||||
|
@ -168,14 +165,28 @@ func main() {
|
||||||
panic("Unrecoverable error without retry.")
|
panic("Unrecoverable error without retry.")
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case <-c:
|
case str := <-c:
|
||||||
|
fmt.Println(str)
|
||||||
continue
|
continue
|
||||||
case <-k:
|
case str := <-k:
|
||||||
os.Exit(0)
|
fmt.Println(str)
|
||||||
|
exit(d4p, 1)
|
||||||
|
case <-s:
|
||||||
|
fmt.Println(" Exiting")
|
||||||
|
exit(d4p, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func exit(d4 *d4S, exitcode int) {
|
||||||
|
// Output logging before closing if debug is enabled
|
||||||
|
if *debug == true {
|
||||||
|
(*d4).debug = true
|
||||||
|
fmt.Print(&buf)
|
||||||
|
}
|
||||||
|
os.Exit(exitcode)
|
||||||
|
}
|
||||||
|
|
||||||
func set(d4 *d4S) bool {
|
func set(d4 *d4S) bool {
|
||||||
if d4loadConfig(d4) {
|
if d4loadConfig(d4) {
|
||||||
if setReaderWriters(d4) {
|
if setReaderWriters(d4) {
|
||||||
|
@ -190,10 +201,16 @@ func set(d4 *d4S) bool {
|
||||||
func d4Copy(d4 *d4S, c chan string, k chan string) {
|
func d4Copy(d4 *d4S, c chan string, k chan string) {
|
||||||
nread, err := io.CopyBuffer(&d4.dst, d4.src, d4.dst.pb)
|
nread, err := io.CopyBuffer(&d4.dst, d4.src, d4.dst.pb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c <- fmt.Sprintf("%s", err)
|
if (d4.retry.Seconds()) > 0 {
|
||||||
|
c <- fmt.Sprintf("%s", err)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
k <- fmt.Sprintf("%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
infof(fmt.Sprintf("Nread: %d, err: %s", nread, err))
|
k <- fmt.Sprintf("EOF: Nread: %d", nread)
|
||||||
k <- "EOF or connection reset: we the drop mic."
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func readConfFile(d4 *d4S, fileName string) []byte {
|
func readConfFile(d4 *d4S, fileName string) []byte {
|
||||||
|
|
Loading…
Reference in New Issue