hamsterdb Embedded Database 1.1.14

server1.c

Go to the documentation of this file.
00001 
00016 #include <stdio.h>
00017 #include <stdlib.h>
00018 #include <string.h>
00019 #include <ham/hamsterdb.h>
00020 #include <ham/hamsterdb_srv.h>
00021 
00022 #ifdef WIN32
00023 #   define EXT ".exe"
00024 #else
00025 #   define EXT ""
00026 #endif
00027 
00028 int 
00029 main(void)
00030 {
00031     ham_db_t *db;
00032     ham_env_t *env;
00033     ham_srv_t *srv;
00034     ham_srv_config_t cfg;
00035     ham_status_t st;
00036     char input[1024];
00037 
00038     ham_env_new(&env);
00039     st=ham_env_create_ex(env, "env1.db", HAM_ENABLE_TRANSACTIONS, 0644, 0);
00040     if (st) {
00041         printf("ham_env_create_ex: %d\n", st);
00042         exit(-1);
00043     }
00044 
00045     ham_new(&db);
00046     st=ham_env_create_db(env, db, 12, HAM_ENABLE_DUPLICATES, 0);
00047     if (st) {
00048         printf("ham_env_create_db: %d\n", st);
00049         exit(-1);
00050     }
00051     ham_close(db, 0);
00052 
00053     st=ham_env_create_db(env, db, 13, HAM_ENABLE_DUPLICATES, 0);
00054     if (st) {
00055         printf("ham_env_create_db: %d\n", st);
00056         exit(-1);
00057     }
00058     ham_close(db, 0);
00059 
00060     st=ham_env_create_db(env, db, 33, 
00061                 HAM_RECORD_NUMBER|HAM_ENABLE_DUPLICATES, 0);
00062     if (st) {
00063         printf("ham_env_create_db: %d\n", st);
00064         exit(-1);
00065     }
00066     ham_close(db, 0);
00067 
00068     memset(&cfg, 0, sizeof(cfg));
00069     cfg.port=8080;
00070     ham_srv_init(&cfg, &srv);
00071     ham_srv_add_env(srv, env, "/env1.db");
00072 
00073     printf("server1%s started - please run sample 'client1%s' for a test\n", 
00074             EXT, EXT);
00075     printf("type 'exit' to end the server\n");
00076     
00077     while (1) {
00078         printf("> ");
00079         (void)scanf("%s", &input[0]);
00080         if (!strcmp(input, "exit")) {
00081             printf("exiting...\n");
00082             break;
00083         }
00084         printf("unknown command\n");
00085     }
00086 
00087     ham_srv_close(srv);
00088     ham_env_close(env, HAM_AUTO_CLEANUP);
00089     ham_env_delete(env);
00090     ham_delete(db);
00091 
00092     return (0);
00093 }