source: testjes/testgdbm.cpp

Last change on this file was 10, checked in by willem, 11 years ago

willem

File size: 883 bytes
Line 
1#include <iostream>
2#include <string>
3#include <stdlib.h>
4#include <unistd.h>
5#include <gdbm.h>
6
7// g++ testgdbm.cpp -lgdbm
8
9// test if locking works
10// run one instance, then start another instance
11//
12int main()
13{
14  GDBM_FILE dbf=0;
15  do
16  {
17    dbf=gdbm_open((char*)"/tmp/testdb_gdbm",0,GDBM_WRCREAT|GDBM_SYNC,0666,0);
18    if (dbf == 0)
19      usleep(1000);
20  }
21  while (dbf == 0);
22  std::cout << "geopend ..." << std::endl;
23  //sleep(15);
24  //return 0;
25  int w=10;
26  datum key,content;
27  key.dptr = (char*)&w;
28  key.dsize = sizeof(w);
29  content.dptr = (char*)&w;
30  content.dsize = sizeof(w);
31  for (int i=0; i<3000000; i++)
32  {
33    int rc = gdbm_store(dbf,key,content,GDBM_REPLACE);
34    if (rc !=0)
35    {
36      std::cout << "rc: " << rc << std::endl;
37      goto einde;
38    }
39  }
40  std::cout << "gestored ..." << std::endl;
41einde:
42  if (dbf != 0)
43    gdbm_close(dbf);
44  return 0;
45}
Note: See TracBrowser for help on using the repository browser.