upscaledb  2.2.1
server1.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2016 Christoph Rupp (chris@crupp.de).
3  * All Rights Reserved.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * See the file COPYING for License information.
16  */
17 
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <ups/upscaledb.h>
27 #include <ups/upscaledb_srv.h>
28 
29 #ifdef WIN32
30 # define EXT ".exe"
31 #else
32 # define EXT ""
33 #endif
34 
35 int
37 {
38  ups_db_t *db;
39  ups_env_t *env;
40  ups_srv_t *srv;
41  ups_srv_config_t cfg;
42  ups_status_t st;
43  char input[1024];
44  int s;
45 
46  /* create a new Environment; this Environment will be attached to the
47  * server */
48  st = ups_env_create(&env, "env1.db", UPS_ENABLE_TRANSACTIONS, 0644, 0);
49  if (st) {
50  printf("ups_env_create: %d\n", st);
51  exit(-1);
52  }
53 
54  /* also create a Database in that Environment ... */
55  st = ups_env_create_db(env, &db, 12, UPS_ENABLE_DUPLICATE_KEYS, 0);
56  if (st) {
57  printf("ups_env_create_db: %d\n", st);
58  exit(-1);
59  }
60 
61  /* ... and close it again. It will be reopened remotely. */
62  ups_db_close(db, 0);
63 
64  /* Create a second database */
65  st = ups_env_create_db(env, &db, 13, UPS_ENABLE_DUPLICATE_KEYS, 0);
66  if (st) {
67  printf("ups_env_create_db: %d\n", st);
68  exit(-1);
69  }
70 
71  ups_db_close(db, 0);
72 
73  st = ups_env_create_db(env, &db, 33,
75  if (st) {
76  printf("ups_env_create_db: %d\n", st);
77  exit(-1);
78  }
79 
80  ups_db_close(db, 0);
81 
82  /* The ups_srv_config_t structure describes the settings of the server
83  * including the port, the Environment etc */
84  memset(&cfg, 0, sizeof(cfg));
85  cfg.port = 8080;
86  ups_srv_init(&cfg, &srv);
87  ups_srv_add_env(srv, env, "/env1.db");
88 
89  printf("server1%s started - please run sample 'client1%s' for a test\n",
90  EXT, EXT);
91  printf("type 'exit' to end the server\n");
92 
93  /* See client1.c for the corresponding client */
94  while (1) {
95  printf("> ");
96  s = scanf("%s", &input[0]);
97  if (s == EOF || !strcmp(input, "exit")) {
98  printf("exiting...\n");
99  break;
100  }
101  printf("unknown command\n");
102  }
103 
104  /* Close the server and the Environment */
105  ups_srv_close(srv);
107 
108  return (0);
109 }
struct ups_srv_t ups_srv_t
Definition: upscaledb_srv.h:68
ups_status_t ups_srv_add_env(ups_srv_t *srv, ups_env_t *env, const char *urlname)
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_close(ups_env_t *env, uint32_t flags)
#define EXT
Definition: server1.c:32
#define UPS_ENABLE_TRANSACTIONS
Definition: upscaledb.h:1322
Header file for the upscaledb network server.
#define UPS_RECORD_NUMBER64
Definition: upscaledb.h:1305
Include file for upscaledb embedded database.
int main()
Definition: server1.c:36
struct ups_db_t ups_db_t
Definition: upscaledb.h:156
ups_status_t ups_srv_init(ups_srv_config_t *config, ups_srv_t **srv)
#define UPS_AUTO_CLEANUP
Definition: upscaledb.h:1883
#define UPS_ENABLE_DUPLICATE_KEYS
Definition: upscaledb.h:1309
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_create(ups_env_t **env, const char *filename, uint32_t flags, uint32_t mode, const ups_parameter_t *param)
void ups_srv_close(ups_srv_t *srv)
int ups_status_t
Definition: types.h:139
UPS_EXPORT ups_status_t UPS_CALLCONV ups_env_create_db(ups_env_t *env, ups_db_t **db, uint16_t name, uint32_t flags, const ups_parameter_t *params)
UPS_EXPORT ups_status_t UPS_CALLCONV ups_db_close(ups_db_t *db, uint32_t flags)
struct ups_env_t ups_env_t
Definition: upscaledb.h:165