Clien Progress

This commit is contained in:
Matthias Fulz 2020-03-24 08:08:27 +01:00
parent 212fa64be1
commit ae7f26766f
1 changed files with 27 additions and 1 deletions

View File

@ -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
}
}
}