add comment

This commit is contained in:
2019-11-14 14:50:19 +08:00
parent 2cf31950e2
commit 0ca8a71e8d
2 changed files with 30 additions and 2 deletions
+12 -2
View File
@@ -1,3 +1,4 @@
// Package notify is a package which provide common tcp/udp/unix socket service
package notify
import (
@@ -7,18 +8,23 @@ import (
"b612.me/starainrt"
)
// Queue 是用来处理收发信息的简单消息队列
var Queue *starainrt.StarQueue
// FuncLists 记录了被通知项所记录的函数
var FuncLists map[string]func(NetMsg) string
var serverStopSign chan int
var notifychan chan int
// NetMsg 指明当前被通知的关键字
type NetMsg struct {
Conn net.Conn
key string
}
func (this *NetMsg) Send(msg string) error {
_, err := this.Conn.Write(Queue.BuildMessage(this.key + "||" + msg))
// Send 用于向client端发送数据
func (nmsg *NetMsg) Send(msg string) error {
_, err := nmsg.Conn.Write(Queue.BuildMessage(nmsg.key + "||" + msg))
return err
}
@@ -27,6 +33,8 @@ func init() {
Queue = starainrt.NewQueue()
FuncLists = make(map[string]func(NetMsg) string)
}
// NewNotifyS 开启一个新的Server端通知
func NewNotifyS(netype, value string) error {
listener, err := net.Listen(netype, value)
if err == nil {
@@ -67,6 +75,7 @@ func NewNotifyS(netype, value string) error {
return err
}
// SetNotify 用于设置通知关键词和调用函数
func SetNotify(name string, data func(NetMsg) string) {
FuncLists[name] = data
}
@@ -96,6 +105,7 @@ func notify() {
}
}
// ServerStop 用于终止Server端运行
func ServerStop() {
serverStopSign <- 0
}