~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/server.cc

  • Committer: Mark Atwood
  • Date: 2011-11-30 07:06:47 UTC
  • mfrom: (2463.1.6 drizzle-include)
  • Revision ID: me@mark.atwood.name-20111130070647-ixp7oalp70hkbt6l
mergeĀ lp:~brianaker/drizzle/libdrizzle-2.0-not-install

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