From 91b5340fd44fa3d7a5fd0be7a0224db56c4f8b0a Mon Sep 17 00:00:00 2001 From: boyce Date: Wed, 12 Feb 2020 16:27:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8F=91=E9=80=81=E5=8E=9F?= =?UTF-8?q?=E5=A7=8B=E5=8C=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- network/tcpsocketserver.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/network/tcpsocketserver.go b/network/tcpsocketserver.go index 1caebd4..031b703 100644 --- a/network/tcpsocketserver.go +++ b/network/tcpsocketserver.go @@ -134,6 +134,16 @@ func (slf *TcpSocketServer) SendMsg(clientid uint64,packtype uint16,message pro return pClient.(*SClient).SendMsg(packtype,message) } +func (slf *TcpSocketServer) Send(clientid uint64,pack *MsgBasePack) error{ + pClient := slf.mapClient.Get(clientid) + if pClient == nil { + return fmt.Errorf("clientid %d is not in connect pool.",clientid) + } + + return pClient.(*SClient).Send(pack) +} + + func (slf *SClient) listendata(){ defer func() { slf.Close() @@ -233,8 +243,14 @@ func (slf *MsgBasePack) Make(packtype uint16,data []byte) { slf.packsize = uint16(unsafe.Sizeof(slf.packtype)*2)+uint16(len(data)) } -func (slf *SClient) Send(pack *MsgBasePack){ +func (slf *SClient) Send(pack *MsgBasePack) error { + if slf.bClose == true { + return fmt.Errorf("client id %d is close!",slf.id) + } + slf.sendPack.Push(pack) + + return nil } @@ -255,6 +271,8 @@ func (slf *SClient) SendMsg(packtype uint16,message proto.Message) error{ return nil } + + func (slf *SClient) onsend(){ defer func() { slf.Close()