aa
This commit is contained in:
@@ -167,7 +167,7 @@ func (t *TcpClient) HandleTcpMessages(printNo string) {
|
|||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timeoutChan:
|
case <-t.TimeoutChan:
|
||||||
globals.SugarLogger.Debugf("HandleTcpMessages timeout")
|
globals.SugarLogger.Debugf("HandleTcpMessages timeout")
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
@@ -196,7 +196,7 @@ func (t *TcpClient) doPrint(key string) (err error) {
|
|||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timeoutChan:
|
case <-t.TimeoutChan:
|
||||||
globals.SugarLogger.Debugf("doPrint timeout")
|
globals.SugarLogger.Debugf("doPrint timeout")
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
@@ -233,7 +233,7 @@ func (t *TcpClient) doPrint(key string) (err error) {
|
|||||||
dao.UpdateEntity(db, printMsg, "Status", "Comment")
|
dao.UpdateEntity(db, printMsg, "Status", "Comment")
|
||||||
if t.isExist(key) {
|
if t.isExist(key) {
|
||||||
t.clear(key)
|
t.clear(key)
|
||||||
close(timeoutChan)
|
close(t.TimeoutChan)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
@@ -243,7 +243,7 @@ func (t *TcpClient) doPrint(key string) (err error) {
|
|||||||
//t.delConn(printMsg.PrintNo)
|
//t.delConn(printMsg.PrintNo)
|
||||||
if t.isExist(key) {
|
if t.isExist(key) {
|
||||||
t.clear(key)
|
t.clear(key)
|
||||||
close(timeoutChan)
|
close(t.TimeoutChan)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data))
|
globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data))
|
||||||
@@ -266,7 +266,7 @@ func (t *TcpClient) HandleCheckTcpHeart(key string) {
|
|||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timeoutChan:
|
case <-t.TimeoutChan:
|
||||||
globals.SugarLogger.Debugf("HandleCheckTcpHeart timeout")
|
globals.SugarLogger.Debugf("HandleCheckTcpHeart timeout")
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
@@ -276,7 +276,7 @@ func (t *TcpClient) HandleCheckTcpHeart(key string) {
|
|||||||
changePrinterStatus(key, printerStatusOffline)
|
changePrinterStatus(key, printerStatusOffline)
|
||||||
if t.isExist(key) {
|
if t.isExist(key) {
|
||||||
t.clear(key)
|
t.clear(key)
|
||||||
close(timeoutChan)
|
close(t.TimeoutChan)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,8 +107,6 @@ var (
|
|||||||
regexpQrl = regexp.MustCompile(byteSignQrLeft + "(.*?)" + byteSignQrLeftE)
|
regexpQrl = regexp.MustCompile(byteSignQrLeft + "(.*?)" + byteSignQrLeftE)
|
||||||
regexpQrr = regexp.MustCompile(byteSignQrRight + "(.*?)" + byteSignQrRightE)
|
regexpQrr = regexp.MustCompile(byteSignQrRight + "(.*?)" + byteSignQrRightE)
|
||||||
regexpSound = regexp.MustCompile(byteSignSound + "(.*?)" + byteSignSoundE)
|
regexpSound = regexp.MustCompile(byteSignSound + "(.*?)" + byteSignSoundE)
|
||||||
|
|
||||||
timeoutChan = make(chan bool)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PrintInfo struct {
|
type PrintInfo struct {
|
||||||
@@ -122,6 +120,7 @@ type TcpClient struct {
|
|||||||
Clients map[string]*PrintInfo //放tcp连接的,printNo 为key
|
Clients map[string]*PrintInfo //放tcp连接的,printNo 为key
|
||||||
MsgMap map[string]chan *model.PrintMsg //放打印信息的,printNo为key
|
MsgMap map[string]chan *model.PrintMsg //放打印信息的,printNo为key
|
||||||
CallBackMap map[string]chan string //放打印信息回调信息的,printNo为key
|
CallBackMap map[string]chan string //放打印信息回调信息的,printNo为key
|
||||||
|
TimeoutChan chan bool //退出channel
|
||||||
*sync.RWMutex
|
*sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,6 +149,9 @@ func (t *TcpClient) addConn(c net.Conn, key string, status int) {
|
|||||||
Status: status,
|
Status: status,
|
||||||
StatusTime: time.Now(),
|
StatusTime: time.Now(),
|
||||||
}
|
}
|
||||||
|
if t.TimeoutChan == nil {
|
||||||
|
t.TimeoutChan = make(chan bool)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TcpClient) buildMsgMap(key string) {
|
func (t *TcpClient) buildMsgMap(key string) {
|
||||||
@@ -281,6 +283,7 @@ func NewTcpClient() *TcpClient {
|
|||||||
Clients: make(map[string]*PrintInfo),
|
Clients: make(map[string]*PrintInfo),
|
||||||
CallBackMap: make(map[string]chan string),
|
CallBackMap: make(map[string]chan string),
|
||||||
MsgMap: make(map[string]chan *model.PrintMsg),
|
MsgMap: make(map[string]chan *model.PrintMsg),
|
||||||
|
TimeoutChan: make(chan bool),
|
||||||
}
|
}
|
||||||
t.RWMutex = new(sync.RWMutex)
|
t.RWMutex = new(sync.RWMutex)
|
||||||
return t
|
return t
|
||||||
|
|||||||
Reference in New Issue
Block a user