|
@@ -8,6 +8,8 @@ import (
|
|
|
"sync"
|
|
|
"sync/atomic"
|
|
|
"time"
|
|
|
+
|
|
|
+ "git.nspix.com/golang/micro/log"
|
|
|
)
|
|
|
|
|
|
var (
|
|
@@ -17,7 +19,7 @@ var (
|
|
|
type (
|
|
|
Client struct {
|
|
|
conn net.Conn
|
|
|
- seq uint16
|
|
|
+ seq int32
|
|
|
once sync.Once
|
|
|
isConnected int32
|
|
|
transactionLocker sync.RWMutex
|
|
@@ -84,6 +86,7 @@ func (c *Client) eventLoop() {
|
|
|
}
|
|
|
|
|
|
func (c *Client) rdyLoop() {
|
|
|
+ log.Infof("RPC: connection %s connected", c.conn.LocalAddr())
|
|
|
defer atomic.StoreInt32(&c.isConnected, 0)
|
|
|
for {
|
|
|
if frame, err := readFrame(c.conn); err == nil {
|
|
@@ -102,6 +105,7 @@ func (c *Client) rdyLoop() {
|
|
|
c.pintAt = time.Now()
|
|
|
}
|
|
|
} else {
|
|
|
+ log.Infof("RPC: connection %s closed", c.conn.LocalAddr())
|
|
|
break
|
|
|
}
|
|
|
}
|
|
@@ -161,8 +165,7 @@ func (c *Client) Do(ctx context.Context, req *Request) (res *Response, err error
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
- c.seq++
|
|
|
- seq := c.seq
|
|
|
+ seq := uint16(atomic.AddInt32(&c.seq, 1))
|
|
|
if err = writeFrame(c.conn, &Frame{
|
|
|
Func: FuncRequest,
|
|
|
Sequence: seq,
|
|
@@ -176,6 +179,7 @@ func (c *Client) Do(ctx context.Context, req *Request) (res *Response, err error
|
|
|
if ok {
|
|
|
res = t.response
|
|
|
} else {
|
|
|
+ //canceled
|
|
|
err = io.ErrClosedPipe
|
|
|
}
|
|
|
case <-ctx.Done():
|