This commit is contained in:
suyl
2021-07-30 18:56:48 +08:00
parent 9861e3edc5
commit a4b956c963
2 changed files with 14 additions and 13 deletions

View File

@@ -93,7 +93,6 @@ const (
)
var (
//t = &TcpClient{}
printErrMap = map[string]string{
printErrWithoutPaper: "打印机缺纸!",
}
@@ -107,9 +106,6 @@ var (
regexpQrr = regexp.MustCompile(byteSignQrRight + "(.*?)" + byteSignQrRightE)
regexpSound = regexp.MustCompile(byteSignSound + "(.*?)" + byteSignSoundE)
//printMsgChan = make(chan *model.PrintMsg, 1024)
//printMsgCallbackMap = make(map[string]chan string, 1024)
//printMsgChanFail = make(chan *model.PrintMsg, 1024)
timeoutChan = make(chan int, 10)
)
@@ -171,7 +167,7 @@ func (t *TcpClient) buildCallBackMap(key string) {
func (t *TcpClient) getPrintStatus(key string) int {
t.RLock()
defer t.RUnlock()
if t.isExist(key) {
if t.Clients[key] != nil {
return t.Clients[key].Status
} else {
return printerStatusOffline
@@ -181,7 +177,7 @@ func (t *TcpClient) getPrintStatus(key string) int {
func (t *TcpClient) getPrintConn(key string) net.Conn {
t.RLock()
defer t.RUnlock()
if t.isExist(key) {
if t.Clients[key] != nil {
return t.Clients[key].C
} else {
return nil
@@ -248,6 +244,17 @@ func (t *TcpClient) addCallbackChan(key, data string) {
t.CallBackMap[key] <- data
}
func (t *TcpClient) clear(key string) {
t.Lock()
defer t.Unlock()
t.Clients[key].C.Close()
delete(t.Clients, key)
close(t.MsgMap[key])
delete(t.MsgMap, key)
close(t.CallBackMap[key])
delete(t.CallBackMap, key)
}
func NewTcpClient() *TcpClient {
t := &TcpClient{
Clients: make(map[string]*PrintInfo),