This commit is contained in:
aozhiwei 2023-08-10 17:56:04 +08:00
parent a6cca0a465
commit 51b43e47cf
5 changed files with 62 additions and 6 deletions

View File

@ -3,20 +3,36 @@ package main
import ( import (
"net" "net"
"fmt" "fmt"
"q5"
"f5"
"cs"
) )
type MsgHdr struct {
conn net.Conn
msgId int
seqId int
data []byte
msg interface{}
entry q5.ListHead
}
type WSPListener_ struct { type WSPListener_ struct {
listener net.Listener listener net.Listener
ch <-chan *MsgHdr
} }
var WSPListener = new (WSPListener_) var WSPListener = new (WSPListener_)
func (this *WSPListener_) Init() { func (this *WSPListener_) Init() {
this.ch = make(chan *MsgHdr)
listener, err := net.Listen("tcp", "0.0.0.0:8888") listener, err := net.Listen("tcp", "0.0.0.0:8888")
if err != nil { if err != nil {
} else { } else {
this.listener = listener this.listener = listener
go this.parseNetPkt()
go this.accept() go this.accept()
} }
} }
@ -54,19 +70,33 @@ func (this *WSPListener_) socketRead(conn net.Conn) {
if err == nil && bufLen > 0 { if err == nil && bufLen > 0 {
warning := false warning := false
for bufLen - offset >= 12 { for bufLen - offset >= 12 {
packLen := int(buf[0]) >> 16 + int(buf[1])
if buf[8] == 'K' && buf[9] == 'S' { if buf[8] == 'K' && buf[9] == 'S' {
packLen := int(buf[0]) >> 16 + int(buf[1])
if bufLen - offset < 12 + packLen { if bufLen - offset < 12 + packLen {
continue continue
} }
hdr := new(MsgHdr)
hdr.msgId = int(buf[0]) >> 16 + int(buf[1])
hdr.seqId = int(buf[0]) >> 16 + int(buf[1])
offset += 12 + packLen offset += 12 + packLen
} else { } else {
warning = true warning = true
offset += 1 offset++
continue continue
} }
} }
if warning { if warning {
f5.SysLog().Warning("收到client非法数据包")
}
}
}
}
func (this *WSPListener_) parseNetPkt() {
for {
if hdr, ok := <-this.ch; ok {
hdr.msg = cs.ParsePb(hdr.msgId, hdr.data)
if hdr.msg != nil {
} }
} }

View File

@ -3,6 +3,7 @@ package main
import ( import (
"time" "time"
"fmt" "fmt"
"sync"
"q5" "q5"
"f5" "f5"
@ -10,6 +11,8 @@ import (
type App_ struct { type App_ struct {
f5.App_ f5.App_
msgMutex sync.Mutex
msgList q5.ListHead
} }
var App = new (App_) var App = new (App_)
@ -17,7 +20,8 @@ var App = new (App_)
func (this *App_) Init() { func (this *App_) Init() {
f5.App = &this.App_ f5.App = &this.App_
f5.App.SetPkgName("imserver") f5.App.SetPkgName("imserver")
this.App_.Init() this.App_.Init(this.Update)
this.msgList.Init(nil)
WSPListener.Init() WSPListener.Init()
go this.goReportServerState(); go this.goReportServerState();
} }
@ -27,6 +31,9 @@ func (this *App_) UnInit() {
this.App_.UnInit() this.App_.UnInit()
} }
func (this *App_) Update() {
}
func (this *App_) goReportServerState() { func (this *App_) goReportServerState() {
for { for {
params := q5.NewMxoObject() params := q5.NewMxoObject()
@ -46,3 +53,13 @@ func (this *App_) goReportServerState() {
time.Sleep(time.Duration(1) * time.Second) time.Sleep(time.Duration(1) * time.Second)
} }
} }
func (this *App_) addNetMsg(hdr *MsgHdr) {
{
this.msgMutex.Lock()
defer this.msgMutex.Unlock()
this.msgList.AddTail(&hdr.entry);
}
this.NotifyLoopCond()
}

View File

@ -0,0 +1,5 @@
package cs
func ParsePb(msgId int, data []byte) interface{} {
return nil
}

View File

@ -2,12 +2,14 @@ module imserver
go 1.20 go 1.20
require q5 v1.0.0 // indirect require q5 v1.0.0
require f5 v1.0.0 require f5 v1.0.0
require mtb v1.0.0 require mtb v1.0.0
require cs v1.0.0
require ( require (
github.com/go-sql-driver/mysql v1.5.0 // indirect github.com/go-sql-driver/mysql v1.5.0 // indirect
github.com/golang/protobuf v1.4.2 // indirect github.com/golang/protobuf v1.4.2 // indirect
@ -19,4 +21,6 @@ replace q5 => ../../third_party/q5
replace f5 => ../../third_party/f5 replace f5 => ../../third_party/f5
replace mtb => ./mtb replace mtb => ./mtb
replace cs => ./cs

2
third_party/f5 vendored

@ -1 +1 @@
Subproject commit efc8db84bc297223ef9e124fffb76ecc1d33899f Subproject commit 6aa5ba1546beb17e9dc6055fe672dce1d4164686