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 <sys/types.h>
16 #include <netinet/in.h>
21 /* Bogus procedure to get internet address of host */
22 static u_long GetIpAddress(hostname)
25 struct hostent *hostent;
27 hostent = gethostbyname(hostname);
28 if (!hostent) {printf("host %s not found", hostname);exit(1);}
29 if (hostent->h_length != sizeof(u_long)) {
30 printf("host address is disagreeable length (%d)", hostent->h_length);
33 bcopy(hostent->h_addr, (char *)&host, sizeof(host));
37 long FetchFile(), StoreFile();
43 char *localFile, *remoteFile;
46 struct rx_connection *conn;
48 struct clock startTime, endTime;
49 int fetch = 0, store = 0, verbose = 0;
50 struct rx_securityClass *null_securityObject;
55 while (**argv == '-') {
56 if (strcmp(*argv, "-fetch") == 0) fetch = 1;
57 else if (strcmp(*argv, "-store") == 0) store = 1;
58 else if (strcmp(*argv, "-verbose") == 0) verbose = 1;
60 fprintf(stderr, "Unknown option %s\n", *argv);
65 if (argc != 3 || !(fetch^store)) {
66 fprintf(stderr, "bulk_client -fetch/-store localFile host remoteFile\n");
70 host = GetIpAddress(argv[1]);
74 null_securityObject = rxnull_NewClientSecurityObject();
75 conn = rx_NewConnection(host, BULK_SERVER_PORT, BULK_SERVICE_ID, null_securityObject, BULK_NULL);
78 clock_GetTime(&startTime);
80 call = rx_NewCall(conn);
81 (fetch? FetchFile:StoreFile)(call, verbose, localFile, remoteFile, &length);
82 error = rx_EndCall(call, error);
85 clock_GetTime(&endTime);
86 msec = clock_ElapsedTime(&startTime, &endTime);
87 if (!error) printf("Transferred %d bytes in %d msec, %d bps\n", length, msec, length*1000/msec);
88 else printf("transfer failed: error %d\n", error);
90 /* Allow Rx to idle down any calls; it's a good idea, but not essential, to call this routine */
94 long FetchFile(call, verbose, localFile, remoteFile, length_ptr)
97 char *localFile, *remoteFile;
100 int fd = -1, error = 0;
103 if (StartBULK_FetchFile(call, verbose, remoteFile)) return BULK_ERROR;
104 fd = open(localFile, O_CREAT|O_TRUNC|O_WRONLY, 0666);
105 if (fd < 0 || fstat(fd, &status) < 0) {
106 fprintf("Could not create %s\n", localFile);
109 if (bulk_ReceiveFile(fd, call, &status)) error = BULK_ERROR;
110 *length_ptr = status.st_size;
111 if (fd >= 0) close(fd);
112 /* If there were any output parameters, then it would be necessary to call EndBULKFetchFile(call, &out1,...) here to pick them up */
116 long StoreFile(call, verbose, localFile, remoteFile, length_ptr)
117 struct rx_call *call;
119 char *localFile, *remoteFile;
122 int fd = -1, error = 0;
125 fd = open(localFile, O_RDONLY, 0);
126 if (fd < 0 || fstat(fd, &status) < 0) {
127 fprintf("Could not open %s\n", localFile);
130 error = StartBULK_StoreFile(call, verbose, remoteFile);
131 if (!error) error = bulk_SendFile(fd, call, &status);
132 /* If there were any output parameters, then it would be necessary to call EndBULKStoreFile(call, &out1,...) here to pick them up */
134 *length_ptr = status.st_size;