[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.
This commit is contained in:
Olga Kornievskaia 2011-05-16 15:46:45 -04:00
parent d83fece068
commit b6beb6f2a9
2 changed files with 10 additions and 2 deletions

View file

@ -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;

View file

@ -64,6 +64,7 @@
#include <string.h>
//#include <unistd.h>
//#include <signal.h>
#include <time.h>
#include <rpc/rpc.h>
#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;
}