reindent-20030715
[openafs.git] / src / rx / test / testserver.c
index 74665ca..cadc3d2 100644 (file)
@@ -12,7 +12,8 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID("$Header$");
+RCSID
+    ("$Header$");
 
 #include <sys/types.h>
 #include <stdio.h>
@@ -34,49 +35,57 @@ RCSID("$Header$");
 #include "rx_globals.h"
 #include "rx_null.h"
 
-int error;  /* Return this error number on a call */
+int error;                     /* Return this error number on a call */
 int print = 0, eventlog = 0, rxlog = 0;
 extern rx_intentionallyDroppedPacketsPer100;
 extern char rxi_tracename[];
 extern int rx_initSendWindow, rx_initReceiveWindow;
 extern int rxi_nSendFrags, rxi_nRecvFrags;
-extern int (*rxi_syscallp)();
+extern int (*rxi_syscallp) ();
 struct clock computeTime, waitTime;
 FILE *debugFile;
 char *rcvFile;
 int logstdout = 0;
 
-void intSignal(int ignore) {
+void
+intSignal(int ignore)
+{
     Quit("Interrupted");
 }
 
-void quitSignal(int ignore) {
+void
+quitSignal(int ignore)
+{
     static int quitCount = 0;
-    if (++quitCount > 1) Quit("rx_ctest: second quit signal, aborting");
+    if (++quitCount > 1)
+       Quit("rx_ctest: second quit signal, aborting");
     rx_debugFile = debugFile = fopen("rx_stest.db", "w");
-    if (debugFile) rx_PrintStats(debugFile);
+    if (debugFile)
+       rx_PrintStats(debugFile);
 }
 
 int SimpleRequest(), FileRequest();
 
 #if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV)
-int test_syscall(a3, a4, a5)
-afs_uint32 a3, a4;
-void * a5;
+int
+test_syscall(a3, a4, a5)
+     afs_uint32 a3, a4;
+     void *a5;
 {
-  afs_uint32 rcode;
-  void (*old)(int);
-       
-  old = signal(SIGSYS, SIG_IGN);       
-  rcode = syscall (31 /* AFS_SYSCALL */, 28 /* AFSCALL_CALL */, a3, a4, a5);
-  signal(SIGSYS, old); 
+    afs_uint32 rcode;
+    void (*old) (int);
+
+    old = signal(SIGSYS, SIG_IGN);
+    rcode =
+       syscall(31 /* AFS_SYSCALL */ , 28 /* AFSCALL_CALL */ , a3, a4, a5);
+    signal(SIGSYS, old);
 
-return rcode;
+    return rcode;
 }
 #endif
 
 main(argc, argv)
-char **argv;
+     char **argv;
 {
     struct rx_service *service;
     struct rx_securityClass *(secobjs[1]);
@@ -87,83 +96,102 @@ char **argv;
     setlinebuf(stdout);
     rxi_syscallp = test_syscall;
 #endif
-    argv++; argc--;
+    argv++;
+    argc--;
     while (argc && **argv == '-') {
-       if (strcmp(*argv, "-verbose") == 0) print = 1;
-       else if (strcmp(*argv, "-rxlog") == 0) rxlog = 1;
-       else if (strcmp(*argv, "-trace") == 0) strcpy(rxi_tracename, *(++argv)), argc--;
-       else if (strcmp(*argv, "-logstdout") == 0) logstdout = 1;
-       else if (strcmp(*argv, "-eventlog") == 0) eventlog = 1;
-       else if (strcmp(*argv, "-npb") == 0) rx_nPackets = atoi(*++argv), argc--;
-       else if (!strcmp(*argv, "-nsf")) 
-            rxi_nSendFrags =  atoi(*++argv), argc--;
-       else if (!strcmp(*argv, "-nrf")) 
-            rxi_nRecvFrags =  atoi(*++argv), argc--;
-       else if (strcmp(*argv, "-twind") == 0) 
-            rx_initSendWindow = atoi(*++argv), argc--;
-       else if (strcmp(*argv, "-rwind") == 0) 
-            rx_initReceiveWindow = atoi(*++argv), argc--;
-       else if (strcmp(*argv, "-file") == 0) rcvFile = *++argv, argc--;
-       else if (strcmp(*argv, "-drop") == 0) rx_intentionallyDroppedPacketsPer100 = atoi(*++argv), argc--;
-       else if (strcmp(*argv, "-err") == 0) error = atoi(*++argv), argc--;
+       if (strcmp(*argv, "-verbose") == 0)
+           print = 1;
+       else if (strcmp(*argv, "-rxlog") == 0)
+           rxlog = 1;
+       else if (strcmp(*argv, "-trace") == 0)
+           strcpy(rxi_tracename, *(++argv)), argc--;
+       else if (strcmp(*argv, "-logstdout") == 0)
+           logstdout = 1;
+       else if (strcmp(*argv, "-eventlog") == 0)
+           eventlog = 1;
+       else if (strcmp(*argv, "-npb") == 0)
+           rx_nPackets = atoi(*++argv), argc--;
+       else if (!strcmp(*argv, "-nsf"))
+           rxi_nSendFrags = atoi(*++argv), argc--;
+       else if (!strcmp(*argv, "-nrf"))
+           rxi_nRecvFrags = atoi(*++argv), argc--;
+       else if (strcmp(*argv, "-twind") == 0)
+           rx_initSendWindow = atoi(*++argv), argc--;
+       else if (strcmp(*argv, "-rwind") == 0)
+           rx_initReceiveWindow = atoi(*++argv), argc--;
+       else if (strcmp(*argv, "-file") == 0)
+           rcvFile = *++argv, argc--;
+       else if (strcmp(*argv, "-drop") == 0)
+           rx_intentionallyDroppedPacketsPer100 = atoi(*++argv), argc--;
+       else if (strcmp(*argv, "-err") == 0)
+           error = atoi(*++argv), argc--;
        else if (strcmp(*argv, "-compute") == 0) {
            /* Simulated "compute" time for each call--to test acknowledgement protocol.  This is simulated by doing an iomgr_select:  imperfect, admittedly. */
            computeTime.sec = atoi(*++argv), argc--;
            computeTime.usec = atoi(*++argv), argc--;
-       }
-       else if (strcmp(*argv, "-wait") == 0) {
+       } else if (strcmp(*argv, "-wait") == 0) {
            /* Wait time between calls--to test lastack code */
            waitTime.sec = atoi(*++argv), argc--;
            waitTime.usec = atoi(*++argv), argc--;
-       }
-       else if (strcmp(*argv, "-fd") == 0) {
+       } else if (strcmp(*argv, "-fd") == 0) {
            /* Open at least this many fd's. */
            setFD = atoi(*++argv), argc--;
+       } else {
+           err++;
+           break;
        }
-       else {err++; break;}
        argv++, argc--;
     }
     if (err || argc != 0)
        Quit("usage: rx_stest [-silent] [-rxlog] [-eventlog]");
 
     if (rxlog || eventlog) {
-       if (logstdout) debugFile = stdout;
-       else debugFile = fopen("rx_stest.db", "w");
-       if (debugFile == NULL) Quit("Couldn't open rx_stest.db");
-       if (rxlog) rx_debugFile = debugFile;
-       if (eventlog) rxevent_debugFile = debugFile;
+       if (logstdout)
+           debugFile = stdout;
+       else
+           debugFile = fopen("rx_stest.db", "w");
+       if (debugFile == NULL)
+           Quit("Couldn't open rx_stest.db");
+       if (rxlog)
+           rx_debugFile = debugFile;
+       if (eventlog)
+           rxevent_debugFile = debugFile;
     }
 
-    signal(SIGINT, intSignal); /* Changed to SIGQUIT since dbx is broken right now */
+    signal(SIGINT, intSignal); /* Changed to SIGQUIT since dbx is broken right now */
 #ifndef AFS_NT40_ENV
     signal(SIGQUIT, quitSignal);
 #endif
 
-    if (setFD>0)
+    if (setFD > 0)
        OpenFD(setFD);
-    if (rx_Init(htons(2500)) != 0 ) {
+    if (rx_Init(htons(2500)) != 0) {
        printf("RX initialization failed, exiting.\n");
        exit(1);
     }
-    if (setFD>0) {
+    if (setFD > 0) {
        printf("rx_socket=%d\n", rx_socket);
     }
 
     secobjs[0] = rxnull_NewServerSecurityObject();
-    service = rx_NewService(/*port*/0, /*service*/3, "test", secobjs, /*nsec*/1, /*Execute request*/ rcvFile? FileRequest: SimpleRequest);
-    if (!service) Abort("rx_NewService returned 0!\n");
+    service = rx_NewService( /*port */ 0, /*service */ 3, "test", secobjs,     /*nsec */
+                           1,  /*Execute request */
+                           rcvFile ? FileRequest : SimpleRequest);
+    if (!service)
+       Abort("rx_NewService returned 0!\n");
     printf("Using %d packet buffers\n", rx_nPackets);
     rx_StartServer(1);
 }
 
 SimpleRequest(call)
-    struct rx_call *call;
+     struct rx_call *call;
 {
     int n;
     int nbytes = 1000;
     char buf[1000];
     while ((n = rx_Read(call, buf, nbytes)) > 0)
-       if (print) printf("stest: Received %d bytes\n", n);
+       if (print)
+           printf("stest: Received %d bytes\n", n);
     if (!rx_Error(call)) {
        /* Fake compute time (use select to lock out everything) */
        struct timeval t;
@@ -173,7 +201,8 @@ SimpleRequest(call)
 #ifdef AFS_NT40_ENV
            Sleep(t.tv_sec);
 #else
-           if (select(0, 0, 0, 0, &t) != 0) Quit("Select didn't return 0");
+           if (select(0, 0, 0, 0, &t) != 0)
+               Quit("Select didn't return 0");
 #endif
        }
        /* Then wait time (use iomgr_select to allow rx to run) */
@@ -186,15 +215,17 @@ SimpleRequest(call)
            IOMGR_Sleep(t.tv_sec);
 #endif
        }
-       rx_Write(call, "So long, and thanks for all the fish!\n", strlen("So long, and thanks for all the fish!\n"));
+       rx_Write(call, "So long, and thanks for all the fish!\n",
+                strlen("So long, and thanks for all the fish!\n"));
     }
-    if (debugFile) rx_PrintPeerStats(debugFile, rx_PeerOf(call->conn));
+    if (debugFile)
+       rx_PrintPeerStats(debugFile, rx_PeerOf(call->conn));
     rx_PrintPeerStats(stdout, rx_PeerOf(call->conn));
     return 0;
 }
 
 FileRequest(call)
-struct rx_call *call;
+     struct rx_call *call;
 {
     int fd;
     struct stat status;
@@ -205,8 +236,11 @@ struct rx_call *call;
     struct statfs tstatfs;
 #endif
     /* Open the file ahead of time:  the client timing the operation doesn't have to include the open time */
-    fd = open(rcvFile, O_WRONLY|O_CREAT|O_TRUNC, 0666);
-    if (fd < 0) {perror("open"); return;}
+    fd = open(rcvFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+    if (fd < 0) {
+       perror("open");
+       return;
+    }
     fstat(fd, &status);
 #ifdef AFS_NT40_ENV
     blockSize = 1024;
@@ -218,10 +252,10 @@ struct rx_call *call;
     blockSize = status.st_blksize;
 #endif
 #endif /* AFS_NT40_ENV */
-    buffer = (char *) malloc(blockSize);
+    buffer = (char *)malloc(blockSize);
+
+    rx_SetLocalStatus(call, 79);       /* Emulation of file server's old "RCallBackReceivedStore" */
 
-    rx_SetLocalStatus(call, 79);   /* Emulation of file server's old "RCallBackReceivedStore" */
-    
     while (nbytes = rx_Read(call, buffer, blockSize)) {
        if (write(fd, buffer, nbytes) != nbytes) {
            perror("writev");
@@ -229,16 +263,19 @@ struct rx_call *call;
            break;
        }
     }
-    rx_Write(call, "So long, and thanks for all the fish!\n", strlen("So long, and thanks for all the fish!\n"));
+    rx_Write(call, "So long, and thanks for all the fish!\n",
+            strlen("So long, and thanks for all the fish!\n"));
     printf("Received file %s\n", rcvFile);
     close(fd);
-    if (debugFile) rx_PrintPeerStats(debugFile, rx_PeerOf(call->conn));
+    if (debugFile)
+       rx_PrintPeerStats(debugFile, rx_PeerOf(call->conn));
     rx_PrintPeerStats(stdout, rx_PeerOf(call->conn));
     return 0;
 }
 
-Abort(msg, a,b,c,d,e) {
-    printf((char *) msg, a, b, c, d, e);
+Abort(msg, a, b, c, d, e)
+{
+    printf((char *)msg, a, b, c, d, e);
     printf("\n");
     if (debugFile) {
        rx_PrintStats(debugFile);
@@ -247,8 +284,9 @@ Abort(msg, a,b,c,d,e) {
     abort();
 }
 
-Quit(msg, a,b,c,d,e) {
-    printf((char *) msg, a,b,c,d,e);
+Quit(msg, a, b, c, d, e)
+{
+    printf((char *)msg, a, b, c, d, e);
     printf("\n");
     if (debugFile) {
        rx_PrintStats(debugFile);
@@ -265,28 +303,26 @@ Quit(msg, a,b,c,d,e) {
  */
 #include <sys/stat.h>
 OpenFD(n)
-int n;
+     int n;
 {
     int i;
     struct stat sbuf;
     int fd, lfd;
 
     lfd = -1;
-    for (i=0; i<n; i++) {
+    for (i = 0; i < n; i++) {
        if (fstat(i, &sbuf) == 0)
            continue;
        if ((fd = open("/dev/null", 0, 0)) < 0) {
-           if (lfd >=0) {
+           if (lfd >= 0) {
                close(lfd);
                return;
            }
-       }
-       else {
+       } else {
            if (fd >= n) {
                close(fd);
                return;
-           }
-           else {
+           } else {
                lfd = fd;
            }
        }