Working on client

This commit is contained in:
Matthias Fulz 2020-02-25 01:37:05 +01:00
parent ec9289224b
commit 212fa64be1
1 changed files with 42 additions and 2 deletions

View File

@ -2,12 +2,13 @@ package srpc
import (
//"bytes"
//"errors"
"errors"
//"fmt"
"io"
"net"
"sync"
//"time"
"sync/atomic"
"time"
)
//func (client *Client) Call(funcName string, args ...interface{}) (ret []byte, err error) {
@ -137,3 +138,42 @@ func (c *RPCClient) Stop() {
c.stopWg.Wait()
c.stopChan = nil
}
func clientHandler(c *RPCClient) {
defer c.stopWg.Done()
var conn io.ReadWriteCloser
var err error
var stopping atomic.Value
for {
dialChan := make(chan struct{})
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)
}
}
close(dialChan)
}()
select {
case <-c.stopChan:
stopping.Store(true)
<-dialChan
return
case <-dialChan:
}
if err != nil {
select {
case <-c.stopChan:
return
case <-time.After(time.Second):
}
continue
}
c.stopWg.Add(1)
}
}