From b6beb6f2a9fc6a20243c12c2528f4490e8913cbc Mon Sep 17 00:00:00 2001 From: Olga Kornievskaia Date: Mon, 16 May 2011 15:46:45 -0400 Subject: [PATCH] [libtircp] adding timeout on async recv once libtirpc blocking recv was changed to a polling receive, we no longer had a timeout mechanims on waiting for a reply. solution: save a timestamp before the recv call, on each async recv return check if the time lapsed does not exceed the timeout value. when timeout is reach, return TIMEDOUT rpc error. --- daemon/nfs41_rpc.c | 4 ++-- libtirpc/src/clnt_vc.c | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/daemon/nfs41_rpc.c b/daemon/nfs41_rpc.c index 93ca884..a6fe228 100644 --- a/daemon/nfs41_rpc.c +++ b/daemon/nfs41_rpc.c @@ -34,7 +34,7 @@ static enum clnt_stat send_null(CLIENT *client) { - struct timeval timeout = {0, 100}; + struct timeval timeout = {10, 0}; return clnt_call(client, 0, (xdrproc_t)xdr_void, NULL, @@ -306,7 +306,7 @@ int nfs41_send_compound( IN char *inbuf, OUT char *outbuf) { - struct timeval timeout = {0, 100}; + struct timeval timeout = {90, 0}; enum clnt_stat rpc_status; int status, count = 0, one = 1, zero = 0; uint32_t version; diff --git a/libtirpc/src/clnt_vc.c b/libtirpc/src/clnt_vc.c index 29d68d0..1e882bf 100644 --- a/libtirpc/src/clnt_vc.c +++ b/libtirpc/src/clnt_vc.c @@ -64,6 +64,7 @@ #include //#include //#include +#include #include #include "rpc_com.h" @@ -499,6 +500,7 @@ clnt_vc_call(cl, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout) bool_t shipnow; int refreshes = 2; u_int seq = -1; + time_t start_send, time_now; #ifndef _WIN32 sigset_t mask, newmask; #else @@ -560,6 +562,7 @@ call_again: * Keep receiving until we get a valid transaction id */ + time(&start_send); while (TRUE) { #ifdef NO_CB_4_KRB5P if (cl->cb_thread != INVALID_HANDLE_VALUE) { @@ -583,6 +586,11 @@ call_again: if (cl->cb_thread != INVALID_HANDLE_VALUE) #endif release_fd_lock(ct->ct_fd, mask); + time(&time_now); + if (time_now - start_send >= timeout.tv_sec) { + ct->ct_error.re_status = RPC_TIMEDOUT; + goto out; + } SwitchToThread(); continue; }