c13161327bfcfe2a91a3edbb0fc1f171b70ad6c9
[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
24 main()
25 {
26     struct rx_securityClass *(securityObjects[N_SECURITY_OBJECTS]);
27     struct rx_service *service;
28
29     /* Initialize Rx, telling it port number this server will use for its single service */
30     if (rx_Init(SAMPLE_SERVER_PORT) < 0)
31         Quit("rx_init");
32
33     /* 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 */
34     securityObjects[SAMPLE_NULL] = rxnull_NewServerSecurityObject();
35     if (securityObjects[SAMPLE_NULL] == (struct rx_securityClass *)0)
36         Quit("rxnull_NewServerSecurityObject");
37
38     /* Instantiate a single sample service.  The rxgen-generated procedure which is called to decode requests is passed in here (TEST_ExecuteRequest). */
39     service =
40         rx_NewService(0, SAMPLE_SERVICE_ID, "sample", securityObjects,
41                       N_SECURITY_OBJECTS, TEST__ExecuteRequest);
42     if (service == (struct rx_service *)0)
43         Quit("rx_NewService");
44
45     rx_StartServer(1);          /* Donate this process to the server process pool */
46     Quit("StartServer returned?");
47 }
48
49 int
50 TEST_Add(call, verbose, a, b, result)
51      struct rx_call *call;
52      int verbose;
53      int a, b;
54      int *result;
55 {
56     if (verbose)
57         printf("TEST_Add(%d,%d,%d)\n", verbose, a, b);
58     *result = a + b;
59     return 0;
60 }
61
62 int
63 TEST_Sub(call, verbose, a, b, result)
64      struct rx_call *call;
65      int verbose;
66      int a, b;
67      int *result;
68 {
69     if (verbose)
70         printf("TEST_Sub(%d,%d,%d)\n", verbose, a, b);
71     *result = a - b;
72     return 0;
73 }
74
75 Quit(msg, a, b)
76      char *msg;
77 {
78     fprintf(stderr, msg, a, b);
79     exit(1);
80 }