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>
25 /* Bogus procedure to get internet address of host */
27 GetIpAddress(char *hostname
)
29 struct hostent
*hostent
;
31 hostent
= gethostbyname(hostname
);
33 printf("host %s not found", hostname
);
36 if (hostent
->h_length
!= sizeof(u_long
)) {
37 printf("host address is disagreeable length (%d)", hostent
->h_length
);
40 memcpy((char *)&host
, hostent
->h_addr
, sizeof(host
));
44 long FetchFile(struct rx_call
*call
, int verbose
, char *localFile
,
45 char *remoteFile
, long *length_ptr
);
46 long StoreFile(struct rx_call
*call
, int verbose
, char *localFile
,
47 char *remoteFile
, long *length_ptr
);
51 main(int argc
, char **argv
)
53 char *localFile
, *remoteFile
;
56 struct rx_connection
*conn
;
58 struct clock startTime
, endTime
;
59 int fetch
= 0, store
= 0, verbose
= 0;
60 struct rx_securityClass
*null_securityObject
;
66 while (**argv
== '-') {
67 if (strcmp(*argv
, "-fetch") == 0)
69 else if (strcmp(*argv
, "-store") == 0)
71 else if (strcmp(*argv
, "-verbose") == 0)
74 fprintf(stderr
, "Unknown option %s\n", *argv
);
80 if (argc
!= 3 || !(fetch
^ store
)) {
82 "bulk_client -fetch/-store localFile host remoteFile\n");
86 host
= GetIpAddress(argv
[1]);
90 null_securityObject
= rxnull_NewClientSecurityObject();
92 rx_NewConnection(host
, BULK_SERVER_PORT
, BULK_SERVICE_ID
,
93 null_securityObject
, RX_SECIDX_NULL
);
96 clock_GetTime(&startTime
);
98 call
= rx_NewCall(conn
);
99 (fetch
? FetchFile
: StoreFile
) (call
, verbose
, localFile
, remoteFile
,
101 error
= rx_EndCall(call
, error
);
104 clock_GetTime(&endTime
);
105 msec
= clock_ElapsedTime(&startTime
, &endTime
);
107 printf("Transferred %d bytes in %d msec, %d bps\n", length
, msec
,
108 length
* 1000 / msec
);
110 printf("transfer failed: error %d\n", error
);
112 /* Allow Rx to idle down any calls; it's a good idea, but not essential, to call this routine */
117 FetchFile(struct rx_call
*call
, int verbose
, char *localFile
,
118 char *remoteFile
, long *length_ptr
)
120 int fd
= -1, error
= 0;
123 if (StartBULK_FetchFile(call
, verbose
, remoteFile
))
125 fd
= open(localFile
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0666);
126 if (fd
< 0 || fstat(fd
, &status
) < 0) {
127 fprintf(stderr
, "Could not create %s\n", localFile
);
130 if (bulk_ReceiveFile(fd
, call
, &status
))
132 *length_ptr
= status
.st_size
;
135 /* If there were any output parameters, then it would be necessary to call EndBULKFetchFile(call, &out1,...) here to pick them up */
140 StoreFile(struct rx_call
*call
, int verbose
, char *localFile
,
141 char *remoteFile
, long *length_ptr
)
143 int fd
= -1, error
= 0;
146 fd
= open(localFile
, O_RDONLY
, 0);
147 if (fd
< 0 || fstat(fd
, &status
) < 0) {
148 fprintf(stderr
, "Could not open %s\n", localFile
);
151 error
= StartBULK_StoreFile(call
, verbose
, remoteFile
);
153 error
= bulk_SendFile(fd
, call
, &status
);
154 /* If there were any output parameters, then it would be necessary to call EndBULKStoreFile(call, &out1,...) here to pick them up */
156 *length_ptr
= status
.st_size
;