mirror of https://github.com/qwc/backive.git
Fix retrying ui connection
This commit is contained in:
parent
0e98dc93e9
commit
559e7f72b3
|
@ -58,36 +58,41 @@ func PollConnection() {
|
||||||
log.Println("Creating connection")
|
log.Println("Creating connection")
|
||||||
c, err = net.Dial("unix", config.Settings.UIUnixSocketLocation)
|
c, err = net.Dial("unix", config.Settings.UIUnixSocketLocation)
|
||||||
} // else already connected
|
} // else already connected
|
||||||
// handle error on connection
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
// ignore
|
|
||||||
err = nil
|
|
||||||
c = nil
|
|
||||||
// sleep a while and then retry
|
|
||||||
time.Sleep(10 * time.Second)
|
|
||||||
}
|
|
||||||
// receive msgs
|
// receive msgs
|
||||||
if c != nil {
|
if c != nil && err == nil {
|
||||||
data := make([]byte, 2048)
|
data := make([]byte, 2048)
|
||||||
nr, err := c.Read(data)
|
nr, err := c.Read(data)
|
||||||
log.Printf("Read %d bytes...", nr)
|
log.Printf("Read %d bytes...", nr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Printf("Error reading data from socket: %s", err)
|
||||||
break
|
c = nil
|
||||||
}
|
}
|
||||||
|
if err == nil {
|
||||||
sdata := string(bytes.Trim(data, "\x00"))
|
sdata := string(bytes.Trim(data, "\x00"))
|
||||||
var message map[string]string
|
var message map[string]string
|
||||||
log.Printf("Reading JSON: %s", sdata)
|
log.Printf("Reading JSON: %s", sdata)
|
||||||
errjson := json.Unmarshal([]byte(sdata), &message)
|
errjson := json.Unmarshal([]byte(sdata), &message)
|
||||||
if errjson != nil {
|
if errjson != nil {
|
||||||
log.Println(errjson)
|
err = errjson
|
||||||
continue
|
log.Printf("Error parsing json: %s", errjson)
|
||||||
|
c = nil
|
||||||
}
|
}
|
||||||
|
if errjson == nil {
|
||||||
ShowNotification(message)
|
ShowNotification(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// handle error on connection
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error during communication: %s", err)
|
||||||
|
// ignore
|
||||||
|
err = nil
|
||||||
|
c = nil
|
||||||
|
// sleep a while and then retry
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ShowNotification shows a single notification
|
// ShowNotification shows a single notification
|
||||||
func ShowNotification(data map[string]string) {
|
func ShowNotification(data map[string]string) {
|
||||||
|
|
Loading…
Reference in New Issue