aa
This commit is contained in:
@@ -22,10 +22,7 @@ func ListenTcp() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
globals.SugarLogger.Debugf("begin listenTcp port 8000......")
|
globals.SugarLogger.Debugf("begin listenTcp port 8000......")
|
||||||
//go t.HandleTcpMessages()
|
|
||||||
go t.HandleCheckTcpHeart()
|
go t.HandleCheckTcpHeart()
|
||||||
//go t.doPrint2()
|
|
||||||
//go t.doPrint(printMsgChanFail)
|
|
||||||
for {
|
for {
|
||||||
c, err := l.Accept()
|
c, err := l.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -90,7 +87,6 @@ func (t *TcpClient) handleConn(c net.Conn) {
|
|||||||
t.setPrintStatus(printNo, status)
|
t.setPrintStatus(printNo, status)
|
||||||
}
|
}
|
||||||
globals.SugarLogger.Debugf("handleConn print model %v", utils.Format4Output(t.Clients[printNo], true))
|
globals.SugarLogger.Debugf("handleConn print model %v", utils.Format4Output(t.Clients[printNo], true))
|
||||||
//}
|
|
||||||
} else if strings.Contains(data, printText) {
|
} else if strings.Contains(data, printText) {
|
||||||
globals.SugarLogger.Debugf("handleConn print callback: %v", data)
|
globals.SugarLogger.Debugf("handleConn print callback: %v", data)
|
||||||
_, printNo = getCallbackMsgInfo(data)
|
_, printNo = getCallbackMsgInfo(data)
|
||||||
@@ -238,9 +234,7 @@ func (t *TcpClient) HandleCheckTcpHeart() {
|
|||||||
for _, v := range keys {
|
for _, v := range keys {
|
||||||
changePrinterStatus(v, printerStatusOffline)
|
changePrinterStatus(v, printerStatusOffline)
|
||||||
if t.isExist(v) {
|
if t.isExist(v) {
|
||||||
t.Lock()
|
t.clear(v)
|
||||||
delete(t.Clients, v)
|
|
||||||
t.Unlock()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//t = &TcpClient{}
|
|
||||||
printErrMap = map[string]string{
|
printErrMap = map[string]string{
|
||||||
printErrWithoutPaper: "打印机缺纸!",
|
printErrWithoutPaper: "打印机缺纸!",
|
||||||
}
|
}
|
||||||
@@ -107,9 +106,6 @@ var (
|
|||||||
regexpQrr = regexp.MustCompile(byteSignQrRight + "(.*?)" + byteSignQrRightE)
|
regexpQrr = regexp.MustCompile(byteSignQrRight + "(.*?)" + byteSignQrRightE)
|
||||||
regexpSound = regexp.MustCompile(byteSignSound + "(.*?)" + byteSignSoundE)
|
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)
|
timeoutChan = make(chan int, 10)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -171,7 +167,7 @@ func (t *TcpClient) buildCallBackMap(key string) {
|
|||||||
func (t *TcpClient) getPrintStatus(key string) int {
|
func (t *TcpClient) getPrintStatus(key string) int {
|
||||||
t.RLock()
|
t.RLock()
|
||||||
defer t.RUnlock()
|
defer t.RUnlock()
|
||||||
if t.isExist(key) {
|
if t.Clients[key] != nil {
|
||||||
return t.Clients[key].Status
|
return t.Clients[key].Status
|
||||||
} else {
|
} else {
|
||||||
return printerStatusOffline
|
return printerStatusOffline
|
||||||
@@ -181,7 +177,7 @@ func (t *TcpClient) getPrintStatus(key string) int {
|
|||||||
func (t *TcpClient) getPrintConn(key string) net.Conn {
|
func (t *TcpClient) getPrintConn(key string) net.Conn {
|
||||||
t.RLock()
|
t.RLock()
|
||||||
defer t.RUnlock()
|
defer t.RUnlock()
|
||||||
if t.isExist(key) {
|
if t.Clients[key] != nil {
|
||||||
return t.Clients[key].C
|
return t.Clients[key].C
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
@@ -248,6 +244,17 @@ func (t *TcpClient) addCallbackChan(key, data string) {
|
|||||||
t.CallBackMap[key] <- data
|
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 {
|
func NewTcpClient() *TcpClient {
|
||||||
t := &TcpClient{
|
t := &TcpClient{
|
||||||
Clients: make(map[string]*PrintInfo),
|
Clients: make(map[string]*PrintInfo),
|
||||||
|
|||||||
Reference in New Issue
Block a user