From ae7f26766f44afef531b52f5216847d57ad4e99a Mon Sep 17 00:00:00 2001 From: Matthias Fulz Date: Tue, 24 Mar 2020 08:08:27 +0100 Subject: [PATCH] Clien Progress --- client.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 9ca25b7..b3d80c5 100644 --- a/client.go +++ b/client.go @@ -85,6 +85,19 @@ import ( //return ret //} +type clientMessage struct { + ID uint64 + Data interface{} + ClientAddr string +} + +type call struct { + Response serverMessage + t time.Time + done chan struct{} + request clientMessage +} + type ResponseDataHandlerFunc func() (response interface{}) type DialHandlerFunc func(addr string) (conn io.ReadWriteCloser, err error) @@ -151,7 +164,7 @@ func clientHandler(c *RPCClient) { go func() { if conn, err = c.DialHandler(c.Addr); err != nil { if stopping.Load() == nil { - c.LogError("srpc - '%s' cannoc estable rpc connection: '%s'\n", c.Addr, err) + c.LogError("srpc - '%s' cannot estable rpc connection: '%s'\n", c.Addr, err) } } close(dialChan) @@ -175,5 +188,18 @@ func clientHandler(c *RPCClient) { } c.stopWg.Add(1) + go clientHandleConnection(c, conn) + } +} + +func clientHandleConnection(c *RPCClient, conn io.ReadWriteCloser) { + if c.ConnectHander != nil { + if newConn, err := c.ConnectHander(c.Addr, conn); err != nil { + c.LogError("srpc - Client: [%s] - Connect error: '%s'\n", c.Addr, err) + conn.Close() + return + } else { + conn = newConn + } } }