1.优化网络库

2.rpc协议在宕机时不会导致整个rpc无法响应
This commit is contained in:
boyce
2020-02-05 17:51:51 +08:00
parent 29b04d82c3
commit 7fd97033ec
5 changed files with 28 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ import (
type TcpSocketClient struct {
conn net.Conn
addr string
}
func (slf *TcpSocketClient) Connect(addr string) error{
@@ -22,13 +23,17 @@ func (slf *TcpSocketClient) Connect(addr string) error{
return err
}
slf.conn = conn
slf.addr = addr
//
return nil
}
func (slf *TcpSocketClient) SendMsg(packtype uint16,message proto.Message) error{
if slf.conn == nil {
return fmt.Errorf("cannt connect %s",slf.addr)
}
var msg MsgBasePack
data,err := proto.Marshal(message)
if err != nil {

View File

@@ -247,7 +247,12 @@ func (slf *SClient) onsend(){
}
pPackData := pack.(*MsgBasePack)
slf.conn.Write(pPackData.Bytes())
_,e := slf.conn.Write(pPackData.Bytes())
if e!=nil {
service.GetLogger().Printf(service.LEVER_DEBUG, "clent id %d write error...",slf.id)
return
}
//fmt.Print("xxxxxxxxxxxxxxx:",n,e)
}
}