28be0db42ba55e4bc2facc59e43b499d87fd69ad
[openafs.git] / src / rx / multi.example / sample_server.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 <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #include <sys/types.h>
15 #include <netdb.h>
16 #include <netinet/in.h>
17
18 #include <stdio.h>
19 #include "sample.h"
20
21 #define N_SECURITY_OBJECTS 1
22
23 extern TEST__ExecuteRequest();
24
25 main()
26 {
27     struct rx_securityClass *(securityObjects[N_SECURITY_OBJECTS]);
28     struct rx_service *service;
29
30     /* Initialize Rx, telling it port number this server will use for its single service */
31     if (rx_Init(SAMPLE_SERVER_PORT) < 0)
32         Quit("rx_init");
33
34     /* Create a single security object, in this case the null security object, for unauthenticated connections, which will be used to control security on connections made to this server */
35     securityObjects[SAMPLE_NULL] = rxnull_NewServerSecurityObject();
36     if (securityObjects[SAMPLE_NULL] == (struct rx_securityClass *)0)
37         Quit("rxnull_NewServerSecurityObject");
38
39     /* Instantiate a single sample service.  The rxgen-generated procedure which is called to decode requests is passed in here (TEST_ExecuteRequest). */
40     service =
41         rx_NewService(0, SAMPLE_SERVICE_ID, "sample", securityObjects,
42                       N_SECURITY_OBJECTS, TEST__ExecuteRequest);
43     if (service == (struct rx_service *)0)
44         Quit("rx_NewService");
45
46     rx_StartServer(1);          /* Donate this process to the server process pool */
47     Quit("StartServer returned?");
48 }
49
50 int
51 TEST_Add(call, verbose, a, b, result)
52      struct rx_call *call;
53      int verbose;
54      int a, b;
55      int *result;
56 {
57     if (verbose)
58         printf("TEST_Add(%d,%d,%d)\n", verbose, a, b);
59     *result = a + b;
60     return 0;
61 }
62
63 int
64 TEST_Sub(call, verbose, a, b, result)
65      struct rx_call *call;
66      int verbose;
67      int a, b;
68      int *result;
69 {
70     if (verbose)
71         printf("TEST_Sub(%d,%d,%d)\n", verbose, a, b);
72     *result = a - b;
73     return 0;
74 }
75
76 Quit(msg, a, b)
77      char *msg;
78 {
79     fprintf(stderr, msg, a, b);
80     exit(1);
81 }