Clien Progress
This commit is contained in:
parent
212fa64be1
commit
ae7f26766f
28
client.go
28
client.go
|
@ -85,6 +85,19 @@ import (
|
||||||
//return ret
|
//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 ResponseDataHandlerFunc func() (response interface{})
|
||||||
|
|
||||||
type DialHandlerFunc func(addr string) (conn io.ReadWriteCloser, err error)
|
type DialHandlerFunc func(addr string) (conn io.ReadWriteCloser, err error)
|
||||||
|
@ -151,7 +164,7 @@ func clientHandler(c *RPCClient) {
|
||||||
go func() {
|
go func() {
|
||||||
if conn, err = c.DialHandler(c.Addr); err != nil {
|
if conn, err = c.DialHandler(c.Addr); err != nil {
|
||||||
if stopping.Load() == 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)
|
close(dialChan)
|
||||||
|
@ -175,5 +188,18 @@ func clientHandler(c *RPCClient) {
|
||||||
}
|
}
|
||||||
|
|
||||||
c.stopWg.Add(1)
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue