|
|
|
@ -31,6 +31,13 @@ type StarNotifyS struct {
|
|
|
|
|
UDPConn *net.UDPConn
|
|
|
|
|
// Online 当前链接是否处于活跃状态
|
|
|
|
|
Online bool
|
|
|
|
|
// ReadDeadline tcp/unix中读超时设置,udp请直接调用UDPConn
|
|
|
|
|
ReadDeadline time.Time
|
|
|
|
|
// WriteDeadline tcp/unix中写超时设置,udp请直接调用UDPConn
|
|
|
|
|
WriteDeadline time.Time
|
|
|
|
|
|
|
|
|
|
// Deadline tcp/unix中超时设置,udp请直接调用UDPConn
|
|
|
|
|
Deadline time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SMsg 指明当前服务端被通知的关键字
|
|
|
|
@ -94,8 +101,6 @@ func doudps(netype, value string) (*StarNotifyS, error) {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
go star.notify()
|
|
|
|
|
go func() {
|
|
|
|
|
for {
|
|
|
|
|
go func() {
|
|
|
|
|
<-star.serverStopSign
|
|
|
|
|
star.notifychan <- 1
|
|
|
|
@ -108,6 +113,7 @@ func doudps(netype, value string) (*StarNotifyS, error) {
|
|
|
|
|
star.Online = false
|
|
|
|
|
return
|
|
|
|
|
}()
|
|
|
|
|
go func() {
|
|
|
|
|
for {
|
|
|
|
|
buf := make([]byte, 8192)
|
|
|
|
|
n, addr, err := star.UDPConn.ReadFromUDP(buf)
|
|
|
|
@ -119,7 +125,6 @@ func doudps(netype, value string) (*StarNotifyS, error) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
star.Online = true
|
|
|
|
|
return &star, nil
|
|
|
|
@ -134,8 +139,6 @@ func notudps(netype, value string) (*StarNotifyS, error) {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
go star.notify()
|
|
|
|
|
go func() {
|
|
|
|
|
for {
|
|
|
|
|
go func() {
|
|
|
|
|
<-star.serverStopSign
|
|
|
|
|
star.notifychan <- 3
|
|
|
|
@ -148,7 +151,8 @@ func notudps(netype, value string) (*StarNotifyS, error) {
|
|
|
|
|
star.Online = false
|
|
|
|
|
return
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
for {
|
|
|
|
|
conn, err := listener.Accept()
|
|
|
|
|
if err != nil {
|
|
|
|
|
select {
|
|
|
|
@ -159,6 +163,15 @@ func notudps(netype, value string) (*StarNotifyS, error) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !star.ReadDeadline.IsZero() {
|
|
|
|
|
conn.SetReadDeadline(star.ReadDeadline)
|
|
|
|
|
}
|
|
|
|
|
if !star.WriteDeadline.IsZero() {
|
|
|
|
|
conn.SetWriteDeadline(star.WriteDeadline)
|
|
|
|
|
}
|
|
|
|
|
if !star.Deadline.IsZero() {
|
|
|
|
|
conn.SetDeadline(star.Deadline)
|
|
|
|
|
}
|
|
|
|
|
go func(conn net.Conn) {
|
|
|
|
|
for {
|
|
|
|
|
buf := make([]byte, 8192)
|
|
|
|
@ -213,21 +226,23 @@ func (star *StarNotifyS) notify() {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
go func() {
|
|
|
|
|
if msg, ok := star.FuncLists[key]; ok {
|
|
|
|
|
sdata := msg(rmsg)
|
|
|
|
|
if sdata == "" {
|
|
|
|
|
continue
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
rmsg.Reply(sdata)
|
|
|
|
|
} else {
|
|
|
|
|
if star.defaultFunc != nil {
|
|
|
|
|
sdata := star.defaultFunc(rmsg)
|
|
|
|
|
if sdata == "" {
|
|
|
|
|
continue
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
rmsg.Reply(sdata)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|