~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/server.cc

  • Committer: Mark Atwood
  • Date: 2011-11-14 07:30:41 UTC
  • Revision ID: me@mark.atwood.name-20111114073041-mo2hgg8ouseo2kpu
releaseĀ 2011.11.29

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include <stdlib.h>
42
42
#include <unistd.h>
43
43
 
44
 
#include <libdrizzle-2.0/drizzle_server.h>
 
44
#include <libdrizzle-1.0/drizzle_server.h>
45
45
 
46
46
#define DRIZZLE_FIELD_MAX 32
47
47
#define DRIZZLE_RESULT_ROWS 20
58
58
  return; \
59
59
}
60
60
 
61
 
static void server(drizzle_st *drizzle, drizzle_con_st *con, drizzle_column_st *column);
 
61
static void server(drizzle_st *drizzle, drizzle_con_st *con,
 
62
                   drizzle_result_st *result, drizzle_column_st *column);
62
63
 
63
64
int main(int argc, char *argv[])
64
65
{
69
70
  in_port_t port= 0;
70
71
  drizzle_verbose_t verbose= DRIZZLE_VERBOSE_NEVER;
71
72
  drizzle_return_t ret;
72
 
  drizzle_st *drizzle;
 
73
  drizzle_st drizzle;
 
74
  drizzle_con_st *con_listen= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
 
75
  drizzle_con_st *con= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
 
76
  drizzle_result_st result;
73
77
  drizzle_column_st column;
74
78
 
75
79
  while((c = getopt(argc, argv, "c:h:mp:v")) != -1)
128
132
    }
129
133
  }
130
134
 
131
 
  if ((drizzle= drizzle_create()) == NULL)
 
135
  if (drizzle_create(&drizzle) == NULL)
132
136
  {
133
 
    fprintf(stderr, "drizzle_create:NULL\n");
 
137
    printf("drizzle_create:NULL\n");
134
138
    return 1;
135
139
  }
136
140
 
137
 
  drizzle_set_option(drizzle, DRIZZLE_FREE_OBJECTS, true);
138
 
  drizzle_set_verbose(drizzle, verbose);
 
141
  drizzle_add_options(&drizzle, DRIZZLE_FREE_OBJECTS);
 
142
  drizzle_set_verbose(&drizzle, verbose);
139
143
 
140
 
  drizzle_con_st* con_listen;
141
 
  if ((con_listen= drizzle_con_create(drizzle)) == NULL)
 
144
  if (drizzle_con_create(&drizzle, con_listen) == NULL)
142
145
  {
143
 
    fprintf(stderr, "drizzle_con_create:NULL\n");
 
146
    printf("drizzle_con_create:NULL\n");
144
147
    return 1;
145
148
  }
146
149
 
148
151
  drizzle_con_set_tcp(con_listen, host, port);
149
152
 
150
153
  if (mysql)
151
 
  {
152
154
    drizzle_con_add_options(con_listen, DRIZZLE_CON_MYSQL);
153
 
  }
154
155
 
155
156
  if (drizzle_con_listen(con_listen) != DRIZZLE_RETURN_OK)
156
157
  {
157
 
    fprintf(stderr, "drizzle_con_listen:%s\n", drizzle_error(drizzle));
 
158
    printf("drizzle_con_listen:%s\n", drizzle_error(&drizzle));
158
159
    return 1;
159
160
  }
160
161
 
161
162
  while (1)
162
163
  {
163
 
    drizzle_con_st *con= drizzle_con_accept(drizzle, &ret);
 
164
    (void)drizzle_con_accept(&drizzle, con, &ret);
164
165
    if (ret != DRIZZLE_RETURN_OK)
165
166
    {
166
 
      fprintf(stderr, "drizzle_con_accept:%s\n", drizzle_error(drizzle));
 
167
      printf("drizzle_con_accept:%s\n", drizzle_error(&drizzle));
167
168
      return 1;
168
169
    }
169
170
 
170
 
    server(drizzle, con, &column);
 
171
    server(&drizzle, con, &result, &column);
171
172
 
172
173
    drizzle_con_free(con);
173
174
 
181
182
  }
182
183
 
183
184
  drizzle_con_free(con_listen);
184
 
  drizzle_free(drizzle);
 
185
  drizzle_free(&drizzle);
 
186
 
 
187
  free(con);
 
188
  free(con_listen);
185
189
 
186
190
  return 0;
187
191
}
188
192
 
189
193
static void server(drizzle_st *drizzle, drizzle_con_st *con,
190
 
                   drizzle_column_st *column)
 
194
                   drizzle_result_st *result, drizzle_column_st *column)
191
195
{
192
196
  drizzle_return_t ret;
193
197
  drizzle_command_t command;
216
220
  DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_server_write", drizzle)
217
221
 
218
222
  ret= drizzle_handshake_client_read(con);
219
 
  DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_client_read", drizzle);
 
223
  DRIZZLE_RETURN_CHECK(ret, "drizzle_handshake_client_read", drizzle)
220
224
 
221
 
  drizzle_result_st *result;
222
 
  if ((result= drizzle_result_create(con)) == NULL)
223
 
  {
 
225
  if (drizzle_result_create(con, result) == NULL)
224
226
    DRIZZLE_RETURN_ERROR("drizzle_result_create", drizzle)
225
 
  }
226
227
 
227
228
  ret= drizzle_result_write(con, result, true);
228
229
  DRIZZLE_RETURN_CHECK(ret, "drizzle_result_write", drizzle)
242
243
    }
243
244
    DRIZZLE_RETURN_CHECK(ret, "drizzle_con_command_buffer", drizzle)
244
245
 
245
 
    if ((result= drizzle_result_create(con)) == NULL)
246
 
    {
 
246
    if (drizzle_result_create(con, result) == NULL)
247
247
      DRIZZLE_RETURN_ERROR("drizzle_result_create", drizzle)
248
 
    }
249
248
 
250
249
    if (command != DRIZZLE_COMMAND_QUERY)
251
250
    {
261
260
 
262
261
    /* Columns. */
263
262
    if (drizzle_column_create(result, column) == NULL)
264
 
    {
265
263
      DRIZZLE_RETURN_ERROR("drizzle_column_create", drizzle)
266
 
    }
267
264
 
268
265
    drizzle_column_set_catalog(column, "default");
269
266
    drizzle_column_set_db(column, "drizzle_test_db");