mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化processor
This commit is contained in:
@@ -2,19 +2,22 @@ package GateService
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/duanhf2012/origin/event"
|
"github.com/duanhf2012/origin/event"
|
||||||
|
"github.com/duanhf2012/origin/network"
|
||||||
|
"github.com/duanhf2012/origin/network/processor"
|
||||||
"github.com/duanhf2012/origin/node"
|
"github.com/duanhf2012/origin/node"
|
||||||
"github.com/duanhf2012/origin/service"
|
"github.com/duanhf2012/origin/service"
|
||||||
"github.com/duanhf2012/origin/sysservice"
|
"github.com/duanhf2012/origin/sysservice"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GateService struct {
|
type GateService struct {
|
||||||
processor *PBProcessor
|
|
||||||
service.Service
|
service.Service
|
||||||
|
processor network.Processor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *GateService) OnInit() error{
|
func (slf *GateService) OnInit() error{
|
||||||
tcpervice := node.GetService("TcpService").(*sysservice.TcpService)
|
tcpervice := node.GetService("TcpService").(*sysservice.TcpService)
|
||||||
tcpervice.SetProcessor(&PBProcessor{})
|
slf.processor = &processor.PBProcessor{}
|
||||||
|
tcpervice.SetProcessor(slf.processor)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +25,7 @@ func (slf *GateService) OnInit() error{
|
|||||||
func (slf *GateService) OnEventHandler(ev *event.Event) error{
|
func (slf *GateService) OnEventHandler(ev *event.Event) error{
|
||||||
if ev.Type == event.Sys_Event_Tcp_RecvPack {
|
if ev.Type == event.Sys_Event_Tcp_RecvPack {
|
||||||
pPack := ev.Data.(*sysservice.TcpPack)
|
pPack := ev.Data.(*sysservice.TcpPack)
|
||||||
slf.processor.Route(pPack.Data,pPack.ClientId)
|
slf.processor.Route(ev.Data,pPack.ClientId)
|
||||||
}else if ev.Type == event.Sys_Event_Tcp_Connected {
|
}else if ev.Type == event.Sys_Event_Tcp_Connected {
|
||||||
pPack := ev.Data.(*sysservice.TcpPack)
|
pPack := ev.Data.(*sysservice.TcpPack)
|
||||||
slf.OnConnected(pPack.ClientId)
|
slf.OnConnected(pPack.ClientId)
|
||||||
|
|||||||
@@ -121,28 +121,28 @@ type Param struct {
|
|||||||
|
|
||||||
func (slf *TestServiceCall) Run(){
|
func (slf *TestServiceCall) Run(){
|
||||||
//var ret int
|
//var ret int
|
||||||
var input int = 10000
|
//var input int = 10000
|
||||||
bT := time.Now() // 开始时间
|
//bT := time.Now() // 开始时间
|
||||||
|
|
||||||
//err := slf.Call("TestServiceCall.RPC_Test",&ret,&input)
|
//err := slf.Call("TestServiceCall.RPC_Test",&ret,&input)
|
||||||
var param Param
|
var param Param
|
||||||
param.A = 2342342341
|
param.A = 2342342341
|
||||||
param.B = "xxxxxxxxxxxxxxxxxxxxxxx"
|
param.B = "xxxxxxxxxxxxxxxxxxxxxxx"
|
||||||
param.Pa = []string{"ccccc","asfsdfsdaf","bbadfsdf","ewrwefasdf","safsadfka;fksd"}
|
param.Pa = []string{"ccccc","asfsdfsdaf","bbadfsdf","ewrwefasdf","safsadfka;fksd"}
|
||||||
|
/*
|
||||||
for i:=input;i>=0;i--{
|
for i:=input;i>=0;i--{
|
||||||
param.Index = i
|
param.Index = i
|
||||||
slf.AsyncCall("TestService1.RPC_Test",¶m, func(reply *Param, err error) {
|
slf.AsyncCall("TestService1.RPC_Test",¶m, func(reply *Param, err error) {
|
||||||
if reply.Index == 0 || err != nil{
|
if reply.Index == 0 || err != nil{
|
||||||
eT := time.Since(bT) // 从开始到当前所消耗的时间
|
eT := time.Since(bT) // 从开始到当前所消耗的时间
|
||||||
fmt.Print(err,eT.Milliseconds())
|
fmt.Print(err,eT.Milliseconds())
|
||||||
fmt.Print("..................",eT,"\n")
|
fmt.Print("xxxx..................",eT,err,"\n")
|
||||||
}
|
}
|
||||||
//fmt.Print(*reply,"\n",err)
|
//fmt.Print(*reply,"\n",err)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
fmt.Print("finsh....")
|
fmt.Print("finsh....")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package GateService
|
package processor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
@@ -22,14 +22,14 @@ func (slf *PBProcessor) SetLittleEndian(littleEndian bool){
|
|||||||
slf.LittleEndian = littleEndian
|
slf.LittleEndian = littleEndian
|
||||||
}
|
}
|
||||||
|
|
||||||
type PackInfo struct {
|
type PBPackInfo struct {
|
||||||
typ uint16
|
typ uint16
|
||||||
msg proto.Message
|
msg proto.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
// must goroutine safe
|
// must goroutine safe
|
||||||
func (slf *PBProcessor ) Route(msg interface{},userdata interface{}) error{
|
func (slf *PBProcessor ) Route(msg interface{},userdata interface{}) error{
|
||||||
pPackInfo := msg.(*PackInfo)
|
pPackInfo := msg.(*PBPackInfo)
|
||||||
v,ok := slf.mapMsg[pPackInfo.typ]
|
v,ok := slf.mapMsg[pPackInfo.typ]
|
||||||
if ok == false {
|
if ok == false {
|
||||||
return fmt.Errorf("cannot find msgtype %d is register!",pPackInfo.typ)
|
return fmt.Errorf("cannot find msgtype %d is register!",pPackInfo.typ)
|
||||||
@@ -60,7 +60,7 @@ func (slf *PBProcessor ) Unmarshal(data []byte) (interface{}, error) {
|
|||||||
return nil,err
|
return nil,err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &PackInfo{typ:msgType,msg:protoMsg},nil
|
return &PBPackInfo{typ:msgType,msg:protoMsg},nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// must goroutine safe
|
// must goroutine safe
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package processor
|
|
||||||
|
|
||||||
type IProcessor interface {
|
|
||||||
//SetByteOrder(littleEndian bool)
|
|
||||||
//SetMsgLen(lenMsgLen int, minMsgLen uint32, maxMsgLen uint32)
|
|
||||||
|
|
||||||
Unmarshal(data []byte) (interface{}, error)
|
|
||||||
// must goroutine safe
|
|
||||||
Marshal(msg interface{}) ([][]byte, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -13,11 +13,11 @@ type TcpService struct {
|
|||||||
tcpServer network.TCPServer
|
tcpServer network.TCPServer
|
||||||
service.Service
|
service.Service
|
||||||
|
|
||||||
tcpService *TcpService
|
tcpService *TcpService
|
||||||
mapClientLocker sync.RWMutex
|
mapClientLocker sync.RWMutex
|
||||||
mapClient map[uint64] *Client
|
mapClient map[uint64] *Client
|
||||||
initClientId uint64
|
initClientId uint64
|
||||||
process network.Processor
|
process network.Processor
|
||||||
}
|
}
|
||||||
|
|
||||||
const Default_MaxConnNum = 3000
|
const Default_MaxConnNum = 3000
|
||||||
|
|||||||
Reference in New Issue
Block a user