Skip to content

Commit

Permalink
chanrpc在外部返回函数时,忽略返回类型检测,方便后期做统一的转发机制;
Browse files Browse the repository at this point in the history
  • Loading branch information
heyilin416 committed Mar 16, 2017
1 parent 92c2e47 commit 85646d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions chanrpc/chanrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ func (c *Client) f(id interface{}, n int) (f interface{}, err error) {
_, ok = f.(func([]interface{}) (interface{}, error))
case 2:
_, ok = f.(func([]interface{}) ([]interface{}, error))
case -1:
ok = true
default:
panic("bug")
}
Expand Down Expand Up @@ -394,6 +396,8 @@ func (c *Client) AsynCall(id interface{}, _args ...interface{}) {
n = 1
case func([]interface{}, error):
n = 2
case ExtRetFunc:
n = -1
default:
panic("definition of callback function is invalid")
}
Expand Down Expand Up @@ -423,6 +427,8 @@ func execCb(ri *RetInfo) {
ri.Cb.(func(interface{}, error))(ri.Ret, ri.Err)
case func([]interface{}, error):
ri.Cb.(func([]interface{}, error))(Assert(ri.Ret), ri.Err)
case ExtRetFunc:
ri.Cb.(ExtRetFunc)(ri.Ret, ri.Err)
default:
panic("bug")
}
Expand Down
4 changes: 2 additions & 2 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func run() {
case <-timer.C:
agentsMutex.RLock()
for _, agent := range agents {
if atomic.AddInt32(&agent.heartHeatWaitTimes, 1) >= 2 {
if atomic.AddInt32(&agent.heartBeatWaitTimes, 1) >= 2 {
agent.conn.Destroy()
} else {
agent.WriteMsg(msg)
Expand Down Expand Up @@ -189,7 +189,7 @@ type Agent struct {
ServerName string
conn *network.TCPConn
userData interface{}
heartHeatWaitTimes int32
heartBeatWaitTimes int32

sync.Mutex
requestID uint32
Expand Down
2 changes: 1 addition & 1 deletion cluster/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func handleNotifyServerName(args []interface{}) {

func handleHeartBeat(args []interface{}) {
agent := args[1].(*Agent)
atomic.StoreInt32(&agent.heartHeatWaitTimes, 0)
atomic.StoreInt32(&agent.heartBeatWaitTimes, 0)
}

func handleRequestMsg(args []interface{}) {
Expand Down

0 comments on commit 85646d7

Please sign in to comment.