优化网络

This commit is contained in:
duanhf2012
2020-02-03 11:16:12 +08:00
parent 892fd26c5a
commit 8b909c4194
4 changed files with 30 additions and 18 deletions

View File

@@ -23,6 +23,7 @@ func (slf *TcpSocketClient) Connect(addr string) error{
}
slf.conn = conn
//
return nil
}

View File

@@ -5,6 +5,7 @@ import (
"encoding/binary"
"github.com/duanhf2012/origin/util"
"github.com/duanhf2012/origin/service"
"github.com/golang/protobuf/proto"
"io"
"net"
"unsafe"
@@ -210,6 +211,20 @@ func (slf *SClient) Send(pack *MsgBasePack){
slf.sendPack.Push(pack)
}
func (slf *SClient) SendMsg(packtype uint16,message proto.Message) error{
var msg MsgBasePack
data,err := proto.Marshal(message)
if err != nil {
return err
}
msg.Make(packtype,data)
slf.sendPack.Push(&msg)
return nil
}
func (slf *SClient) onsend(){
for {
pack := slf.sendPack.Pop()