DEVEL15-kill-ubik-pthread-env-20080718
[openafs.git] / src / ubik / utst_server.c
index 8f02488..f58f449 100644 (file)
@@ -7,10 +7,11 @@
  * directory or online at http://www.openafs.org/dl/license10.html
  */
 
-#include <afs/param.h>
 #include <afsconfig.h>
+#include <afs/param.h>
 
-RCSID("$Header$");
+RCSID
+    ("$Header$");
 
 #include <afs/stds.h>
 #include <sys/types.h>
@@ -24,6 +25,7 @@ RCSID("$Header$");
 #endif
 #include <time.h>
 #include <stdio.h>
+#include <string.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <lock.h>
@@ -35,11 +37,11 @@ RCSID("$Header$");
 struct ubik_dbase *dbase;
 afs_int32 sleepTime;
 
-SAMPLE_Inc(rxcall)
-struct rx_call *rxcall;
+SAMPLE_Inc(rxconn)
+     struct rx_connection *rxconn;
 {
     afs_int32 code, temp;
-    struct ubik_trans  *tt;
+    struct ubik_trans *tt;
     struct timeval tv;
 
     code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
@@ -47,8 +49,8 @@ struct rx_call        *rxcall;
        return code;
     printf("about to set lock\n");
     /* now set database locks.  Must do this or people may read uncommitted
-         data.  Note that we're just setting a lock at position 1, which is
-this program's convention for locking the whole database */
+     * data.  Note that we're just setting a lock at position 1, which is
+     * this program's convention for locking the whole database */
     code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
     printf("now have lock\n");
     if (code) {
@@ -56,23 +58,26 @@ this program's convention for locking the whole database */
        return code;
     }
     /* sleep for a little while to make it possible for us to test for some
-       race conditions */
+     * race conditions */
     if (sleepTime) {
        tv.tv_sec = sleepTime;
        tv.tv_usec = 0;
+#ifdef AFS_PTHREAD_ENV
+       select(0, 0, 0, 0, &tv);
+#else
        IOMGR_Select(0, 0, 0, 0, &tv);
+#endif
     }
     /* read the original value */
     code = ubik_Read(tt, &temp, sizeof(afs_int32));
     if (code == UEOF) {
        /* short read */
        temp = 0;
-    }
-    else if (code) {
+    } else if (code) {
        ubik_AbortTrans(tt);
        return code;
     }
-    temp++; /* bump the value here */
+    temp++;                    /* bump the value here */
     /* reset the file pointer back to where it was before the read */
     code = ubik_Seek(tt, 0, 0);
     if (code) {
@@ -92,16 +97,16 @@ this program's convention for locking the whole database */
 }
 
 
-SAMPLE_Get(rxcall, gnumber)
-struct rx_call *rxcall;
-afs_int32 *gnumber;
+SAMPLE_Get(rxconn, gnumber)
+     struct rx_connection *rxconn;
+     afs_int32 *gnumber;
 {
     afs_int32 code, temp;
-    struct ubik_trans  *tt;
+    struct ubik_trans *tt;
     struct timeval tv;
 
     /* start with a read transaction, since we're only going to do read
-         operations in this transaction. */
+     * operations in this transaction. */
     code = ubik_BeginTrans(dbase, UBIK_READTRANS, &tt);
     if (code)
        return code;
@@ -117,15 +122,18 @@ afs_int32 *gnumber;
     if (sleepTime) {
        tv.tv_sec = sleepTime;
        tv.tv_usec = 0;
+#ifdef AFS_PTHREAD_ENV
+       select(0, 0, 0, 0, &tv);
+#else
        IOMGR_Select(0, 0, 0, 0, &tv);
+#endif
     }
     /* read the value */
     code = ubik_Read(tt, &temp, sizeof(afs_int32));
     if (code == UEOF) {
        /* premature eof, use 0 */
        temp = 0;
-    }
-    else if (code) {
+    } else if (code) {
        ubik_AbortTrans(tt);
        return code;
     }
@@ -136,16 +144,16 @@ afs_int32 *gnumber;
 }
 
 
-SAMPLE_QGet(rxcall, gnumber)
-struct rx_call *rxcall;
-afs_int32 *gnumber;
+SAMPLE_QGet(rxconn, gnumber)
+     struct rx_connection *rxconn;
+     afs_int32 *gnumber;
 {
     afs_int32 code, temp;
-    struct ubik_trans  *tt;
+    struct ubik_trans *tt;
     struct timeval tv;
 
     /* start with a read transaction, since we're only going to do read
-         operations in this transaction. */
+     * operations in this transaction. */
     code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
     if (code)
        return code;
@@ -161,15 +169,18 @@ afs_int32 *gnumber;
     if (sleepTime) {
        tv.tv_sec = sleepTime;
        tv.tv_usec = 0;
+#ifdef AFS_PTHREAD_ENV
+       select(0, 0, 0, 0, &tv);
+#else
        IOMGR_Select(0, 0, 0, 0, &tv);
+#endif
     }
     /* read the value */
     code = ubik_Read(tt, &temp, sizeof(afs_int32));
     if (code == UEOF) {
        /* premature eof, use 0 */
        temp = 0;
-    }
-    else if (code) {
+    } else if (code) {
        ubik_AbortTrans(tt);
        return code;
     }
@@ -180,16 +191,17 @@ afs_int32 *gnumber;
 }
 
 
-SAMPLE_Trun(rxcall)
-struct rx_call *rxcall;
+SAMPLE_Trun(rxconn)
+     struct rx_connection *rxconn;
 {
     afs_int32 code;
-    struct ubik_trans  *tt;
+    struct ubik_trans *tt;
     struct timeval tv;
 
     /* truncation operation requires a write transaction, too */
     code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
-    if (code) return code;
+    if (code)
+       return code;
     printf("about to set lock\n");
     /* lock the database */
     code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
@@ -201,7 +213,11 @@ struct rx_call     *rxcall;
     if (sleepTime) {
        tv.tv_sec = sleepTime;
        tv.tv_usec = 0;
+#ifdef AFS_PTHREAD_ENV
+       select(0, 0, 0, 0, &tv);
+#else
        IOMGR_Select(0, 0, 0, 0, &tv);
+#endif
     }
     /* shrink the file */
     code = ubik_Truncate(tt, 0);
@@ -215,21 +231,22 @@ struct rx_call    *rxcall;
 }
 
 
-SAMPLE_Test(rxcall)
-struct rx_call *rxcall;
+SAMPLE_Test(rxconn)
+     struct rx_connection *rxconn;
 {
     afs_int32 code, temp;
-    struct ubik_trans  *tt;
+    struct ubik_trans *tt;
     struct timeval tv;
 
     /* first start a new transaction.  Must be a write transaction since
-      we're going to change some data (with ubik_Write) */
+     * we're going to change some data (with ubik_Write) */
     code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
-    if (code) return code;
+    if (code)
+       return code;
     printf("about to set lock\n");
     /* now set database locks.  Must do this or people may read uncommitted
-         data.  Note that we're just setting a lock at position 1, which is
-      this program's convention for locking the whole database */
+     * data.  Note that we're just setting a lock at position 1, which is
+     * this program's convention for locking the whole database */
     code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
     printf("now have lock\n");
     if (code) {
@@ -237,23 +254,26 @@ struct rx_call    *rxcall;
        return code;
     }
     /* sleep for a little while to make it possible for us to test for some
-       race conditions */
+     * race conditions */
     if (sleepTime) {
        tv.tv_sec = sleepTime;
        tv.tv_usec = 0;
+#ifdef AFS_PTHREAD_ENV
+       select(0, 0, 0, 0, &tv);
+#else
        IOMGR_Select(0, 0, 0, 0, &tv);
+#endif
     }
     /* read the original value */
     code = ubik_Read(tt, &temp, sizeof(afs_int32));
     if (code == UEOF) {
        printf("short read, using 0\n");
        temp = 0;
-    }
-    else if (code) {
+    } else if (code) {
        ubik_AbortTrans(tt);
        return code;
     }
-    ubik_AbortTrans(tt);    /* surprise! pretend something went wrong */
+    ubik_AbortTrans(tt);       /* surprise! pretend something went wrong */
     return code;
 }
 
@@ -261,41 +281,40 @@ struct rx_call    *rxcall;
 #include "AFS_component_version_number.c"
 
 main(argc, argv)
-    int argc;
-    char **argv; {
+     int argc;
+     char **argv;
+{
     register afs_int32 code, i;
     afs_int32 serverList[MAXSERVERS];
     afs_int32 myHost;
-    struct rx_service      *tservice;
+    struct rx_service *tservice;
     struct rx_securityClass *sc[2];
-    extern struct rx_securityClass *rxnull_NewServerSecurityObject();
-    extern struct rx_securityClass *rxvab_NewServerSecurityObject();
-    extern int             SAMPLE_ExecuteRequest();
+    extern int SAMPLE_ExecuteRequest();
     char dbfileName[128];
 
     if (argc == 1) {
        printf("usage: userver -servers <serverlist> {-sleep <sleeptime>}\n");
        exit(0);
     }
-#ifdef AFS_NT40_ENV 
+#ifdef AFS_NT40_ENV
     /* initialize winsock */
-     if (afs_winsockInit()<0) 
+    if (afs_winsockInit() < 0)
        return -1;
 #endif
     /* parse our own local arguments */
     sleepTime = 0;
-    for(i=1;i<argc;i++) {
-       if (strcmp(argv[i], "-sleep")==0) {
-           if (i >= argc-1) {
+    for (i = 1; i < argc; i++) {
+       if (strcmp(argv[i], "-sleep") == 0) {
+           if (i >= argc - 1) {
                printf("missing time in -sleep argument\n");
                exit(1);
            }
-           sleepTime = atoi(argv[i+1]);
+           sleepTime = atoi(argv[i + 1]);
            i++;
        }
     }
     /* call routine to parse command line -servers switch, filling in
-       myHost and serverList arrays appropriately */
+     * myHost and serverList arrays appropriately */
     code = ubik_ParseServerList(argc, argv, &myHost, serverList);
     if (code) {
        printf("could not parse server list, code %d\n", code);
@@ -308,9 +327,9 @@ main(argc, argv)
 
     sprintf(dbfileName, "%s/testdb", gettmpdir());
 
-    code = ubik_ServerInit (myHost, htons(3000), serverList, dbfileName,
-                           &dbase);
-    
+    code =
+       ubik_ServerInit(myHost, htons(3000), serverList, dbfileName, &dbase);
+
     if (code) {
        printf("ubik init failed with code %d\n", code);
        return;
@@ -320,7 +339,7 @@ main(argc, argv)
 #if 0
     sc[1] = rxvab_NewServerSecurityObject("applexx", 0);
 #endif
-    tservice = rx_NewService(0, USER_SERVICE_ID, "Sample", sc, 1/*2*/,
+    tservice = rx_NewService(0, USER_SERVICE_ID, "Sample", sc, 1 /*2 */ ,
                             SAMPLE_ExecuteRequest);
     if (tservice == (struct rx_service *)0) {
        printf("Could not create SAMPLE rx service\n");
@@ -329,5 +348,5 @@ main(argc, argv)
     rx_SetMinProcs(tservice, 2);
     rx_SetMaxProcs(tservice, 3);
 
-    rx_StartServer(1);             /* Why waste this idle process?? */
+    rx_StartServer(1);         /* Why waste this idle process?? */
 }