2002-04-20 22:36:26 +02:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <rpc/rpc.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#define PROGNUM 1234
|
|
|
|
#define VERSNUM 1
|
|
|
|
#define PROCNUM 1
|
2002-10-14 20:10:15 +02:00
|
|
|
#define PROCQUIT 2
|
2002-04-20 22:36:26 +02:00
|
|
|
|
|
|
|
static int exitcode;
|
|
|
|
|
2002-10-14 20:10:15 +02:00
|
|
|
struct rpc_arg
|
|
|
|
{
|
|
|
|
CLIENT *client;
|
|
|
|
u_long proc;
|
|
|
|
};
|
|
|
|
|
2002-04-20 22:36:26 +02:00
|
|
|
static void
|
|
|
|
dispatch(struct svc_req *request, SVCXPRT *xprt)
|
|
|
|
{
|
2002-10-14 20:10:15 +02:00
|
|
|
svc_sendreply(xprt, (xdrproc_t)xdr_void, 0);
|
|
|
|
if (request->rq_proc == PROCQUIT)
|
|
|
|
exit (0);
|
2002-04-20 22:36:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-10-14 20:10:15 +02:00
|
|
|
test_one_call (struct rpc_arg *a)
|
2002-04-20 22:36:26 +02:00
|
|
|
{
|
|
|
|
struct timeval tout = { 60, 0 };
|
|
|
|
enum clnt_stat result;
|
|
|
|
|
|
|
|
printf ("test_one_call: ");
|
2002-10-14 20:10:15 +02:00
|
|
|
result = clnt_call (a->client, a->proc,
|
2002-04-20 22:36:26 +02:00
|
|
|
(xdrproc_t) xdr_void, 0,
|
|
|
|
(xdrproc_t) xdr_void, 0, tout);
|
|
|
|
if (result == RPC_SUCCESS)
|
|
|
|
puts ("success");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clnt_perrno (result);
|
|
|
|
putchar ('\n');
|
|
|
|
exitcode = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
thread_wrapper (void *arg)
|
|
|
|
{
|
2002-10-14 20:10:15 +02:00
|
|
|
struct rpc_arg a;
|
|
|
|
|
|
|
|
a.client = (CLIENT *)arg;
|
|
|
|
a.proc = PROCNUM;
|
|
|
|
test_one_call (&a);
|
|
|
|
a.client = (CLIENT *)arg;
|
|
|
|
a.proc = PROCQUIT;
|
|
|
|
test_one_call (&a);
|
2002-04-20 22:36:26 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
|
|
|
pthread_t tid;
|
|
|
|
pid_t pid;
|
|
|
|
int err;
|
|
|
|
SVCXPRT *svx;
|
|
|
|
CLIENT *clnt;
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
struct timeval wait = { 5, 0 };
|
|
|
|
int sock = RPC_ANYSOCK;
|
2002-10-14 20:10:15 +02:00
|
|
|
struct rpc_arg a;
|
2002-04-20 22:36:26 +02:00
|
|
|
|
|
|
|
svx = svcudp_create (RPC_ANYSOCK);
|
|
|
|
svc_register (svx, PROGNUM, VERSNUM, dispatch, 0);
|
|
|
|
|
|
|
|
pid = fork ();
|
|
|
|
if (pid == -1)
|
|
|
|
{
|
|
|
|
perror ("fork");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (pid == 0)
|
|
|
|
svc_run ();
|
|
|
|
|
|
|
|
inet_aton ("127.0.0.1", &sin.sin_addr);
|
|
|
|
sin.sin_port = htons (svx->xp_port);
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
|
|
|
|
clnt = clntudp_create (&sin, PROGNUM, VERSNUM, wait, &sock);
|
|
|
|
|
2002-10-14 20:10:15 +02:00
|
|
|
a.client = clnt;
|
|
|
|
a.proc = PROCNUM;
|
|
|
|
|
2002-04-20 22:36:26 +02:00
|
|
|
/* Test in this thread */
|
2002-10-14 20:10:15 +02:00
|
|
|
test_one_call (&a);
|
2002-04-20 22:36:26 +02:00
|
|
|
|
|
|
|
/* Test in a child thread */
|
|
|
|
err = pthread_create (&tid, 0, thread_wrapper, (void *) clnt);
|
|
|
|
if (err)
|
|
|
|
fprintf (stderr, "pthread_create: %s\n", strerror (err));
|
|
|
|
err = pthread_join (tid, 0);
|
|
|
|
if (err)
|
|
|
|
fprintf (stderr, "pthread_join: %s\n", strerror (err));
|
|
|
|
|
|
|
|
return exitcode;
|
|
|
|
}
|