• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) Bull S.A.  2007 All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like.  Any license provided herein, whether implied or
15 * otherwise, applies only to this software file.  Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 * History:
24 * Created by: Cyril Lacabanne (Cyril.Lacabanne@bull.net)
25 *
26 */
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <time.h>
31 #include <rpc/rpc.h>
32 
33 #define VERSNUM	1
34 #define PROCNUM 10000
35 
36 #define MAXITER	10
37 
38 static void serverDisp();
39 
main(int argc,char ** argv)40 int main(int argc, char **argv)
41 {
42 	CLIENT *clnt = NULL;
43 	SVCXPRT *svc = NULL;
44 	int progNum = atoi(argv[2]);
45 	int test_status = 0;
46 	int run_mode = 0;
47 	struct timeval tv;
48 	long long resTbl[MAXITER];
49 	struct timeval tv1, tv2;
50 	struct timezone tz;
51 	long long diff;
52 	int intSnd = 0;
53 	int intRec;
54 	int i;
55 	int sum;
56 
57 	//Initialization
58 	tv.tv_sec = 0;
59 	tv.tv_usec = 100;
60 
61 	for (i = 0; i < MAXITER; i++)
62 		resTbl[i] = -1;
63 
64 	//Create both client and server handle
65 	svc = svcraw_create();
66 
67 	if (svc == NULL) {
68 		fprintf(stderr, "Could not create server handle\n");
69 		exit(5);
70 	}
71 
72 	if (!svc_register(svc, progNum, VERSNUM, (void *)serverDisp, 0)) {
73 		fprintf(stderr, "Error svc_register\n");
74 		exit(5);
75 	}
76 
77 	clnt = clntraw_create(progNum, VERSNUM);
78 
79 	if (clnt == NULL) {
80 		clnt_pcreateerror("raw");
81 		exit(1);
82 	}
83 
84 	if (run_mode == 1) {
85 		printf("CLNT %p\n", clnt);
86 		printf("SVC %p\n", svc);
87 	}
88 	//Call RPC using testing mode (raw)
89 	for (i = 0; i < MAXITER; i++) {
90 		intSnd = i;
91 
92 		gettimeofday(&tv1, &tz);
93 		if (clnt_call
94 		    (clnt, PROCNUM, (xdrproc_t) xdr_int, (char *)&intSnd,
95 		     (xdrproc_t) xdr_int, (char *)&intRec, tv) != RPC_SUCCESS) {
96 			clnt_perror(clnt, "raw");
97 			exit(1);
98 		} else {
99 			gettimeofday(&tv2, &tz);
100 			diff =
101 			    (tv2.tv_sec - tv1.tv_sec) * 1000000L +
102 			    (tv2.tv_usec - tv1.tv_usec);
103 			resTbl[i] = diff;
104 		}
105 	}
106 
107 	//Test all returned values, calc. average
108 	for (i = 0; i < MAXITER; i++) {
109 		if (resTbl[i] == -1) {
110 			test_status = 1;
111 			break;
112 		}
113 		sum += resTbl[i];
114 		if (run_mode == 1)
115 			fprintf(stderr, "%lld\n", resTbl[i]);
116 	}
117 	sum = (int)(sum / MAXITER);
118 
119 	printf("%d\n", test_status);
120 
121 	return test_status;
122 }
123 
serverDisp(struct svc_req * rqstp,SVCXPRT * transp)124 static void serverDisp(struct svc_req *rqstp, SVCXPRT * transp)
125 {
126 	int numRec;
127 	fprintf(stderr, "in server proc\n");
128 
129 	switch (rqstp->rq_proc) {
130 	case 0:
131 		if (svc_sendreply(transp, (xdrproc_t) xdr_void, 0) == FALSE) {
132 			fprintf(stderr, "error in null proc\n");
133 			exit(1);
134 		}
135 		return;
136 	case PROCNUM:
137 		break;
138 	default:
139 		svcerr_noproc(transp);
140 		return;
141 	}
142 
143 	if (!svc_getargs(transp, (xdrproc_t) xdr_int, (char *)&numRec)) {
144 		svcerr_decode(transp);
145 		return;
146 	}
147 
148 	numRec++;
149 	if (svc_sendreply(transp, (xdrproc_t) xdr_int, (char *)&numRec) ==
150 	    FALSE) {
151 		fprintf(stderr, "error in sending answer\n");
152 		exit(1);
153 	}
154 
155 	return;
156 }
157