diff --git a/vendor/github.com/minio/dsync/rpc-client.go b/vendor/github.com/minio/dsync/rpc-client.go new file mode 100644 index 000000000..b1f1ea7a3 --- /dev/null +++ b/vendor/github.com/minio/dsync/rpc-client.go @@ -0,0 +1,82 @@ +/* + * Minio Cloud Storage, (C) 2016 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dsync + +import ( + "net/rpc" + "reflect" + "sync" +) + +// Wrapper type for rpc.Client that provides connection management like +// reconnect on first failure. +type RPCClient struct { + sync.Mutex + rpc *rpc.Client + node string + rpcPath string +} + +func newClient(node, rpcPath string) *RPCClient { + return &RPCClient{ + node: node, + rpcPath: rpcPath, + } +} + +func (rpcClient *RPCClient) SetRPC(rpc *rpc.Client) { + rpcClient.Lock() + defer rpcClient.Unlock() + rpcClient.rpc = rpc +} +func (rpcClient *RPCClient) Close() error { + rpcClient.Lock() + defer rpcClient.Unlock() + return rpcClient.rpc.Close() +} + +func (rpcClient *RPCClient) Call(serviceMethod string, args interface{}, reply interface{}) error { + rpcClient.Lock() + defer rpcClient.Unlock() + if rpcClient.rpc == nil { + return rpc.ErrShutdown + } + err := rpcClient.rpc.Call(serviceMethod, args, reply) + return err + +} + +func (rpcClient *RPCClient) Reconnect() error { + rpcClient.Lock() + defer rpcClient.Unlock() + clnt, err := rpc.DialHTTPPath("tcp", rpcClient.node, rpcClient.rpcPath) + if err != nil { + return err + } + rpcClient.rpc = clnt + return nil +} + +func IsRPCError(err error) bool { + // The following are net/rpc specific errors that indicate that + // the connection may have been reset. + if err == rpc.ErrShutdown || + reflect.TypeOf(err) == reflect.TypeOf((*rpc.ServerError)(nil)).Elem() { + return true + } + return false +} diff --git a/vendor/vendor.json b/vendor/vendor.json index ae0ed47ac..0a0cf2e08 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -100,8 +100,8 @@ { "checksumSHA1": "Ev8FdU+RSmpHQsLGzRpg5/ka7zE=", "path": "github.com/minio/dsync", - "revision": "c84de1533e4cd403cdaaf9c4018e12c60a916e23", - "revisionTime": "2016-08-10T23:17:05Z" + "revision": "b26292b87d023da097193c8fe624d4a159e0fd03", + "revisionTime": "2016-08-11T06:53:13Z" }, { "path": "github.com/minio/go-homedir",