bug fix
This commit is contained in:
@@ -10,13 +10,13 @@ import (
|
||||
|
||||
// StarNotifyC 为Client端
|
||||
type StarNotifyC struct {
|
||||
connc net.Conn
|
||||
Connc net.Conn
|
||||
clientSign map[string]chan string
|
||||
// FuncLists 当不使用channel时,使用此记录调用函数
|
||||
FuncLists map[string]func(CMsg)
|
||||
clientStopSign chan int
|
||||
defaultFunc func(CMsg)
|
||||
// Stop 停止信号
|
||||
// Stop 停止信 号
|
||||
Stop chan int
|
||||
// UseChannel 是否使用channel作为信息传递
|
||||
UseChannel bool
|
||||
@@ -71,34 +71,34 @@ func NewNotifyC(netype, value string) (*StarNotifyC, error) {
|
||||
if strings.Index(netype, "udp") >= 0 {
|
||||
star.isUDP = true
|
||||
}
|
||||
star.connc, err = net.Dial(netype, value)
|
||||
star.Connc, err = net.Dial(netype, value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
go star.cnotify()
|
||||
go func() {
|
||||
<-star.clientStopSign
|
||||
star.notifychan <- 2
|
||||
star.Connc.Close()
|
||||
star.Stop <- 0
|
||||
star.Online = false
|
||||
return
|
||||
}()
|
||||
go func() {
|
||||
for {
|
||||
go func() {
|
||||
<-star.clientStopSign
|
||||
star.notifychan <- 2
|
||||
star.connc.Close()
|
||||
star.Stop <- 0
|
||||
star.Online = false
|
||||
return
|
||||
}()
|
||||
buf := make([]byte, 8192)
|
||||
n, err := star.connc.Read(buf)
|
||||
n, err := star.Connc.Read(buf)
|
||||
if n != 0 {
|
||||
star.Queue.ParseMessage(buf[0:n], star.Connc)
|
||||
}
|
||||
if err != nil {
|
||||
star.connc.Close()
|
||||
star.Connc.Close()
|
||||
star.Stop <- 1
|
||||
star.notifychan <- 3
|
||||
//star, _ = NewNotifyC(netype, value)
|
||||
star.Online = false
|
||||
return
|
||||
}
|
||||
if n != 0 {
|
||||
star.Queue.ParseMessage(buf[0:n], star.connc)
|
||||
}
|
||||
}
|
||||
}()
|
||||
star.Online = true
|
||||
@@ -107,13 +107,13 @@ func NewNotifyC(netype, value string) (*StarNotifyC, error) {
|
||||
|
||||
// Send 用于向Server端发送数据
|
||||
func (star *StarNotifyC) Send(name string) error {
|
||||
_, err := star.connc.Write(star.Queue.BuildMessage(name))
|
||||
_, err := star.Connc.Write(star.Queue.BuildMessage(name))
|
||||
return err
|
||||
}
|
||||
|
||||
// SendValue 用于向Server端发送key-value类型数据
|
||||
func (star *StarNotifyC) SendValue(name, value string) error {
|
||||
_, err := star.connc.Write(star.Queue.BuildMessage(name + "||" + value))
|
||||
_, err := star.Connc.Write(star.Queue.BuildMessage(name + "||" + value))
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user