From: Matthew N. Andrews Date: Wed, 14 May 2003 15:30:51 +0000 (+0000) Subject: rx-bulk-example-cleanup-20030513 X-Git-Tag: openafs-devel-1_3_50~232 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=d9eab68f86dd90cd4cfee623eaca35cd9248b864 rx-bulk-example-cleanup-20030513 FIXES 1436 make the bulk example work --- diff --git a/src/rx/bulk.example/Makefile.in b/src/rx/bulk.example/Makefile.in index 7c690d5..6f093b2 100644 --- a/src/rx/bulk.example/Makefile.in +++ b/src/rx/bulk.example/Makefile.in @@ -9,12 +9,11 @@ srcdir=@srcdir@ include @TOP_OBJDIR@/src/config/Makefile.config -SRCDIR=/usr/andy/ -LIBRX=${SRCDIR}/lib/librx.a -DESTDIR=/usr/andy/ -INSTALL=${SRCDIR}/bin/install -LIBS=${LIBRX} ${SRCDIR}/lib/liblwp.a -CFLAGS=-g -I.. -I. -I${SRCDIR}/include -DDEBUG ${XCFLAGS} +SRCDIR=@srcdir@ +LIBRX=@TOP_OBJDIR@/lib/librx.a +DESTDIR=@srcdir@ +LIBS=${LIBRX} ${TOP_OBJDIR}/lib/liblwp.a ${TOP_OBJDIR}/lib/libafsutil.a +CFLAGS=-g ${COMMON_INCL} -DDEBUG ${XCFLAGS} all: bulk_client bulk_server @@ -27,4 +26,7 @@ bulk_server: bulk_server.o bulk_io.o bulk.ss.o ${LIBS} bulk_client.o bulk_server.o bulk_io.o: bulk.h bulk.cs.c bulk.ss.c bulk.er.c bulk.h: bulk.xg - rxgen bulk.xg + ${RXGEN} bulk.xg + +clean: + rm -f *.o bulk.cs.c bulk.ss.c bulk.xdr.c bulk.h bulk_client bulk_server *~ diff --git a/src/rx/bulk.example/bulk.xg b/src/rx/bulk.example/bulk.xg index 2163875..59ee80c 100644 --- a/src/rx/bulk.example/bulk.xg +++ b/src/rx/bulk.example/bulk.xg @@ -9,24 +9,25 @@ package BULK_ -#include -#include +%#include +%#include -#define BULK_SERVER_PORT htonl(5000) -#define BULK_SERVICE_PORT htonl(0) /* i.e. user server's port */ -#define BULK_SERVICE_ID 4 +%#define BULK_SERVER_PORT 5000 +%#define BULK_SERVICE_PORT 0 /* i.e. user server's port */ +%#define BULK_SERVICE_ID 4 /* Maximum number of requests that will be handled by this service simultaneously */ /* This number will also be guaranteed to execute in parallel if no services' requests are being processed */ -#define BULK_MAX 2 +%#define BULK_MAX 2 /* Minimum number of requests that are guaranteed to be handled immediately */ -#define BULK_MIN 1 +%#define BULK_MIN 1 +%#define BULK_NAME_MAX 1024 /* Index of the "null" security class in the BULK service. This must be 0 (there are N classes, numbered from 0. In this case, N is 1) */ -#define BULK_NULL 0 +%#define BULK_NULL 0 -#define BULK_ERROR 1 /* Error used to abort a bulk transfer */ +%#define BULK_ERROR 1 /* Error used to abort a bulk transfer */ -FetchFile(IN int verbose, string name) split = 1; -StoreFile(IN int verbose, string name) split = 2; +FetchFile(IN int verbose, string name) split = 1; +StoreFile(IN int verbose, string name) split = 2; diff --git a/src/rx/bulk.example/bulk_client.c b/src/rx/bulk.example/bulk_client.c index a4f743e..b600e98 100644 --- a/src/rx/bulk.example/bulk_client.c +++ b/src/rx/bulk.example/bulk_client.c @@ -12,7 +12,8 @@ #include #include -RCSID("$Header$"); +RCSID + ("$Header$"); #include #include @@ -24,13 +25,16 @@ RCSID("$Header$"); #include "bulk.h" /* Bogus procedure to get internet address of host */ -static u_long GetIpAddress(hostname) - char *hostname; +static u_long +GetIpAddress(char *hostname) { struct hostent *hostent; u_long host; hostent = gethostbyname(hostname); - if (!hostent) {printf("host %s not found", hostname);exit(1);} + if (!hostent) { + printf("host %s not found", hostname); + exit(1); + } if (hostent->h_length != sizeof(u_long)) { printf("host address is disagreeable length (%d)", hostent->h_length); exit(1); @@ -39,11 +43,14 @@ static u_long GetIpAddress(hostname) return host; } -long FetchFile(), StoreFile(); +long FetchFile(struct rx_call *call, int verbose, + char *localFile, char *remoteFile, long *length_ptr); +long StoreFile(struct rx_call *call, int verbose, + char *localFile, char *remoteFile, long *length_ptr); + -main(argc, argv) - int argc; - char **argv; +int +main(int argc, char **argv) { char *localFile, *remoteFile; u_long host; @@ -56,19 +63,25 @@ main(argc, argv) int error = 0; long msec; - argc--; argv++; + argc--; + argv++; while (**argv == '-') { - if (strcmp(*argv, "-fetch") == 0) fetch = 1; - else if (strcmp(*argv, "-store") == 0) store = 1; - else if (strcmp(*argv, "-verbose") == 0) verbose = 1; + if (strcmp(*argv, "-fetch") == 0) + fetch = 1; + else if (strcmp(*argv, "-store") == 0) + store = 1; + else if (strcmp(*argv, "-verbose") == 0) + verbose = 1; else { fprintf(stderr, "Unknown option %s\n", *argv); exit(1); } - argc--; argv++; + argc--; + argv++; } - if (argc != 3 || !(fetch^store)) { - fprintf(stderr, "bulk_client -fetch/-store localFile host remoteFile\n"); + if (argc != 3 || !(fetch ^ store)) { + fprintf(stderr, + "bulk_client -fetch/-store localFile host remoteFile\n"); exit(1); } localFile = argv[0]; @@ -77,66 +90,71 @@ main(argc, argv) rx_Init(0); null_securityObject = rxnull_NewClientSecurityObject(); - conn = rx_NewConnection(host, BULK_SERVER_PORT, BULK_SERVICE_ID, null_securityObject, BULK_NULL); + conn = + rx_NewConnection(host, BULK_SERVER_PORT, BULK_SERVICE_ID, + null_securityObject, BULK_NULL); clock_NewTime(); clock_GetTime(&startTime); call = rx_NewCall(conn); - (fetch? FetchFile:StoreFile)(call, verbose, localFile, remoteFile, &length); + (fetch ? FetchFile : StoreFile) (call, verbose, localFile, remoteFile, + &length); error = rx_EndCall(call, error); clock_NewTime(); clock_GetTime(&endTime); msec = clock_ElapsedTime(&startTime, &endTime); - if (!error) printf("Transferred %d bytes in %d msec, %d bps\n", length, msec, length*1000/msec); - else printf("transfer failed: error %d\n", error); + if (!error) + printf("Transferred %d bytes in %d msec, %d bps\n", length, msec, + length * 1000 / msec); + else + printf("transfer failed: error %d\n", error); /* Allow Rx to idle down any calls; it's a good idea, but not essential, to call this routine */ rx_Finalize(); } -long FetchFile(call, verbose, localFile, remoteFile, length_ptr) - struct rx_call *call; - int verbose; - char *localFile, *remoteFile; - long *length_ptr; +long +FetchFile(struct rx_call *call, int verbose, + char *localFile, char *remoteFile, long *length_ptr) { int fd = -1, error = 0; struct stat status; - if (StartBULK_FetchFile(call, verbose, remoteFile)) return BULK_ERROR; - fd = open(localFile, O_CREAT|O_TRUNC|O_WRONLY, 0666); + if (StartBULK_FetchFile(call, verbose, remoteFile)) + return BULK_ERROR; + fd = open(localFile, O_CREAT | O_TRUNC | O_WRONLY, 0666); if (fd < 0 || fstat(fd, &status) < 0) { - fprintf("Could not create %s\n", localFile); + fprintf(stderr, "Could not create %s\n", localFile); error = BULK_ERROR; } - if (bulk_ReceiveFile(fd, call, &status)) error = BULK_ERROR; + if (bulk_ReceiveFile(fd, call, &status)) + error = BULK_ERROR; *length_ptr = status.st_size; - if (fd >= 0) close(fd); + if (fd >= 0) + close(fd); /* If there were any output parameters, then it would be necessary to call EndBULKFetchFile(call, &out1,...) here to pick them up */ return error; } -long StoreFile(call, verbose, localFile, remoteFile, length_ptr) - struct rx_call *call; - int verbose; - char *localFile, *remoteFile; - long *length_ptr; +long +StoreFile(struct rx_call *call, int verbose, + char *localFile, char *remoteFile, long *length_ptr) { int fd = -1, error = 0; struct stat status; fd = open(localFile, O_RDONLY, 0); if (fd < 0 || fstat(fd, &status) < 0) { - fprintf("Could not open %s\n", localFile); + fprintf(stderr, "Could not open %s\n", localFile); return BULK_ERROR; } error = StartBULK_StoreFile(call, verbose, remoteFile); - if (!error) error = bulk_SendFile(fd, call, &status); + if (!error) + error = bulk_SendFile(fd, call, &status); /* If there were any output parameters, then it would be necessary to call EndBULKStoreFile(call, &out1,...) here to pick them up */ close(fd); *length_ptr = status.st_size; return error; } - diff --git a/src/rx/bulk.example/bulk_io.c b/src/rx/bulk.example/bulk_io.c index 329adb1..b749b19 100644 --- a/src/rx/bulk.example/bulk_io.c +++ b/src/rx/bulk.example/bulk_io.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header$"); +RCSID + ("$Header$"); #include #include @@ -19,12 +20,11 @@ RCSID("$Header$"); #include #include "bulk.h" -int bulk_SendFile(fd, call, status) -register int fd; -register struct rx_call *call; -register struct stat *status; +int +bulk_SendFile(register int fd, + register struct rx_call *call, register struct stat *status) { - char *buffer = (char*) 0; + char *buffer = (char *)0; int blockSize; long length; XDR xdr; @@ -37,9 +37,10 @@ register struct stat *status; return BULK_ERROR; } xdrrx_create(&xdr, call, XDR_ENCODE); - if (!xdr_long(&xdr, &length)) error = BULK_ERROR; + if (!xdr_long(&xdr, &length)) + error = BULK_ERROR; while (!error && length) { - register nbytes = (length>blockSize?blockSize:length); + register nbytes = (length > blockSize ? blockSize : length); nbytes = read(fd, buffer, nbytes); if (nbytes <= 0) { fprintf(stderr, "File system read failed\n"); @@ -49,42 +50,47 @@ register struct stat *status; break; length -= nbytes; } - if (buffer) free(buffer); - if (length) error = BULK_ERROR; + if (buffer) + free(buffer); + if (length) + error = BULK_ERROR; return error; } /* Copy the appropriate number of bytes from the call to fd. The status should reflect the file's status coming into the routine and will reflect it going out of the routine, in the absence of errors */ -int bulk_ReceiveFile(fd, call, status) - register int fd; - register struct rx_call *call; - register struct stat *status; +int +bulk_ReceiveFile(register int fd, + register struct rx_call *call, register struct stat *status) { - register char *buffer = (char*) 0; + register char *buffer = (char *)0; long length; XDR xdr; register int blockSize; long error = 0; xdrrx_create(&xdr, call, XDR_DECODE); - if (!xdr_long(&xdr, &length)) return BULK_ERROR; + if (!xdr_long(&xdr, &length)) + return BULK_ERROR; blockSize = status->st_blksize; buffer = (char *)malloc(status->st_blksize); if (!buffer) { - printf("malloc failed\n"); + fprintf(stderr, "malloc failed\n"); return BULK_ERROR; } while (!error && length) { - register nbytes = (length>blockSize?blockSize:length); + register nbytes = (length > blockSize ? blockSize : length); nbytes = rx_Read(call, buffer, nbytes); - if (!nbytes) error = BULK_ERROR; + if (!nbytes) + error = BULK_ERROR; if (write(fd, buffer, nbytes) != nbytes) { - fprintf("File system write failed!\n"); + fprintf(stderr, "File system write failed!\n"); error = BULK_ERROR; } length -= nbytes; } - if (buffer) free(buffer); - if (!error) fstat(fd, status); + if (buffer) + free(buffer); + if (!error) + fstat(fd, status); return error; } diff --git a/src/rx/bulk.example/bulk_server.c b/src/rx/bulk.example/bulk_server.c index cdbea8f..d39ed01 100644 --- a/src/rx/bulk.example/bulk_server.c +++ b/src/rx/bulk.example/bulk_server.c @@ -10,7 +10,8 @@ #include #include -RCSID("$Header$"); +RCSID + ("$Header$"); #include #include @@ -23,69 +24,80 @@ RCSID("$Header$"); #define N_SECURITY_OBJECTS 1 -extern BULK__ExecuteRequest(); +extern int BULK_ExecuteRequest(register struct rx_call *z_call); +void Quit(char *msg); -main() { +int +main(int argc, char **argv) +{ struct rx_securityClass *(securityObjects[N_SECURITY_OBJECTS]); struct rx_service *service; /* Initialize Rx, telling it port number this server will use for its single service */ - if (rx_Init(BULK_SERVER_PORT) < 0) Quit("rx_init"); + if (rx_Init(BULK_SERVER_PORT) < 0) + Quit("rx_init"); /* 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 */ securityObjects[BULK_NULL] = rxnull_NewServerSecurityObject(); - if (securityObjects[BULK_NULL] == (struct rx_securityClass *) 0) Quit("rxnull_NewServerSecurityObject"); + if (securityObjects[BULK_NULL] == (struct rx_securityClass *)0) + Quit("rxnull_NewServerSecurityObject"); /* Instantiate a single BULK service. The rxgen-generated procedure which is called to decode requests is passed in here (BULK_ExecuteRequest). */ - service = rx_NewService(0, BULK_SERVICE_ID, "BULK", securityObjects, N_SECURITY_OBJECTS, BULK__ExecuteRequest); - if (service == (struct rx_service *) 0) Quit("rx_NewService"); + service = + rx_NewService(0, BULK_SERVICE_ID, "BULK", securityObjects, + N_SECURITY_OBJECTS, BULK_ExecuteRequest); + if (service == (struct rx_service *)0) + Quit("rx_NewService"); rx_SetMaxProcs(service, 2); - rx_StartServer(1); /* Donate this process to the server process pool */ + rx_StartServer(1); /* Donate this process to the server process pool */ Quit("StartServer returned?"); } -int BULK_FetchFile(call, verbose, name) - struct rx_call *call; - char *name; +int +BULK_FetchFile(struct rx_call *call, int verbose, char *name) { int fd = -1; int error = 0; struct stat status; - if (verbose) printf("Fetch file %s\n", name); + if (verbose) + printf("Fetch file %s\n", name); fd = open(name, O_RDONLY, 0); if (fd < 0 || fstat(fd, &status) < 0) { - if (verbose) printf("Failed to open %s\n", name); + if (verbose) + printf("Failed to open %s\n", name); error = BULK_ERROR; } - if (!error) error = bulk_SendFile(fd, call, &status); - if (fd >= 0) close(fd); + if (!error) + error = bulk_SendFile(fd, call, &status); + if (fd >= 0) + close(fd); return error; } -int BULK_StoreFile(call, verbose, name) - struct rx_call *call; - int verbose; - char *name; +int +BULK_StoreFile(struct rx_call *call, int verbose, char *name) { int fd = -1; struct stat status; int error = 0; - if (verbose) printf("Store file %s\n", name); - fd = open(name, O_CREAT|O_TRUNC|O_WRONLY, 0666); + if (verbose) + printf("Store file %s\n", name); + fd = open(name, O_CREAT | O_TRUNC | O_WRONLY, 0666); if (fd < 0 || fstat(fd, &status) < 0) { - fprintf("Could not create %s\n", name); + fprintf(stderr, "Could not create %s\n", name); error = BULK_ERROR; } - if (!error) error = bulk_ReceiveFile(fd, call, &status); - if (fd >= 0) close(fd); + if (!error) + error = bulk_ReceiveFile(fd, call, &status); + if (fd >= 0) + close(fd); return error; } -Quit(msg, a, b) - char *msg; +void +Quit(char *msg) { - fprintf(stderr, msg, a, b); + fprintf(stderr, msg); exit(1); } -