Update.
[glibc.git] / sunrpc / thrsvc.c
blobac6af09f5b75192e49b474a0be0cb278c65b2568
1 #include <pthread.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include <rpc/rpc.h>
6 #include <arpa/inet.h>
8 #define PROGNUM 1234
9 #define VERSNUM 1
10 #define PROCNUM 1
12 static int exitcode;
14 static void
15 dispatch(struct svc_req *request, SVCXPRT *xprt)
17 svc_sendreply(xprt, (xdrproc_t)xdr_void, 0);
20 static void
21 test_one_call (CLIENT *c)
23 struct timeval tout = { 60, 0 };
24 enum clnt_stat result;
26 printf ("test_one_call: ");
27 result = clnt_call (c, PROCNUM,
28 (xdrproc_t) xdr_void, 0,
29 (xdrproc_t) xdr_void, 0, tout);
30 if (result == RPC_SUCCESS)
31 puts ("success");
32 else
34 clnt_perrno (result);
35 putchar ('\n');
36 exitcode = 1;
40 static void *
41 thread_wrapper (void *arg)
43 test_one_call ((CLIENT *)arg);
44 return 0;
47 int
48 main (void)
50 pthread_t tid;
51 pid_t pid;
52 int err;
53 SVCXPRT *svx;
54 CLIENT *clnt;
55 struct sockaddr_in sin;
56 struct timeval wait = { 5, 0 };
57 int sock = RPC_ANYSOCK;
59 svx = svcudp_create (RPC_ANYSOCK);
60 svc_register (svx, PROGNUM, VERSNUM, dispatch, 0);
62 pid = fork ();
63 if (pid == -1)
65 perror ("fork");
66 return 1;
68 if (pid == 0)
69 svc_run ();
71 inet_aton ("127.0.0.1", &sin.sin_addr);
72 sin.sin_port = htons (svx->xp_port);
73 sin.sin_family = AF_INET;
75 clnt = clntudp_create (&sin, PROGNUM, VERSNUM, wait, &sock);
77 /* Test in this thread */
78 test_one_call (clnt);
80 /* Test in a child thread */
81 err = pthread_create (&tid, 0, thread_wrapper, (void *) clnt);
82 if (err)
83 fprintf (stderr, "pthread_create: %s\n", strerror (err));
84 err = pthread_join (tid, 0);
85 if (err)
86 fprintf (stderr, "pthread_join: %s\n", strerror (err));
88 return exitcode;