mirror of
https://github.com/duanhf2012/origin.git
synced 2026-03-14 21:03:33 +08:00
修改协议字段小写转大写
This commit is contained in:
@@ -46,19 +46,14 @@ type TcpSocketServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MsgBasePack struct {
|
type MsgBasePack struct {
|
||||||
packsize uint16
|
PackSize uint16
|
||||||
packtype uint16
|
PackType uint16
|
||||||
body []byte
|
Body []byte
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *MsgBasePack) PackType() uint16 {
|
|
||||||
return slf.packtype
|
|
||||||
}
|
|
||||||
|
|
||||||
func (slf *MsgBasePack) Body() []byte{
|
|
||||||
return slf.body
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func (slf *TcpSocketServer) Register(listenAddr string,iReciver ITcpSocketServerReciver){
|
func (slf *TcpSocketServer) Register(listenAddr string,iReciver ITcpSocketServerReciver){
|
||||||
@@ -180,8 +175,8 @@ func (slf *SClient) listendata(){
|
|||||||
fillsize,bfillRet,fillhead := pack.FillData(buff,buffDataSize)
|
fillsize,bfillRet,fillhead := pack.FillData(buff,buffDataSize)
|
||||||
//提交校验头
|
//提交校验头
|
||||||
if fillhead == true {
|
if fillhead == true {
|
||||||
if pack.packsize>slf.tcpserver.MaxRecvPackSize || slf.tcpserver.iReciver.VerifyPackType(pack.packtype) == false {
|
if pack.PackSize>slf.tcpserver.MaxRecvPackSize || slf.tcpserver.iReciver.VerifyPackType(pack.PackType) == false {
|
||||||
service.GetLogger().Printf(service.LEVER_WARN, "VerifyPackType error clent id %d is disconnect %d,%d",slf.id,pack.packtype, pack.packsize)
|
service.GetLogger().Printf(service.LEVER_WARN, "VerifyPackType error clent id %d is disconnect %d,%d",slf.id,pack.PackType, pack.PackSize)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,9 +195,9 @@ func (slf *SClient) listendata(){
|
|||||||
func (slf *MsgBasePack) Bytes() []byte{
|
func (slf *MsgBasePack) Bytes() []byte{
|
||||||
var bRet []byte
|
var bRet []byte
|
||||||
bRet = make([]byte,4)
|
bRet = make([]byte,4)
|
||||||
binary.BigEndian.PutUint16(bRet,slf.packsize)
|
binary.BigEndian.PutUint16(bRet,slf.PackSize)
|
||||||
binary.BigEndian.PutUint16(bRet[2:],slf.packtype)
|
binary.BigEndian.PutUint16(bRet[2:],slf.PackType)
|
||||||
bRet = append(bRet,slf.body...)
|
bRet = append(bRet,slf.Body...)
|
||||||
|
|
||||||
return bRet
|
return bRet
|
||||||
}
|
}
|
||||||
@@ -212,21 +207,21 @@ func (slf *MsgBasePack) FillData(bdata []byte,datasize uint16) (uint16,bool,bool
|
|||||||
var fillsize uint16
|
var fillsize uint16
|
||||||
fillhead := false
|
fillhead := false
|
||||||
//解包头
|
//解包头
|
||||||
if slf.packsize ==0 {
|
if slf.PackSize ==0 {
|
||||||
if datasize < 4 {
|
if datasize < 4 {
|
||||||
return 0,false,fillhead
|
return 0,false,fillhead
|
||||||
}
|
}
|
||||||
|
|
||||||
slf.packsize= binary.BigEndian.Uint16(bdata[:2])
|
slf.PackSize= binary.BigEndian.Uint16(bdata[:2])
|
||||||
slf.packtype= binary.BigEndian.Uint16(bdata[2:4])
|
slf.PackType= binary.BigEndian.Uint16(bdata[2:4])
|
||||||
fillsize += 4
|
fillsize += 4
|
||||||
fillhead = true
|
fillhead = true
|
||||||
}
|
}
|
||||||
|
|
||||||
//解包体
|
//解包体
|
||||||
if slf.packsize>0 && datasize+4>=slf.packsize {
|
if slf.PackSize>0 && datasize+4>=slf.PackSize {
|
||||||
slf.body = append(slf.body, bdata[fillsize:slf.packsize]...)
|
slf.Body = append(slf.Body, bdata[fillsize:slf.PackSize]...)
|
||||||
fillsize += (slf.packsize - fillsize)
|
fillsize += (slf.PackSize - fillsize)
|
||||||
return fillsize,true,fillhead
|
return fillsize,true,fillhead
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,9 +233,9 @@ func (slf *MsgBasePack) Clear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (slf *MsgBasePack) Make(packtype uint16,data []byte) {
|
func (slf *MsgBasePack) Make(packtype uint16,data []byte) {
|
||||||
slf.packtype = packtype
|
slf.PackType = packtype
|
||||||
slf.body = data
|
slf.Body = data
|
||||||
slf.packsize = uint16(unsafe.Sizeof(slf.packtype)*2)+uint16(len(data))
|
slf.PackSize = uint16(unsafe.Sizeof(slf.PackType)*2)+uint16(len(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *SClient) Send(pack *MsgBasePack) error {
|
func (slf *SClient) Send(pack *MsgBasePack) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user