~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/sqlite_server.c

  • Committer: Monty Taylor
  • Author(s): Stewart Smith
  • Date: 2010-11-08 11:27:13 UTC
  • mto: This revision was merged to the branch mainline in revision 1931.
  • Revision ID: stewart@flamingspork.com-20101108112713-7qpp4twyvsefdul9
fix sqlite_server stack usage

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
  bool mysql= false;
67
67
  in_port_t port= 0;
68
68
  drizzle_return_t ret;
69
 
  sqlite_server server;
 
69
  sqlite_server *server= (sqllite_server*)malloc(sizeof(sqlite_server));
70
70
  drizzle_con_st *con_listen= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
71
71
 
72
 
  server.db= NULL;
73
 
  server.verbose= DRIZZLE_VERBOSE_NEVER;
 
72
  server->db= NULL;
 
73
  server->verbose= DRIZZLE_VERBOSE_NEVER;
74
74
 
75
75
  while((c = getopt(argc, argv, "c:h:mp:v")) != -1)
76
76
  {
93
93
      break;
94
94
 
95
95
    case 'v':
96
 
      server.verbose++;
 
96
      server->verbose++;
97
97
      break;
98
98
 
99
99
    default:
108
108
    return 1;
109
109
  }
110
110
 
111
 
  sqlite3_open(argv[optind], &(server.db));
112
 
  if (server.db == NULL)
 
111
  sqlite3_open(argv[optind], &(server->db));
 
112
  if (server->db == NULL)
113
113
  {
114
114
    printf("sqlite3_open: could not open sqlite3 db\n");
115
115
    return 1;
116
116
  }
117
117
 
118
 
  if (drizzle_create(&server.drizzle) == NULL)
 
118
  if (drizzle_create(&(server->drizzle)) == NULL)
119
119
  {
120
120
    printf("drizzle_create:NULL\n");
121
121
    return 1;
122
122
  }
123
123
 
124
 
  drizzle_add_options(&server.drizzle, DRIZZLE_FREE_OBJECTS);
125
 
  drizzle_set_verbose(&server.drizzle, server.verbose);
 
124
  drizzle_add_options(&(server->drizzle), DRIZZLE_FREE_OBJECTS);
 
125
  drizzle_set_verbose(&(server->drizzle), server->verbose);
126
126
 
127
 
  if (drizzle_con_create(&server.drizzle, con_listen) == NULL)
 
127
  if (drizzle_con_create(&(server->drizzle), con_listen) == NULL)
128
128
  {
129
129
    printf("drizzle_con_create:NULL\n");
130
130
    return 1;
138
138
 
139
139
  if (drizzle_con_listen(con_listen) != DRIZZLE_RETURN_OK)
140
140
  {
141
 
    printf("drizzle_con_listen:%s\n", drizzle_error(&server.drizzle));
 
141
    printf("drizzle_con_listen:%s\n", drizzle_error(&(server->drizzle)));
142
142
    return 1;
143
143
  }
144
144
 
145
145
  while (1)
146
146
  {
147
 
    (void)drizzle_con_accept(&server.drizzle, &server.con, &ret);
 
147
    (void)drizzle_con_accept(&(server->drizzle), &(server->con), &ret);
148
148
    if (ret != DRIZZLE_RETURN_OK)
149
149
    {
150
 
      printf("drizzle_con_accept:%s\n", drizzle_error(&server.drizzle));
 
150
      printf("drizzle_con_accept:%s\n", drizzle_error(&(server->drizzle)));
151
151
      return 1;
152
152
    }
153
153
 
154
 
    server_run(&server);
 
154
    server_run(server);
155
155
 
156
 
    drizzle_con_free(&server.con);
 
156
    drizzle_con_free(&(server->con));
157
157
 
158
158
    if (count > 0)
159
159
    {
165
165
  }
166
166
 
167
167
  drizzle_con_free(con_listen);
168
 
  drizzle_free(&server.drizzle);
169
 
  sqlite3_close(server.db);
 
168
  drizzle_free(&(server->drizzle));
 
169
  sqlite3_close(server->db);
170
170
  free(con_listen);
 
171
  free(server);
171
172
 
172
173
  return 0;
173
174
}