This commit is contained in:
crusader 2017-11-01 17:43:20 +09:00
parent 5cad5b126d
commit a8acaab5b8
4 changed files with 7 additions and 7 deletions

View File

@ -10,7 +10,7 @@ var callStatePool sync.Pool
var zeroTime time.Time var zeroTime time.Time
type CallState struct { type CallState struct {
ID interface{} ID uint64
Method string Method string
Args interface{} Args interface{}
Result interface{} Result interface{}

View File

@ -34,7 +34,7 @@ type client struct {
conn net.Conn conn net.Conn
pendingRequestsCount uint32 pendingRequestsCount uint32
pendingRequests map[interface{}]*CallState pendingRequests map[uint64]*CallState
pendingRequestsLock sync.Mutex pendingRequestsLock sync.Mutex
requestQueueChan chan *CallState requestQueueChan chan *CallState
@ -56,7 +56,7 @@ func (c *client) Connect() error {
} }
c.stopChan = make(chan struct{}) c.stopChan = make(chan struct{})
c.requestQueueChan = make(chan *CallState, c.ch.GetPendingRequests()) c.requestQueueChan = make(chan *CallState, c.ch.GetPendingRequests())
c.pendingRequests = make(map[interface{}]*CallState) c.pendingRequests = make(map[uint64]*CallState)
go c.handleRPC() go c.handleRPC()
@ -297,9 +297,9 @@ func (c *client) rpcReader(readerDone chan<- error) {
func (c *client) responseHandle(codecResponse protocol.ClientCodecResponse) error { func (c *client) responseHandle(codecResponse protocol.ClientCodecResponse) error {
c.pendingRequestsLock.Lock() c.pendingRequestsLock.Lock()
cs, ok := c.pendingRequests[codecResponse.ID()] cs, ok := c.pendingRequests[codecResponse.ID().(uint64)]
if ok { if ok {
delete(c.pendingRequests, codecResponse.ID()) delete(c.pendingRequests, codecResponse.ID().(uint64))
} }
c.pendingRequestsLock.Unlock() c.pendingRequestsLock.Unlock()

View File

@ -16,6 +16,6 @@ type ClientHandler interface {
GetRequestTimeout() time.Duration GetRequestTimeout() time.Duration
GetPendingRequests() int GetPendingRequests() int
GetRequestID() interface{} GetRequestID() uint64
Validate() Validate()
} }

View File

@ -50,7 +50,7 @@ func (ch *ClientHandlers) GetPendingRequests() int {
return ch.PendingRequests return ch.PendingRequests
} }
func (ch *ClientHandlers) GetRequestID() interface{} { func (ch *ClientHandlers) GetRequestID() uint64 {
var id uint64 var id uint64
ch.requestIDMtx.Lock() ch.requestIDMtx.Lock()
ch.requestID++ ch.requestID++