aa
This commit is contained in:
@@ -22,7 +22,6 @@ func ListenTcp() {
|
||||
return
|
||||
}
|
||||
globals.SugarLogger.Debugf("begin listenTcp port 8000......")
|
||||
go t.HandleCheckTcpHeart()
|
||||
for {
|
||||
c, err := l.Accept()
|
||||
if err != nil {
|
||||
@@ -83,6 +82,7 @@ func (t *TcpClient) handleConn(c net.Conn) {
|
||||
}
|
||||
changePrinterStatus(printNo, status)
|
||||
}
|
||||
t.HandleCheckTcpHeart(printNo)
|
||||
if t.getPrintStatus(printNo) != status {
|
||||
t.setPrintStatus(printNo, status)
|
||||
changePrinterStatus(printNo, status)
|
||||
@@ -219,23 +219,32 @@ func (t *TcpClient) doPrint(key string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *TcpClient) HandleCheckTcpHeart() {
|
||||
for {
|
||||
keys := []string{}
|
||||
t.RLock()
|
||||
for k, v := range t.Clients {
|
||||
if time.Now().Sub(v.StatusTime) > time.Minute+time.Second {
|
||||
v.Status = printerStatusOffline
|
||||
keys = append(keys, k)
|
||||
func (t *TcpClient) HandleCheckTcpHeart(key string) {
|
||||
go func() {
|
||||
for {
|
||||
if time.Now().Sub(t.getPrintStatusTime(key)) > time.Minute+time.Second {
|
||||
changePrinterStatus(key, printerStatusOffline)
|
||||
if t.isExist(key) {
|
||||
t.clear(key)
|
||||
return
|
||||
}
|
||||
}
|
||||
//keys := []string{}
|
||||
//t.RLock()
|
||||
//for k, v := range t.Clients {
|
||||
// if time.Now().Sub(v.StatusTime) > time.Minute+time.Second {
|
||||
// v.Status = printerStatusOffline
|
||||
// keys = append(keys, k)
|
||||
// }
|
||||
//}
|
||||
//t.RUnlock()
|
||||
//globals.SugarLogger.Debugf("HandleCheckTcpHeart del keys: %v", keys)
|
||||
//for _, v := range keys {
|
||||
// changePrinterStatus(v, printerStatusOffline)
|
||||
// if t.isExist(v) {
|
||||
// t.clear(v)
|
||||
// }
|
||||
//}
|
||||
}
|
||||
t.RUnlock()
|
||||
globals.SugarLogger.Debugf("HandleCheckTcpHeart del keys: %v", keys)
|
||||
for _, v := range keys {
|
||||
changePrinterStatus(v, printerStatusOffline)
|
||||
if t.isExist(v) {
|
||||
t.clear(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -184,6 +184,16 @@ func (t *TcpClient) getPrintConn(key string) net.Conn {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TcpClient) getPrintStatusTime(key string) time.Time {
|
||||
t.RLock()
|
||||
defer t.RUnlock()
|
||||
if t.Clients[key] != nil {
|
||||
return t.Clients[key].StatusTime
|
||||
} else {
|
||||
return utils.ZeroTimeValue
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TcpClient) isExistMsg(key string) bool {
|
||||
t.RLock()
|
||||
defer t.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user