Standardize License information
[openafs.git] / src / rx / test / kstest.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include "afs/param.h"
11 #include <sys/types.h>
12 #include <netinet/in.h>
13 #include <netdb.h>
14 #include <stdio.h>
15 #include <signal.h>
16 #include "xdr.h"
17 #include "rx.h"
18 #include "rx_globals.h"
19 #include "rx_null.h"
20
21 static int port;
22 static short stats = 0;
23
24 void SigInt(int ignore) {
25     if (rx_debugFile) {
26         rx_PrintStats(rx_debugFile);
27         fflush(rx_debugFile);
28     }
29     if (stats) rx_PrintStats(stdout);
30     exit(1);
31 }
32
33
34 static ParseCmd(argc, argv)
35 int argc;
36 char **argv; {
37     register int i;
38     for(i=1;i<argc;i++) {
39         if (!strcmp(argv[i],"-port")) {
40             port = atoi(argv[i+1]);
41             port = htons(port);
42             i++;
43         }
44         else if (!strcmp(argv[i],"-log")) {
45             rx_debugFile = fopen("kstest.log", "w");
46             if (rx_debugFile == NULL) printf("Couldn't open rx_stest.db");
47             signal(SIGINT, SigInt);
48         }
49         else if (!strcmp(argv[i], "-stats")) stats = 1;
50         else {
51             printf("unrecognized switch '%s'\n", argv[i]);
52             return -1;
53         }
54     }
55     return 0;
56 }
57
58 /* er loop */
59 static rxk_erproc (acall)
60 struct rx_call *acall; {
61     XDR xdr;
62     long temp;
63
64     xdrrx_create(&xdr, acall, XDR_DECODE);
65     xdr_long(&xdr, &temp);
66     temp++;
67     xdr.x_op = XDR_ENCODE;
68     xdr_long(&xdr, &temp);
69     return 0;
70 }
71
72 main(argc, argv)
73 int argc;
74 char **argv; {
75     register long code;
76     static struct rx_securityClass *sc[3];  /* so other kernel procs can reference it */
77     register struct rx_service *tservice;
78
79     port = htons(10000);
80     if (ParseCmd(argc, argv) != 0) {
81         printf("erorr parsing commands\n");
82         exit(1);
83     }
84     code = rx_Init(port);
85     if (code) {
86         printf("init failed code %d\n", code);
87         exit(1);
88     }
89     signal(SIGINT, SigInt);
90     printf("back from rx server init\n");
91     sc[0] = rxnull_NewServerSecurityObject();
92     sc[1] = sc[2] = 0;
93     printf("new secobj created\n");
94     tservice = rx_NewService(0, 1, "test", sc, 1 /* 3 */, rxk_erproc);
95     printf("service is %x\n", tservice);
96     if (!tservice) {
97         printf("failed to create service\n");
98         exit(1);
99     }
100     rx_StartServer(1);  /* donate self */
101 }