Example #1
0
int
main(int argc, char **argv)
{
	CLIENT		*cl;
	square_in	in;
	square_out	*outp;
	struct timeval	tv;

	if (argc != 4)
		err_quit("usage: client <hostname> <integer-value> <protocol>");

	cl = Clnt_create(argv[1], SQUARE_PROG, SQUARE_VERS, argv[3]);

	Clnt_control(cl, CLGET_TIMEOUT, (char *) &tv);
	printf("timeout = %ld sec, %ld usec\n", tv.tv_sec, tv.tv_usec);
	if (clnt_control(cl, CLGET_RETRY_TIMEOUT, (char *) &tv) == TRUE)
		printf("retry timeout = %ld sec, %ld usec\n", tv.tv_sec, tv.tv_usec);

	in.arg1 = atol(argv[2]);
	if ( (outp = squareproc_1(&in, cl)) == NULL)
		err_quit("%s", clnt_sperror(cl, argv[1]));

	printf("result: %ld\n", outp->res1);
	exit(0);
}
Example #2
0
int
main(int argc, char **argv)
{
	CLIENT		*cl;
	square_in	in;
	square_out	*outp;

	if (argc != 4)
		err_quit("usage: client <hostname> <integer-value> <protocol>");

	cl = Clnt_create(argv[1], SQUARE_PROG, SQUARE_VERS, argv[3]);

	in.arg1 = atol(argv[2]);
	if ( (outp = squareproc_1(&in, cl)) == NULL)
		err_quit("%s", clnt_sperror(cl, argv[1]));

	printf("result: %ld\n", outp->res1);
	exit(0);
}
Example #3
0
int
main(int argc, char **argv)
{
	CLIENT		*cl;
	square_in	in;
	square_out	out;

	if (argc != 3)
		err_quit("usage: client <hostname> <integer-value>");

	cl = Clnt_create(argv[1], SQUARE_PROG, SQUARE_VERS, "tcp");

	in.arg1 = atol(argv[2]);
	if (squareproc_2(&in, &out, cl) != RPC_SUCCESS)
		err_quit("%s", clnt_sperror(cl, argv[1]));

	printf("result: %ld\n", out.res1);
	exit(0);
}
Example #4
0
int
main(int argc, char **argv)
{
	int		i, nloop;
	CLIENT	*cl;
	struct timeval	tv;

	if (argc != 4)
		err_quit("usage: lat_sunrpc_client <hostname> <#loops> <protocol>");
	nloop = atoi(argv[2]);

	cl = Clnt_create(argv[1], BW_SUNRPC_PROG, BW_SUNRPC_VERS, argv[3]);

	tv.tv_sec = 10;
	tv.tv_usec = 0;
	Start_time();
	for (i = 0; i < nloop; i++) {
		if (clnt_call(cl, NULLPROC, xdr_void, NULL,
					  xdr_void, NULL, tv) != RPC_SUCCESS)
			err_quit("%s", clnt_sperror(cl, argv[1]));
	}
	printf("latency: %.3f usec\n", Stop_time() / nloop);
	exit(0);
}
Example #5
0
/* Client routine  to send the asynchrnous response, key is used to wait for a response */
int nlm_send_async(int                  proc,
                   state_nlm_client_t * host,
                   void               * inarg,
                   void               * key)
{
  struct timeval  tout = { 0, 10 };
  int             retval, retry;
  struct timeval  start, now;
  struct timespec timeout;

  for(retry = 1; retry <= MAX_ASYNC_RETRY; retry++)
    {
      if(host->slc_callback_clnt == NULL)
        {
          LogFullDebug(COMPONENT_NLM,
                       "Clnt_create %s",
                       host->slc_nsm_client->ssc_nlm_caller_name);

          host->slc_callback_clnt = Clnt_create(host->slc_nsm_client->ssc_nlm_caller_name,
                                                NLMPROG,
                                                NLM4_VERS,
                                                (char *)xprt_type_to_str(host->slc_client_type));

          if(host->slc_callback_clnt == NULL)
            {
              LogMajor(COMPONENT_NLM,
                       "Cannot create NLM async %s connection to client %s",
                       xprt_type_to_str(host->slc_client_type),
                       host->slc_nsm_client->ssc_nlm_caller_name);
              return -1;
            }
        }

      pthread_mutex_lock(&nlm_async_resp_mutex);
      resp_key = key;
      pthread_mutex_unlock(&nlm_async_resp_mutex);

      LogFullDebug(COMPONENT_NLM, "About to make clnt_call");
      retval = clnt_call(host->slc_callback_clnt,
                         proc,
                         nlm_reply_proc[proc],
                         inarg,
                         (xdrproc_t) xdr_void,
                         NULL,
                         tout);
      LogFullDebug(COMPONENT_NLM, "Done with clnt_call");

      if(retval == RPC_TIMEDOUT || retval == RPC_SUCCESS)
        {
          retval = RPC_SUCCESS;
          break;
        }

      LogDebug(COMPONENT_NLM,
               "NLM async Client procedure call %d failed with return code %d %s",
               proc, retval, clnt_sperror(host->slc_callback_clnt, ""));

      Clnt_destroy(host->slc_callback_clnt);
      host->slc_callback_clnt = NULL;

      if(retry == MAX_ASYNC_RETRY)
        {
          LogMajor(COMPONENT_NLM,
                   "NLM async Client exceeded retry count %d",
                   MAX_ASYNC_RETRY);
          pthread_mutex_lock(&nlm_async_resp_mutex);
          resp_key = NULL;
          pthread_mutex_unlock(&nlm_async_resp_mutex);
          return retval;
        }
    }

  pthread_mutex_lock(&nlm_async_resp_mutex);
  if(resp_key != NULL)
    {
      /* Wait for 5 seconds or a signal */
      gettimeofday(&start, NULL);
      gettimeofday(&now, NULL);
      timeout.tv_sec = 5 + start.tv_sec;
      timeout.tv_nsec = 0;
      LogFullDebug(COMPONENT_NLM,
                   "About to wait for signal for key %p",
                   resp_key);
      while(resp_key != NULL && now.tv_sec < (start.tv_sec + 5))
        {
          int rc = pthread_cond_timedwait(&nlm_async_resp_cond, &nlm_async_resp_mutex, &timeout);
          LogFullDebug(COMPONENT_NLM,
                       "pthread_cond_timedwait returned %d", rc);
          gettimeofday(&now, NULL);
        }
      LogFullDebug(COMPONENT_NLM, "Done waiting");
    }
  pthread_mutex_unlock(&nlm_async_resp_mutex);

  return retval;
}