Browse Source

fixes from review

pull/1780/head
Ethan Buchman 8 years ago
parent
commit
83920a1c37
3 changed files with 19 additions and 24 deletions
  1. +17
    -21
      client/grpc_client.go
  2. +2
    -2
      client/local_client.go
  3. +0
    -1
      server/socket_server.go

+ 17
- 21
client/grpc_client.go View File

@ -240,22 +240,18 @@ func (cli *grpcClient) finishAsyncCall(req *types.Request, res *types.Response)
return reqres return reqres
} }
func (cli *grpcClient) checkErrGetResult() *types.Result {
func (cli *grpcClient) checkErrGetResult() types.Result {
if cli.err != nil { if cli.err != nil {
errorLog := cli.err.Error()
cli.StopForError(cli.err) cli.StopForError(cli.err)
result := types.ErrInternalError
result.SetLog(errorLog)
return &result
return types.ErrInternalError.SetLog(cli.err.Error())
} }
return nil return nil
} }
func (cli *grpcClient) checkGetErr() error { func (cli *grpcClient) checkGetErr() error {
if cli.err != nil { if cli.err != nil {
err := errors.New(cli.err.Error())
cli.StopForError(cli.err) cli.StopForError(cli.err)
return err
return cli.err
} }
return nil return nil
} }
@ -264,8 +260,8 @@ func (cli *grpcClient) checkGetErr() error {
func (cli *grpcClient) EchoSync(msg string) (res types.Result) { func (cli *grpcClient) EchoSync(msg string) (res types.Result) {
reqres := cli.EchoAsync(msg) reqres := cli.EchoAsync(msg)
if res := cli.checkErrGetResult(); res != nil {
return *res
if res := cli.checkErrGetResult(); res.IsErr() {
return res
} }
resp := reqres.Response.GetEcho() resp := reqres.Response.GetEcho()
return types.NewResultOK([]byte(resp.Message), LOG) return types.NewResultOK([]byte(resp.Message), LOG)
@ -277,8 +273,8 @@ func (cli *grpcClient) FlushSync() error {
func (cli *grpcClient) InfoSync() (res types.Result) { func (cli *grpcClient) InfoSync() (res types.Result) {
reqres := cli.InfoAsync() reqres := cli.InfoAsync()
if res := cli.checkErrGetResult(); res != nil {
return *res
if res := cli.checkErrGetResult(); res.IsErr() {
return res
} }
resp := reqres.Response.GetInfo() resp := reqres.Response.GetInfo()
return types.NewResultOK([]byte(resp.Info), LOG) return types.NewResultOK([]byte(resp.Info), LOG)
@ -286,8 +282,8 @@ func (cli *grpcClient) InfoSync() (res types.Result) {
func (cli *grpcClient) SetOptionSync(key string, value string) (res types.Result) { func (cli *grpcClient) SetOptionSync(key string, value string) (res types.Result) {
reqres := cli.SetOptionAsync(key, value) reqres := cli.SetOptionAsync(key, value)
if res := cli.checkErrGetResult(); res != nil {
return *res
if res := cli.checkErrGetResult(); res.IsErr() {
return res
} }
resp := reqres.Response.GetSetOption() resp := reqres.Response.GetSetOption()
return types.Result{Code: OK, Data: nil, Log: resp.Log} return types.Result{Code: OK, Data: nil, Log: resp.Log}
@ -295,8 +291,8 @@ func (cli *grpcClient) SetOptionSync(key string, value string) (res types.Result
func (cli *grpcClient) AppendTxSync(tx []byte) (res types.Result) { func (cli *grpcClient) AppendTxSync(tx []byte) (res types.Result) {
reqres := cli.AppendTxAsync(tx) reqres := cli.AppendTxAsync(tx)
if res := cli.checkErrGetResult(); res != nil {
return *res
if res := cli.checkErrGetResult(); res.IsErr() {
return res
} }
resp := reqres.Response.GetAppendTx() resp := reqres.Response.GetAppendTx()
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log} return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
@ -304,8 +300,8 @@ func (cli *grpcClient) AppendTxSync(tx []byte) (res types.Result) {
func (cli *grpcClient) CheckTxSync(tx []byte) (res types.Result) { func (cli *grpcClient) CheckTxSync(tx []byte) (res types.Result) {
reqres := cli.CheckTxAsync(tx) reqres := cli.CheckTxAsync(tx)
if res := cli.checkErrGetResult(); res != nil {
return *res
if res := cli.checkErrGetResult(); res.IsErr() {
return res
} }
resp := reqres.Response.GetCheckTx() resp := reqres.Response.GetCheckTx()
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log} return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
@ -313,8 +309,8 @@ func (cli *grpcClient) CheckTxSync(tx []byte) (res types.Result) {
func (cli *grpcClient) QuerySync(query []byte) (res types.Result) { func (cli *grpcClient) QuerySync(query []byte) (res types.Result) {
reqres := cli.QueryAsync(query) reqres := cli.QueryAsync(query)
if res := cli.checkErrGetResult(); res != nil {
return *res
if res := cli.checkErrGetResult(); res.IsErr() {
return res
} }
resp := reqres.Response.GetQuery() resp := reqres.Response.GetQuery()
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log} return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}
@ -322,8 +318,8 @@ func (cli *grpcClient) QuerySync(query []byte) (res types.Result) {
func (cli *grpcClient) CommitSync() (res types.Result) { func (cli *grpcClient) CommitSync() (res types.Result) {
reqres := cli.CommitAsync() reqres := cli.CommitAsync()
if res := cli.checkErrGetResult(); res != nil {
return *res
if res := cli.checkErrGetResult(); res.IsErr() {
return res
} }
resp := reqres.Response.GetCommit() resp := reqres.Response.GetCommit()
return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log} return types.Result{Code: resp.Code, Data: resp.Data, Log: resp.Log}


+ 2
- 2
client/local_client.go View File

@ -8,7 +8,7 @@ import (
) )
type localClient struct { type localClient struct {
*BaseService
BaseService
mtx *sync.Mutex mtx *sync.Mutex
types.Application types.Application
Callback Callback
@ -22,7 +22,7 @@ func NewLocalClient(mtx *sync.Mutex, app types.Application) *localClient {
mtx: mtx, mtx: mtx,
Application: app, Application: app,
} }
cli.BaseService = NewBaseService(log, "localClient", cli)
cli.BaseService = *NewBaseService(log, "localClient", cli)
return cli return cli
} }


+ 0
- 1
server/socket_server.go View File

@ -120,7 +120,6 @@ func (s *SocketServer) acceptConnectionsRoutine() {
errClose := <-closeConn errClose := <-closeConn
if err == io.EOF { if err == io.EOF {
log.Warn("Connection was closed by client") log.Warn("Connection was closed by client")
return // is this correct? the conn is closed?
} else if errClose != nil { } else if errClose != nil {
log.Warn("Connection error", "error", errClose) log.Warn("Connection error", "error", errClose)
} else { } else {


Loading…
Cancel
Save