From 3964cd05b0124d866ca3d51816de6bb1b8f6ac48 Mon Sep 17 00:00:00 2001 From: starainrt Date: Fri, 7 Jan 2022 15:07:24 +0800 Subject: [PATCH] add SendWaitObj Fn --- client.go | 10 +++++++++- clienttype.go | 1 + server.go | 8 ++++++++ servertype.go | 8 ++++---- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 16efbdc..66b172b 100644 --- a/client.go +++ b/client.go @@ -273,7 +273,7 @@ func (c *ClientCommon) loadMessage() { return } message := Message{ - ServerConn: c, + ServerConn: c, TransferMsg: msg.(TransferMsg), NetType: NET_CLIENT, } @@ -469,6 +469,14 @@ func (c *ClientCommon) SendWait(key string, value MsgVal, timeout time.Duration) }, timeout) } +func (c *ClientCommon) SendWaitObj(key string, value interface{}, timeout time.Duration) (Message, error) { + data, err := c.sequenceEn(value) + if err != nil { + return Message{}, err + } + return c.SendWait(key, data, timeout) +} + func (c *ClientCommon) Reply(m Message, value MsgVal) error { return m.Reply(value) } diff --git a/clienttype.go b/clienttype.go index 30b0551..a4042a4 100644 --- a/clienttype.go +++ b/clienttype.go @@ -12,6 +12,7 @@ type Client interface { sendWait(msg TransferMsg, timeout time.Duration) (Message, error) Send(key string, value MsgVal) error SendWait(key string, value MsgVal, timeout time.Duration) (Message, error) + SendWaitObj(key string, value interface{}, timeout time.Duration) (Message, error) SendCtx(ctx context.Context, key string, value MsgVal) (Message, error) Reply(m Message, value MsgVal) error ExchangeKey(newKey []byte) error diff --git a/server.go b/server.go index 87b68be..362e3a7 100644 --- a/server.go +++ b/server.go @@ -449,6 +449,14 @@ func (s *ServerCommon) SendWait(c *ClientConn, key string, value MsgVal, timeout }, timeout) } +func (s *ServerCommon) SendWaitObj(c *ClientConn, key string, value interface{}, timeout time.Duration) (Message, error) { + data, err := s.sequenceEn(value) + if err != nil { + return Message{}, err + } + return s.SendWait(c, key, data, timeout) +} + func (s *ServerCommon) SendObjCtx(ctx context.Context, c *ClientConn, key string, val interface{}) (Message, error) { data, err := s.sequenceEn(val) if err != nil { diff --git a/servertype.go b/servertype.go index 1185447..5a947e7 100644 --- a/servertype.go +++ b/servertype.go @@ -17,6 +17,7 @@ type Server interface { SendObj(c *ClientConn, key string, val interface{}) error Send(c *ClientConn, key string, value MsgVal) error SendWait(c *ClientConn, key string, value MsgVal, timeout time.Duration) (Message, error) + SendWaitObj(c *ClientConn, key string, value interface{}, timeout time.Duration) (Message, error) SendCtx(ctx context.Context, c *ClientConn, key string, value MsgVal) (Message, error) Reply(m Message, value MsgVal) error pushMessage([]byte, string) @@ -35,12 +36,11 @@ type Server interface { GetClientLists() []*ClientConn GetClientAddrs() []net.Addr - GetSequenceEn() func(interface{}) ([]byte,error) - SetSequenceEn(func(interface{}) ([]byte,error)) + GetSequenceEn() func(interface{}) ([]byte, error) + SetSequenceEn(func(interface{}) ([]byte, error)) GetSequenceDe() func([]byte) (interface{}, error) SetSequenceDe(func([]byte) (interface{}, error)) - HeartbeatTimeoutSec()int64 + HeartbeatTimeoutSec() int64 SetHeartbeatTimeoutSec(int64) - }