Back to index

glibc  2.9
Classes | Defines | Functions | Variables
thrsvc.c File Reference
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <rpc/rpc.h>
#include <arpa/inet.h>

Go to the source code of this file.

Classes

struct  rpc_arg

Defines

#define PROGNUM   1234
#define VERSNUM   1
#define PROCNUM   1
#define PROCQUIT   2

Functions

static void dispatch (struct svc_req *request, SVCXPRT *xprt)
static void test_one_call (struct rpc_arg *a)
static void * thread_wrapper (void *arg)
int main (void)

Variables

static int exitcode

Class Documentation

struct rpc_arg

Definition at line 15 of file thrsvc.c.

Collaboration diagram for rpc_arg:
Class Members
CLIENT * client
u_long proc

Define Documentation

#define PROCNUM   1

Definition at line 10 of file thrsvc.c.

#define PROCQUIT   2

Definition at line 11 of file thrsvc.c.

#define PROGNUM   1234

Definition at line 8 of file thrsvc.c.

#define VERSNUM   1

Definition at line 9 of file thrsvc.c.


Function Documentation

static void dispatch ( struct svc_req request,
SVCXPRT xprt 
) [static]

Definition at line 22 of file thrsvc.c.

{
  svc_sendreply(xprt, (xdrproc_t)xdr_void, 0);
  if (request->rq_proc == PROCQUIT)
    exit (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( void  )

Definition at line 64 of file thrsvc.c.

{
  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;
  struct rpc_arg a;

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

  a.client = clnt;
  a.proc = PROCNUM;

  /* Test in this thread */
  test_one_call (&a);

  /* 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;
}

Here is the call graph for this function:

static void test_one_call ( struct rpc_arg a) [static]

Definition at line 30 of file thrsvc.c.

{
  struct timeval tout = { 60, 0 };
  enum clnt_stat result;

  printf ("test_one_call: ");
  result = clnt_call (a->client, a->proc,
                    (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;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void* thread_wrapper ( void *  arg) [static]

Definition at line 50 of file thrsvc.c.

{
  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);
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int exitcode [static]

Definition at line 13 of file thrsvc.c.