2 * Copyright 2000, International Business Machines Corporation and others.
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
10 /* Sample program using multi_Rx, to execute calls in parallel to multiple hosts */
12 #include <afsconfig.h>
13 #include <afs/param.h>
16 #include <sys/types.h>
20 #include <netinet/in.h>
24 #include <rx/rx_null.h>
31 rx_PrintStats(stdout
);
36 /* Bogus procedure to get internet address of host */
38 GetIpAddress(hostname
)
41 struct hostent
*hostent
;
43 hostent
= gethostbyname(hostname
);
45 printf("host %s not found", hostname
);
48 if (hostent
->h_length
!= sizeof(u_long
)) {
49 printf("host address is disagreeable length (%d)", hostent
->h_length
);
52 memcpy((char *)&host
, hostent
->h_addr
, sizeof(host
));
56 long FetchFile(), StoreFile();
60 struct rx_connection
*conn
;
74 struct async_work
*work
= (struct async_work
*)data
;
76 struct clock startTime
, endTime
;
82 for (i
= 0; i
< work
->count
; i
++) {
83 call
= rx_NewCall(work
->conn
);
85 clock_GetTime(&startTime
);
87 ((work
->store
? StoreFile
: FetchFile
) (call
, work
->verbose
,
88 work
->local
, work
->remote
,
90 error
= rx_EndCall(call
, error
);
93 clock_GetTime(&endTime
);
94 msec
= clock_ElapsedTime(&startTime
, &endTime
);
95 if (work
->verbose
&& !error
)
96 printf("%s: %s %s, %d bytes in %d msec, %d bps\n", work
->host
,
97 work
->store
? "stored" : "fetched",
98 work
->store
? work
->local
: work
->remote
, length
, msec
,
99 length
* 1000 / msec
);
101 printf("%s: %s of %s failed: error %d\n", work
->host
,
102 work
->store
? "store" : "fetch",
103 work
->store
? work
->local
: work
->remote
, error
);
106 osi_Wakeup(&async_nProcs
);
109 async_BulkTest(host
, conn
, store
, count
, verbose
, file
)
111 struct rx_connection
*conn
;
120 struct async_work
*work
= malloc(sizeof(struct async_work
));
125 work
->verbose
= verbose
;
126 name
= strrchr(file
, '/');
131 /* sprintf(tempfile, "/usr/tmp/%s.%s", myHostName, name);*/
132 sprintf(tempfile
, "/usr/tmp/%s", name
);
133 work
->local
= strdup(store
? file
: tempfile
);
134 work
->remote
= strdup(store
? tempfile
: file
);
136 LWP_CreateProcess(async_BulkProc
, 3000, RX_PROCESS_PRIORITY
, (void *)work
,
141 FetchFile(call
, verbose
, localFile
, remoteFile
, length_ptr
)
142 struct rx_call
*call
;
144 char *localFile
, *remoteFile
;
147 int fd
= -1, error
= 0;
150 if (StartBULK_FetchFile(call
, verbose
, remoteFile
))
152 fd
= open(localFile
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0666);
153 if (fd
< 0 || fstat(fd
, &status
) < 0) {
154 fprintf("Could not create %s\n", localFile
);
156 } else if (bulk_ReceiveFile(fd
, call
, &status
))
158 *length_ptr
= status
.st_size
;
161 /* If there were any output parameters, then it would be necessary to call EndBULKFetchFile(call, &out1,...) here to pick them up */
166 StoreFile(call
, verbose
, localFile
, remoteFile
, length_ptr
)
167 struct rx_call
*call
;
169 char *localFile
, *remoteFile
;
172 int fd
= -1, error
= 0;
175 fd
= open(localFile
, O_RDONLY
, 0);
176 if (fd
< 0 || fstat(fd
, &status
) < 0) {
177 fprintf("Could not open %s\n", localFile
);
180 error
= StartBULK_StoreFile(call
, verbose
, remoteFile
);
182 error
= bulk_SendFile(fd
, call
, &status
);
183 /* If there were any output parameters, then it would be necessary to call EndBULKStoreFile(call, &out1,...) here to pick them up */
185 *length_ptr
= status
.st_size
;
195 char *hostname
= NULL
;
197 struct rx_securityClass
*null_securityObject
;
198 struct rx_connection
*conn
= (struct rx_connection
*)0;
199 gethostname(myHostName
, sizeof(myHostName
));
200 signal(SIGINT
, InterruptSignal
);
203 null_securityObject
= rxnull_NewClientSecurityObject();
207 while (**argv
== '-') {
208 if (strcmp(*argv
, "-h") == 0) {
211 host
= GetIpAddress(hostname
);
213 rx_NewConnection(host
, BULK_SERVER_PORT
, BULK_SERVICE_ID
,
214 null_securityObject
, RX_SECIDX_NULL
);
215 } else if (strcmp(*argv
, "-f") == 0)
217 else if (strcmp(*argv
, "-s") == 0)
219 else if (strcmp(*argv
, "-v") == 0)
221 else if (strcmp(*argv
, "-c") == 0)
222 (count
= atoi(*++argv
)), argc
--;
224 fprintf(stderr
, "Unknown option %s\n", *argv
);
231 fprintf(stderr
, "local + remote file names expected\n");
234 if (conn
== (struct rx_connection
*)0) {
235 fprintf(stderr
, "No host specified\n");
238 async_BulkTest(hostname
, conn
, store
, count
, verbose
, argv
[0]);
243 osi_Sleep(&async_nProcs
);
245 fprintf(stderr
, "All transfers done\n");
246 rx_PrintStats(stdout
);
247 /* Allow Rx to idle down any calls; it's a good idea, but not essential, to call this routine */