home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / n / n001 / 2.ddi / EXAMPLES / DIAG / CLIENT / CLIENT.C next >
Encoding:
C/C++ Source or Header  |  1989-12-11  |  6.6 KB  |  228 lines

  1. /*                                                                            *
  2.  *                                                                            *
  3.  *                  Copyright 1987, 1988, 1989 Netwise, Inc.                  *
  4.  *                              All Rights Reserved                           *
  5.  *   This software contains information which is proprietary to and a trade   *
  6.  *   secret of Netwise, Inc. It is not to be used, reproduced, or disclosed   *
  7.  *   except as authorized in your license agreement.                          *
  8.  *                                                                            *
  9.  *                          Restricted Rights Legend                          *
  10.  *   Use, duplication,  or  disclosure  by the  Government  is  subject  to   *
  11.  *   restrictions as set forth in subparagraph (c)(1)(ii) of the Rights  in   *
  12.  *   Technical Data and  Computer Software clause  at 252.227-7013, or  the   *
  13.  *   equivalent Government clause for other agencies.                         *
  14.  *   Contractor: Netwise, Inc., Boulder, CO 80301 USA                         *
  15.  *                                                                            *
  16.  */ 
  17. /*
  18.  * File: diag\client\client.c
  19.  *
  20.  * This example works in the following environments:
  21.  *    NetWare RPC 1.0, NetWare 2.1 or higher, DOS 3.3
  22.  *
  23.  * This is the driver program for the diag example. The purpose of this
  24.  * example is to perform a series of RPC diagnostic tests.
  25.  */
  26.  
  27. #include <stdio.h>
  28. #include "diag.h"    /* client header file, created by the RPC compiler */
  29.  
  30. extern int _rpcerr_;    /* declare RPC error code */
  31.  
  32. /* Server_Name is used to set the process-binding variable.
  33.  * It must be defined as the name the server registers under.
  34.  */
  35. #define Server_Name  "example"
  36.  
  37. /* declare variable of type server_name for process binding */
  38. server_name sname;
  39.  
  40. /* declare variable of type connection_id for process binding for
  41.  * a persistent connection.
  42.  */
  43. connection_id conn;
  44.  
  45. main()
  46. {
  47.     int arg1, arg2;
  48.     int result;
  49.  
  50.     sname = Server_Name;
  51.  
  52.     printf("CLIENT: RPC Diagnostic\n");
  53.  
  54.     /* Test non-persistent connection */
  55.     printf("CLIENT: trying nonper() procedure on server '%s'\n", sname);
  56.     result = nonper(sname, 1);
  57.  
  58.     /* check RPC error call after remote call */
  59.     if (_rpcerr_) {
  60.        printf("CLIENT: RPC error %d in nonper()\n", _rpcerr_);
  61.        exit(1);
  62.     }
  63.     if (result != 1) {
  64.        printf("CLIENT: nonper() returned bad result (%d)\n", result);
  65.        exit(1);
  66.     }
  67.  
  68.     /* Test persistent connection */
  69.     printf("CLIENT: attempting to establish a persistent connection\n");
  70.     /* open persistent connection */
  71.     result = start(sname);
  72.  
  73.     /* check RPC error call after remote call */
  74.     if (_rpcerr_) {
  75.         printf("CLIENT: RPC error %d in start() call\n", _rpcerr_);
  76.         exit(1);
  77.     }
  78.     if (result != 0) {
  79.        printf("CLIENT: start() returned bad result (%d)\n", result);
  80.        exit(1);
  81.     }
  82.     printf("CLIENT: persistent connection established\n");
  83.  
  84.  
  85.     /* Using persistent connection, send simple data */
  86.     do_simple();
  87.  
  88.     /* Using persistent connection, send complex data */
  89.     do_complex();
  90.  
  91.     /* Close persistent connection using stop procedure */
  92.     printf("CLIENT: attempting to close persistent connection\n");
  93.     result = stop();
  94.  
  95.     /* check RPC error call after remote call */
  96.     if (_rpcerr_) {
  97.         printf("CLIENT: RPC error %d in stop() call\n", _rpcerr_);
  98.         exit(1);
  99.     }
  100.     if (result != 0) {
  101.        printf("CLIENT: stop() returned bad result (%d)\n", result);
  102.        exit(1);
  103.     }
  104.     printf("CLIENT: persistent connection closed\n");
  105.  
  106.     /* Retry non-persistent connection */
  107.     printf("CLIENT: retrying nonper()\n");
  108.     result = nonper(sname, -1);
  109.  
  110.     /* check RPC error call after remote call */
  111.     if (_rpcerr_) {
  112.        printf("CLIENT: RPC error %d in nonper()\n", _rpcerr_);
  113.        exit(1);
  114.     }
  115.     if (result != -1) {
  116.        printf("CLIENT: nonper() returned bad result (%d)\n", result);
  117.        exit(1);
  118.     }
  119.  
  120.     exit(0);
  121. }
  122.  
  123. do_simple()
  124. {
  125.     int result;
  126.     long l;
  127.     double d;
  128.     char c;
  129.  
  130.     printf("CLIENT: sending simple data\n");
  131.     result = simple((long)0x1234, (double)1.234e-10, 'a', &l, &d, &c);
  132.  
  133.     if (_rpcerr_) {        /* check RPC return code */
  134.         printf("CLIENT: RPC error %d in simple() call\n",
  135.             _rpcerr_);
  136.         exit(1);
  137.     }
  138.     if (result != 0) {
  139.        printf("CLIENT: simple() returned bad result (%d)\n", result);
  140.        exit(1);
  141.     }
  142.     if (l != 0x1234) {
  143.        printf("CLIENT: simple() returned bad long (%ld)\n", l);
  144.        exit(1);
  145.     }
  146.     if (d != 1.234e-10) {
  147.        printf("CLIENT: simple() returned bad double (%e)\n", d);
  148.        exit(1);
  149.     }
  150.     if (c != 'a') {
  151.        printf("CLIENT: simple() returned bad char (%c)\n", c);
  152.        exit(1);
  153.     }
  154. }
  155.  
  156. #define char_string "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  157.  
  158. do_complex()
  159. {
  160.     int result, i, j;
  161.     struct cmplx_type *cptr, *cnext, cmplx;
  162.     extern char *malloc();
  163.     
  164.  
  165.     printf("CLIENT: building complex data\n");
  166.     /* build a linked list of structures, each of which contains
  167.      * a data element with 5 copies of the character string defined
  168.      * above, and a length element
  169.      */
  170.     cptr=(struct cmplx_type *)0;
  171.     for (i=0; i<9; i++) {
  172.         if ((cnext=
  173.             (struct cmplx_type *)malloc(sizeof(struct cmplx_type))) ==
  174.             (struct cmplx_type *)NULL) {
  175.             printf("CLIENT: malloc failed!  execution aborted\n");
  176.             exit (1);
  177.             }
  178.         cnext->link = cptr;
  179.         cptr=cnext;
  180.         cptr->length=0;
  181.         cptr->data[0]='\0';
  182.         for (j=0; j<5; j++) {
  183.             strcat(cptr->data,char_string);
  184.             cptr->length += strlen(char_string);
  185.         }
  186.     }
  187.             
  188.     printf("CLIENT: sending complex data\n");
  189.     /* by sending a pointer to the head of the linked list, the entire
  190.      * list is sent to the remote procedure.  On return, the entire
  191.      * returned list is created for the client by the client stub
  192.      */
  193.     result = complex(cptr, &cmplx);
  194.  
  195.     if (_rpcerr_) {        /* check RPC return code */
  196.         printf("CLIENT: RPC error %d in complex() call\n",
  197.             _rpcerr_);
  198.         exit(1);
  199.     }
  200.     if (result != 0) {
  201.        printf("CLIENT: complex() returned bad result (%d)\n", result);
  202.        exit(1);
  203.     }
  204.  
  205.     /* the remote procedure simply copied the input list to the output;
  206.      * check that the returned linked list is correct
  207.      */
  208.     i=9;
  209.     for (cnext = &cmplx; cnext != (struct cmplx_type *)0;
  210.                         cnext=cnext->link) {
  211.         i--;
  212.         if (cnext->length != cptr->length) {
  213.              printf("CLIENT: complex() returned bad length data (%d)\n",
  214.                 cnext->length);
  215.           exit(1);
  216.         }
  217.         if (strncmp(cnext->data,cptr->data,cptr->length) != 0) {
  218.              printf("CLIENT: complex() returned bad char data\n");
  219.           printf("CLIENT:          '%s'\n",cnext->data);
  220.           exit(1);
  221.         }
  222.     }
  223.     if (i != 0) {
  224.         printf("CLIENT: complex() returned with bad links (%d)\n", i);
  225.         exit(1);
  226.     }
  227. }
  228.