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 #include <afs/param.h>
12 #include <sys/types.h>
19 #include <netinet/in.h>
31 struct ubik_dbase *dbase;
35 struct rx_call *rxcall;
38 struct ubik_trans *tt;
41 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
44 printf("about to set lock\n");
45 /* now set database locks. Must do this or people may read uncommitted
46 data. Note that we're just setting a lock at position 1, which is
47 this program's convention for locking the whole database */
48 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
49 printf("now have lock\n");
54 /* sleep for a little while to make it possible for us to test for some
57 tv.tv_sec = sleepTime;
59 IOMGR_Select(0, 0, 0, 0, &tv);
61 /* read the original value */
62 code = ubik_Read(tt, &temp, sizeof(afs_int32));
71 temp++; /* bump the value here */
72 /* reset the file pointer back to where it was before the read */
73 code = ubik_Seek(tt, 0, 0);
78 /* write the data back */
79 code = ubik_Write(tt, &temp, sizeof(afs_int32));
84 /* finally, we commit the transaction */
85 code = ubik_EndTrans(tt);
91 SAMPLE_Get(rxcall, gnumber)
92 struct rx_call *rxcall;
96 struct ubik_trans *tt;
99 /* start with a read transaction, since we're only going to do read
100 operations in this transaction. */
101 code = ubik_BeginTrans(dbase, UBIK_READTRANS, &tt);
104 printf("about to set lock\n");
105 /* obtain a read lock, so we don't read data the other guy is writing */
106 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
107 printf("now have lock\n");
112 /* sleep to allow races */
114 tv.tv_sec = sleepTime;
116 IOMGR_Select(0, 0, 0, 0, &tv);
119 code = ubik_Read(tt, &temp, sizeof(afs_int32));
121 /* premature eof, use 0 */
129 /* end the transaction, automatically releasing locks */
130 code = ubik_EndTrans(tt);
135 SAMPLE_QGet(rxcall, gnumber)
136 struct rx_call *rxcall;
139 afs_int32 code, temp;
140 struct ubik_trans *tt;
143 /* start with a read transaction, since we're only going to do read
144 operations in this transaction. */
145 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
148 printf("about to set lock\n");
149 /* obtain a read lock, so we don't read data the other guy is writing */
150 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
151 printf("now have lock\n");
156 /* sleep to allow races */
158 tv.tv_sec = sleepTime;
160 IOMGR_Select(0, 0, 0, 0, &tv);
163 code = ubik_Read(tt, &temp, sizeof(afs_int32));
165 /* premature eof, use 0 */
173 /* end the transaction, automatically releasing locks */
174 code = ubik_EndTrans(tt);
180 struct rx_call *rxcall;
183 struct ubik_trans *tt;
186 /* truncation operation requires a write transaction, too */
187 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
188 if (code) return code;
189 printf("about to set lock\n");
190 /* lock the database */
191 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
192 printf("now have lock\n");
198 tv.tv_sec = sleepTime;
200 IOMGR_Select(0, 0, 0, 0, &tv);
202 /* shrink the file */
203 code = ubik_Truncate(tt, 0);
209 code = ubik_EndTrans(tt);
215 struct rx_call *rxcall;
217 afs_int32 code, temp;
218 struct ubik_trans *tt;
221 /* first start a new transaction. Must be a write transaction since
222 we're going to change some data (with ubik_Write) */
223 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
224 if (code) return code;
225 printf("about to set lock\n");
226 /* now set database locks. Must do this or people may read uncommitted
227 data. Note that we're just setting a lock at position 1, which is
228 this program's convention for locking the whole database */
229 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
230 printf("now have lock\n");
235 /* sleep for a little while to make it possible for us to test for some
238 tv.tv_sec = sleepTime;
240 IOMGR_Select(0, 0, 0, 0, &tv);
242 /* read the original value */
243 code = ubik_Read(tt, &temp, sizeof(afs_int32));
245 printf("short read, using 0\n");
252 ubik_AbortTrans(tt); /* surprise! pretend something went wrong */
257 #include "AFS_component_version_number.c"
262 register afs_int32 code, i;
263 afs_int32 serverList[MAXSERVERS];
265 struct rx_service *tservice;
266 struct rx_securityClass *sc[2];
267 extern struct rx_securityClass *rxnull_NewServerSecurityObject();
268 extern struct rx_securityClass *rxvab_NewServerSecurityObject();
269 extern int SAMPLE_ExecuteRequest();
270 char dbfileName[128];
273 printf("usage: userver -servers <serverlist> {-sleep <sleeptime>}\n");
277 /* initialize winsock */
278 if (afs_winsockInit()<0)
281 /* parse our own local arguments */
283 for(i=1;i<argc;i++) {
284 if (strcmp(argv[i], "-sleep")==0) {
286 printf("missing time in -sleep argument\n");
289 sleepTime = atoi(argv[i+1]);
293 /* call routine to parse command line -servers switch, filling in
294 myHost and serverList arrays appropriately */
295 code = ubik_ParseServerList(argc, argv, &myHost, serverList);
297 printf("could not parse server list, code %d\n", code);
300 /* call ServerInit with the values from ParseServerList. Also specify the
301 * name to use for the database files (/tmp/testdb), and the port (3000)
302 * for RPC requests. ServerInit returns a pointer to the database (in
303 * dbase), which is required for creating new transactions */
305 sprintf(dbfileName, "%s/testdb", gettmpdir());
307 code = ubik_ServerInit (myHost, htons(3000), serverList, dbfileName,
311 printf("ubik init failed with code %d\n", code);
315 sc[0] = rxnull_NewServerSecurityObject();
317 sc[1] = rxvab_NewServerSecurityObject("applexx", 0);
319 tservice = rx_NewService(0, USER_SERVICE_ID, "Sample", sc, 1/*2*/,
320 SAMPLE_ExecuteRequest);
321 if (tservice == (struct rx_service *)0) {
322 printf("Could not create SAMPLE rx service\n");
325 rx_SetMinProcs(tservice, 2);
326 rx_SetMaxProcs(tservice, 3);
328 rx_StartServer(1); /* Why waste this idle process?? */