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