|
|
@ -31,6 +31,13 @@ type StarNotifyS struct {
|
|
|
|
UDPConn *net.UDPConn
|
|
|
|
UDPConn *net.UDPConn
|
|
|
|
// Online 当前链接是否处于活跃状态
|
|
|
|
// Online 当前链接是否处于活跃状态
|
|
|
|
Online bool
|
|
|
|
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 指明当前服务端被通知的关键字
|
|
|
|
// SMsg 指明当前服务端被通知的关键字
|
|
|
@ -94,30 +101,28 @@ func doudps(netype, value string) (*StarNotifyS, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
go star.notify()
|
|
|
|
go star.notify()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
<-star.serverStopSign
|
|
|
|
|
|
|
|
star.notifychan <- 1
|
|
|
|
|
|
|
|
star.notifychan <- 2
|
|
|
|
|
|
|
|
for k, v := range star.udpPool {
|
|
|
|
|
|
|
|
star.UDPConn.WriteToUDP(star.Queue.BuildMessage("b612ryzstop"), v)
|
|
|
|
|
|
|
|
delete(star.connPool, k)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
star.UDPConn.Close()
|
|
|
|
|
|
|
|
star.Online = false
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
go func() {
|
|
|
|
buf := make([]byte, 8192)
|
|
|
|
<-star.serverStopSign
|
|
|
|
n, addr, err := star.UDPConn.ReadFromUDP(buf)
|
|
|
|
star.notifychan <- 1
|
|
|
|
if n != 0 {
|
|
|
|
star.notifychan <- 2
|
|
|
|
star.Queue.ParseMessage(buf[0:n], addr)
|
|
|
|
for k, v := range star.udpPool {
|
|
|
|
star.udpPool[addr.String()] = addr
|
|
|
|
star.UDPConn.WriteToUDP(star.Queue.BuildMessage("b612ryzstop"), v)
|
|
|
|
}
|
|
|
|
delete(star.connPool, k)
|
|
|
|
if err != nil {
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
star.UDPConn.Close()
|
|
|
|
|
|
|
|
star.Online = false
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
|
|
|
buf := make([]byte, 8192)
|
|
|
|
|
|
|
|
n, addr, err := star.UDPConn.ReadFromUDP(buf)
|
|
|
|
|
|
|
|
if n != 0 {
|
|
|
|
|
|
|
|
star.Queue.ParseMessage(buf[0:n], addr)
|
|
|
|
|
|
|
|
star.udpPool[addr.String()] = addr
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
@ -134,21 +139,20 @@ func notudps(netype, value string) (*StarNotifyS, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
go star.notify()
|
|
|
|
go star.notify()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
<-star.serverStopSign
|
|
|
|
|
|
|
|
star.notifychan <- 3
|
|
|
|
|
|
|
|
star.notifychan <- 4
|
|
|
|
|
|
|
|
for k, v := range star.connPool {
|
|
|
|
|
|
|
|
v.Close()
|
|
|
|
|
|
|
|
delete(star.connPool, k)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
listener.Close()
|
|
|
|
|
|
|
|
star.Online = false
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
<-star.serverStopSign
|
|
|
|
|
|
|
|
star.notifychan <- 3
|
|
|
|
|
|
|
|
star.notifychan <- 4
|
|
|
|
|
|
|
|
for k, v := range star.connPool {
|
|
|
|
|
|
|
|
v.Close()
|
|
|
|
|
|
|
|
delete(star.connPool, k)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
listener.Close()
|
|
|
|
|
|
|
|
star.Online = false
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conn, err := listener.Accept()
|
|
|
|
conn, err := listener.Accept()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
select {
|
|
|
|
select {
|
|
|
@ -159,6 +163,15 @@ func notudps(netype, value string) (*StarNotifyS, error) {
|
|
|
|
continue
|
|
|
|
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) {
|
|
|
|
go func(conn net.Conn) {
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
buf := make([]byte, 8192)
|
|
|
|
buf := make([]byte, 8192)
|
|
|
@ -213,21 +226,23 @@ func (star *StarNotifyS) notify() {
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if msg, ok := star.FuncLists[key]; ok {
|
|
|
|
go func() {
|
|
|
|
sdata := msg(rmsg)
|
|
|
|
if msg, ok := star.FuncLists[key]; ok {
|
|
|
|
if sdata == "" {
|
|
|
|
sdata := msg(rmsg)
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rmsg.Reply(sdata)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if star.defaultFunc != nil {
|
|
|
|
|
|
|
|
sdata := star.defaultFunc(rmsg)
|
|
|
|
|
|
|
|
if sdata == "" {
|
|
|
|
if sdata == "" {
|
|
|
|
continue
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rmsg.Reply(sdata)
|
|
|
|
rmsg.Reply(sdata)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if star.defaultFunc != nil {
|
|
|
|
|
|
|
|
sdata := star.defaultFunc(rmsg)
|
|
|
|
|
|
|
|
if sdata == "" {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rmsg.Reply(sdata)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|