Merge pull request #173 from rosslagerwall/reconnect-retries

socket: Limit reconnect retries to 10
libnfs-4.0.0-vitalif
Ronnie Sahlberg 2017-03-02 17:07:13 -08:00 committed by GitHub
commit 70df81c16a
2 changed files with 8 additions and 1 deletions

View File

@ -133,6 +133,7 @@ struct rpc_context {
/* track the address we connect to so we can auto-reconnect on session failure */
struct sockaddr_storage s;
int auto_reconnect;
int auto_reconnect_retries;
/* fragment reassembly */
struct rpc_fragment *fragments;

View File

@ -85,6 +85,8 @@
#include "win32_errnowrapper.h"
#endif
#define NR_RECONNECT_RETRIES 10
static int rpc_reconnect_requeue(struct rpc_context *rpc);
static int create_socket(int domain, int type, int protocol)
@ -703,6 +705,9 @@ static int rpc_reconnect_requeue(struct rpc_context *rpc)
assert(rpc->magic == RPC_CONTEXT_MAGIC);
if (rpc->is_connected)
rpc->auto_reconnect_retries = NR_RECONNECT_RETRIES;
if (rpc->fd != -1) {
rpc->old_fd = rpc->fd;
}
@ -728,7 +733,8 @@ static int rpc_reconnect_requeue(struct rpc_context *rpc)
}
rpc->waitpdu_len = 0;
if (rpc->auto_reconnect != 0) {
if (rpc->auto_reconnect != 0 && rpc->auto_reconnect_retries > 0) {
rpc->auto_reconnect_retries--;
rpc->connect_cb = reconnect_cb;
RPC_LOG(rpc, 1, "reconnect initiated");
if (rpc_connect_sockaddr_async(rpc) != 0) {