home *** CD-ROM | disk | FTP | other *** search
- /* *
- * *
- * Copyright 1987, 1988, 1989 Netwise, Inc. *
- * All Rights Reserved *
- * This software contains information which is proprietary to and a trade *
- * secret of Netwise, Inc. It is not to be used, reproduced, or disclosed *
- * except as authorized in your license agreement. *
- * *
- * Restricted Rights Legend *
- * Use, duplication, or disclosure by the Government is subject to *
- * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in *
- * Technical Data and Computer Software clause at 252.227-7013, or the *
- * equivalent Government clause for other agencies. *
- * Contractor: Netwise, Inc., Boulder, CO 80301 USA *
- * *
- */
- /*
- * File: diag\client\client.c
- *
- * This example works in the following environments:
- * NetWare RPC 1.0, NetWare 2.1 or higher, DOS 3.3
- *
- * This is the driver program for the diag example. The purpose of this
- * example is to perform a series of RPC diagnostic tests.
- */
-
- #include <stdio.h>
- #include "diag.h" /* client header file, created by the RPC compiler */
-
- extern int _rpcerr_; /* declare RPC error code */
-
- /* Server_Name is used to set the process-binding variable.
- * It must be defined as the name the server registers under.
- */
- #define Server_Name "example"
-
- /* declare variable of type server_name for process binding */
- server_name sname;
-
- /* declare variable of type connection_id for process binding for
- * a persistent connection.
- */
- connection_id conn;
-
- main()
- {
- int arg1, arg2;
- int result;
-
- sname = Server_Name;
-
- printf("CLIENT: RPC Diagnostic\n");
-
- /* Test non-persistent connection */
- printf("CLIENT: trying nonper() procedure on server '%s'\n", sname);
- result = nonper(sname, 1);
-
- /* check RPC error call after remote call */
- if (_rpcerr_) {
- printf("CLIENT: RPC error %d in nonper()\n", _rpcerr_);
- exit(1);
- }
- if (result != 1) {
- printf("CLIENT: nonper() returned bad result (%d)\n", result);
- exit(1);
- }
-
- /* Test persistent connection */
- printf("CLIENT: attempting to establish a persistent connection\n");
- /* open persistent connection */
- result = start(sname);
-
- /* check RPC error call after remote call */
- if (_rpcerr_) {
- printf("CLIENT: RPC error %d in start() call\n", _rpcerr_);
- exit(1);
- }
- if (result != 0) {
- printf("CLIENT: start() returned bad result (%d)\n", result);
- exit(1);
- }
- printf("CLIENT: persistent connection established\n");
-
-
- /* Using persistent connection, send simple data */
- do_simple();
-
- /* Using persistent connection, send complex data */
- do_complex();
-
- /* Close persistent connection using stop procedure */
- printf("CLIENT: attempting to close persistent connection\n");
- result = stop();
-
- /* check RPC error call after remote call */
- if (_rpcerr_) {
- printf("CLIENT: RPC error %d in stop() call\n", _rpcerr_);
- exit(1);
- }
- if (result != 0) {
- printf("CLIENT: stop() returned bad result (%d)\n", result);
- exit(1);
- }
- printf("CLIENT: persistent connection closed\n");
-
- /* Retry non-persistent connection */
- printf("CLIENT: retrying nonper()\n");
- result = nonper(sname, -1);
-
- /* check RPC error call after remote call */
- if (_rpcerr_) {
- printf("CLIENT: RPC error %d in nonper()\n", _rpcerr_);
- exit(1);
- }
- if (result != -1) {
- printf("CLIENT: nonper() returned bad result (%d)\n", result);
- exit(1);
- }
-
- exit(0);
- }
-
- do_simple()
- {
- int result;
- long l;
- double d;
- char c;
-
- printf("CLIENT: sending simple data\n");
- result = simple((long)0x1234, (double)1.234e-10, 'a', &l, &d, &c);
-
- if (_rpcerr_) { /* check RPC return code */
- printf("CLIENT: RPC error %d in simple() call\n",
- _rpcerr_);
- exit(1);
- }
- if (result != 0) {
- printf("CLIENT: simple() returned bad result (%d)\n", result);
- exit(1);
- }
- if (l != 0x1234) {
- printf("CLIENT: simple() returned bad long (%ld)\n", l);
- exit(1);
- }
- if (d != 1.234e-10) {
- printf("CLIENT: simple() returned bad double (%e)\n", d);
- exit(1);
- }
- if (c != 'a') {
- printf("CLIENT: simple() returned bad char (%c)\n", c);
- exit(1);
- }
- }
-
- #define char_string "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
-
- do_complex()
- {
- int result, i, j;
- struct cmplx_type *cptr, *cnext, cmplx;
- extern char *malloc();
-
-
- printf("CLIENT: building complex data\n");
- /* build a linked list of structures, each of which contains
- * a data element with 5 copies of the character string defined
- * above, and a length element
- */
- cptr=(struct cmplx_type *)0;
- for (i=0; i<9; i++) {
- if ((cnext=
- (struct cmplx_type *)malloc(sizeof(struct cmplx_type))) ==
- (struct cmplx_type *)NULL) {
- printf("CLIENT: malloc failed! execution aborted\n");
- exit (1);
- }
- cnext->link = cptr;
- cptr=cnext;
- cptr->length=0;
- cptr->data[0]='\0';
- for (j=0; j<5; j++) {
- strcat(cptr->data,char_string);
- cptr->length += strlen(char_string);
- }
- }
-
- printf("CLIENT: sending complex data\n");
- /* by sending a pointer to the head of the linked list, the entire
- * list is sent to the remote procedure. On return, the entire
- * returned list is created for the client by the client stub
- */
- result = complex(cptr, &cmplx);
-
- if (_rpcerr_) { /* check RPC return code */
- printf("CLIENT: RPC error %d in complex() call\n",
- _rpcerr_);
- exit(1);
- }
- if (result != 0) {
- printf("CLIENT: complex() returned bad result (%d)\n", result);
- exit(1);
- }
-
- /* the remote procedure simply copied the input list to the output;
- * check that the returned linked list is correct
- */
- i=9;
- for (cnext = &cmplx; cnext != (struct cmplx_type *)0;
- cnext=cnext->link) {
- i--;
- if (cnext->length != cptr->length) {
- printf("CLIENT: complex() returned bad length data (%d)\n",
- cnext->length);
- exit(1);
- }
- if (strncmp(cnext->data,cptr->data,cptr->length) != 0) {
- printf("CLIENT: complex() returned bad char data\n");
- printf("CLIENT: '%s'\n",cnext->data);
- exit(1);
- }
- }
- if (i != 0) {
- printf("CLIENT: complex() returned with bad links (%d)\n", i);
- exit(1);
- }
- }
-