Remove lastcall.

This commit is contained in:
Sadlil Rhythom 2017-02-06 17:38:24 +06:00 committed by Christoffer Fjellström
parent 5c665de2d6
commit f2f0349d2d

View File

@ -18,7 +18,7 @@ var (
type Client struct { type Client struct {
sync.Mutex sync.Mutex
net, addr, lastcall string net, addr string
respHandler *responseHandlerMap respHandler *responseHandlerMap
innerHandler *responseHandlerMap innerHandler *responseHandlerMap
in chan *Response in chan *Response
@ -171,12 +171,7 @@ func (client *Client) processLoop() {
for resp := range client.in { for resp := range client.in {
switch resp.DataType { switch resp.DataType {
case dtError: case dtError:
if client.lastcall != "" {
resp = client.handleInner(client.lastcall, resp)
client.lastcall = ""
} else {
client.err(getError(resp.Data)) client.err(getError(resp.Data))
}
case dtStatusRes: case dtStatusRes:
resp = client.handleInner("s"+resp.Handle, resp) resp = client.handleInner("s"+resp.Handle, resp)
case dtJobCreated: case dtJobCreated:
@ -228,7 +223,6 @@ func (client *Client) do(funcname string, data []byte,
var result = make(chan handleOrError, 1) var result = make(chan handleOrError, 1)
client.Lock() client.Lock()
defer client.Unlock() defer client.Unlock()
client.lastcall = "c"
client.innerHandler.put("c", func(resp *Response) { client.innerHandler.put("c", func(resp *Response) {
if resp.DataType == dtError { if resp.DataType == dtError {
err = getError(resp.Data) err = getError(resp.Data)
@ -243,7 +237,6 @@ func (client *Client) do(funcname string, data []byte,
req.DataType = flag req.DataType = flag
if err = client.write(req); err != nil { if err = client.write(req); err != nil {
client.innerHandler.remove("c") client.innerHandler.remove("c")
client.lastcall = ""
return return
} }
var timer = time.After(client.ResponseTimeout * time.Millisecond) var timer = time.After(client.ResponseTimeout * time.Millisecond)
@ -252,7 +245,6 @@ func (client *Client) do(funcname string, data []byte,
return ret.handle, ret.err return ret.handle, ret.err
case <-timer: case <-timer:
client.innerHandler.remove("c") client.innerHandler.remove("c")
client.lastcall = ""
return "", ErrLostConn return "", ErrLostConn
} }
return return
@ -308,7 +300,6 @@ func (client *Client) Status(handle string) (status *Status, err error) {
} }
var mutex sync.Mutex var mutex sync.Mutex
mutex.Lock() mutex.Lock()
client.lastcall = "s" + handle
client.innerHandler.put("s"+handle, func(resp *Response) { client.innerHandler.put("s"+handle, func(resp *Response) {
defer mutex.Unlock() defer mutex.Unlock()
var err error var err error
@ -339,7 +330,6 @@ func (client *Client) Echo(data []byte) (echo []byte, err error) {
req := getRequest() req := getRequest()
req.DataType = dtEchoReq req.DataType = dtEchoReq
req.Data = data req.Data = data
client.lastcall = "e"
client.write(req) client.write(req)
mutex.Lock() mutex.Lock()
return return