1
This commit is contained in:
parent
a6cca0a465
commit
51b43e47cf
@ -3,20 +3,36 @@ package main
|
||||
import (
|
||||
"net"
|
||||
"fmt"
|
||||
|
||||
"q5"
|
||||
"f5"
|
||||
"cs"
|
||||
)
|
||||
|
||||
type MsgHdr struct {
|
||||
conn net.Conn
|
||||
msgId int
|
||||
seqId int
|
||||
data []byte
|
||||
msg interface{}
|
||||
entry q5.ListHead
|
||||
}
|
||||
|
||||
type WSPListener_ struct {
|
||||
listener net.Listener
|
||||
ch <-chan *MsgHdr
|
||||
}
|
||||
|
||||
var WSPListener = new (WSPListener_)
|
||||
|
||||
func (this *WSPListener_) Init() {
|
||||
this.ch = make(chan *MsgHdr)
|
||||
listener, err := net.Listen("tcp", "0.0.0.0:8888")
|
||||
if err != nil {
|
||||
|
||||
} else {
|
||||
this.listener = listener
|
||||
go this.parseNetPkt()
|
||||
go this.accept()
|
||||
}
|
||||
}
|
||||
@ -54,19 +70,33 @@ func (this *WSPListener_) socketRead(conn net.Conn) {
|
||||
if err == nil && bufLen > 0 {
|
||||
warning := false
|
||||
for bufLen - offset >= 12 {
|
||||
packLen := int(buf[0]) >> 16 + int(buf[1])
|
||||
if buf[8] == 'K' && buf[9] == 'S' {
|
||||
packLen := int(buf[0]) >> 16 + int(buf[1])
|
||||
if bufLen - offset < 12 + packLen {
|
||||
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
|
||||
} else {
|
||||
warning = true
|
||||
offset += 1
|
||||
offset++
|
||||
continue
|
||||
}
|
||||
}
|
||||
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 {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"time"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"q5"
|
||||
"f5"
|
||||
@ -10,6 +11,8 @@ import (
|
||||
|
||||
type App_ struct {
|
||||
f5.App_
|
||||
msgMutex sync.Mutex
|
||||
msgList q5.ListHead
|
||||
}
|
||||
|
||||
var App = new (App_)
|
||||
@ -17,7 +20,8 @@ var App = new (App_)
|
||||
func (this *App_) Init() {
|
||||
f5.App = &this.App_
|
||||
f5.App.SetPkgName("imserver")
|
||||
this.App_.Init()
|
||||
this.App_.Init(this.Update)
|
||||
this.msgList.Init(nil)
|
||||
WSPListener.Init()
|
||||
go this.goReportServerState();
|
||||
}
|
||||
@ -27,6 +31,9 @@ func (this *App_) UnInit() {
|
||||
this.App_.UnInit()
|
||||
}
|
||||
|
||||
func (this *App_) Update() {
|
||||
}
|
||||
|
||||
func (this *App_) goReportServerState() {
|
||||
for {
|
||||
params := q5.NewMxoObject()
|
||||
@ -46,3 +53,13 @@ func (this *App_) goReportServerState() {
|
||||
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()
|
||||
}
|
||||
|
5
server/imserver/cs/cs.generate.go
Normal file
5
server/imserver/cs/cs.generate.go
Normal file
@ -0,0 +1,5 @@
|
||||
package cs
|
||||
|
||||
func ParsePb(msgId int, data []byte) interface{} {
|
||||
return nil
|
||||
}
|
@ -2,12 +2,14 @@ module imserver
|
||||
|
||||
go 1.20
|
||||
|
||||
require q5 v1.0.0 // indirect
|
||||
require q5 v1.0.0
|
||||
|
||||
require f5 v1.0.0
|
||||
|
||||
require mtb v1.0.0
|
||||
|
||||
require cs v1.0.0
|
||||
|
||||
require (
|
||||
github.com/go-sql-driver/mysql v1.5.0 // indirect
|
||||
github.com/golang/protobuf v1.4.2 // indirect
|
||||
@ -19,4 +21,6 @@ replace q5 => ../../third_party/q5
|
||||
|
||||
replace f5 => ../../third_party/f5
|
||||
|
||||
replace mtb => ./mtb
|
||||
replace mtb => ./mtb
|
||||
|
||||
replace cs => ./cs
|
||||
|
2
third_party/f5
vendored
2
third_party/f5
vendored
@ -1 +1 @@
|
||||
Subproject commit efc8db84bc297223ef9e124fffb76ecc1d33899f
|
||||
Subproject commit 6aa5ba1546beb17e9dc6055fe672dce1d4164686
|
Loading…
x
Reference in New Issue
Block a user