Remove the RCSID macro
[openafs.git] / src / rx / bulktest / bulk_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 #include <sys/stat.h>
18 #include <sys/file.h>
19 #include <signal.h>
20 #include <stdio.h>
21 #include <rx/xdr.h>
22 #include "bulk.h"
23
24 #define N_SECURITY_OBJECTS 1
25
26 extern BULK_ExecuteRequest();
27
28 InterruptSignal()
29 {
30     rx_PrintStats(stdout);
31     exit(0);
32 }
33
34 main()
35 {
36     struct rx_securityClass *(securityObjects[N_SECURITY_OBJECTS]);
37     struct rx_service *service;
38
39     signal(SIGINT, InterruptSignal);
40
41     /* Initialize Rx, telling it port number this server will use for its single service */
42     if (rx_Init(BULK_SERVER_PORT) < 0)
43         Quit("rx_init");
44
45     /* 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 */
46     securityObjects[BULK_NULL] = rxnull_NewServerSecurityObject();
47     if (securityObjects[BULK_NULL] == (struct rx_securityClass *)0)
48         Quit("rxnull_NewServerSecurityObject");
49
50     /* Instantiate a single BULK service.  The rxgen-generated procedure which is called to decode requests is passed in here (BULK_ExecuteRequest). */
51     service =
52         rx_NewService(0, BULK_SERVICE_ID, "BULK", securityObjects,
53                       N_SECURITY_OBJECTS, BULK_ExecuteRequest);
54     if (service == (struct rx_service *)0)
55         Quit("rx_NewService");
56     rx_SetMaxProcs(service, 5);
57
58     rx_StartServer(1);          /* Donate this process to the server process pool */
59     Quit("StartServer returned?");
60 }
61
62 int bulk_operationNumber = 0;
63
64 int
65 BULK_FetchFile(call, verbose, name)
66      struct rx_call *call;
67      char *name;
68 {
69     int fd = -1;
70     int error = 0;
71     int opnum = ++bulk_operationNumber;
72     struct stat status;
73     if (verbose)
74         printf("%d: fetch %s\n", opnum, name);
75     fd = open(name, O_RDONLY, 0);
76     if (fd < 0 || fstat(fd, &status) < 0) {
77         if (verbose)
78             printf("%d: failed to open %s\n", opnum, name);
79         error = BULK_ERROR;
80         goto fail;
81     }
82     error = bulk_SendFile(fd, call, &status);
83     if (error)
84         printf("%d: fetch of %s failed, error %d\n", opnum, name, error);
85     else if (verbose)
86         printf("%d: fetch of %s complete\n", opnum, name);
87   fail:
88     if (fd >= 0)
89         close(fd);
90     return error;
91 }
92
93 int
94 BULK_StoreFile(call, verbose, name)
95      struct rx_call *call;
96      int verbose;
97      char *name;
98 {
99     int opnum = ++bulk_operationNumber;
100     int fd = -1;
101     struct stat status;
102     int error = 0;
103     if (verbose)
104         printf("%d: store file %s\n", opnum, name);
105     fd = open(name, O_CREAT | O_TRUNC | O_WRONLY, 0666);
106     if (fd < 0 || fstat(fd, &status) < 0) {
107         fprintf(stderr, "%d: could not create %s\n", opnum, name);
108         error = BULK_ERROR;
109         goto fail;
110     }
111     error = bulk_ReceiveFile(fd, call, &status);
112     if (error)
113         printf("%d: store of %s failed, error %d\n", opnum, name, error);
114     else if (verbose)
115         printf("%d: store of %s complete\n", opnum, name);
116
117   fail:
118     if (fd >= 0)
119         close(fd);
120     return error;
121 }
122
123 Quit(msg, a, b)
124      char *msg;
125 {
126     fprintf(stderr, msg, a, b);
127     exit(1);
128 }