~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/proxy.cc

  • Committer: Brian Aker
  • Date: 2011-11-24 00:05:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2465.
  • Revision ID: brian@tangent.org-20111124000544-186obn61qr3b7r9x
First pass, drizzle_create() no longer takes an argument. This means that we can now change drizzle_st without being concerned about ABI.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
 
51
51
#define DRIZZLE_RETURN_ERROR(__function, __drizzle) \
52
52
{ \
53
 
  printf(__function ":%s\n", drizzle_error(__drizzle)); \
 
53
  fprintf(stderr, __function ":%s\n", drizzle_error(__drizzle)); \
54
54
  return; \
55
55
}
56
56
 
70
70
  in_port_t client_port= 0;
71
71
  drizzle_verbose_t verbose= DRIZZLE_VERBOSE_NEVER;
72
72
  drizzle_return_t ret;
73
 
  drizzle_st drizzle;
 
73
  drizzle_st *drizzle;
74
74
  drizzle_con_st *con_listen= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
75
75
  drizzle_con_st *server= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
76
76
  drizzle_con_st *client= (drizzle_con_st*)malloc(sizeof(drizzle_con_st));
135
135
      break;
136
136
 
137
137
    default:
138
 
      printf("\nusage: %s [-c <count>] [-h <host>] [-H <host>] [-m] [-M] "
 
138
      fprintf(stderr, "\nusage: %s [-c <count>] [-h <host>] [-H <host>] [-m] [-M] "
139
139
             "[-p <port>] [-p <port>] [-v]\n", argv[0]);
140
 
      printf("\t-c <count> - Number of connections to accept before exiting\n");
141
 
      printf("\t-h <host>  - Host to listen on\n");
142
 
      printf("\t-H <host>  - Host to connect to\n");
143
 
      printf("\t-m         - Use MySQL protocol for incoming connections\n");
144
 
      printf("\t-M         - Use MySQL protocol for outgoing connectionsn\n");
145
 
      printf("\t-p <port>  - Port to listen on\n");
146
 
      printf("\t-P <port>  - Port to connect to\n");
147
 
      printf("\t-v         - Increase verbosity level\n");
 
140
      fprintf(stderr, "\t-c <count> - Number of connections to accept before exiting\n");
 
141
      fprintf(stderr, "\t-h <host>  - Host to listen on\n");
 
142
      fprintf(stderr, "\t-H <host>  - Host to connect to\n");
 
143
      fprintf(stderr, "\t-m         - Use MySQL protocol for incoming connections\n");
 
144
      fprintf(stderr, "\t-M         - Use MySQL protocol for outgoing connectionsn\n");
 
145
      fprintf(stderr, "\t-p <port>  - Port to listen on\n");
 
146
      fprintf(stderr, "\t-P <port>  - Port to connect to\n");
 
147
      fprintf(stderr, "\t-v         - Increase verbosity level\n");
148
148
      return 1;
149
149
    }
150
150
  }
151
151
 
152
 
  if (drizzle_create(&drizzle) == NULL)
 
152
  if ((drizzle= drizzle_create()) == NULL)
153
153
  {
154
 
    printf("drizzle_create:NULL\n");
 
154
    fprintf(stderr, "drizzle_create:NULL\n");
155
155
    return 1;
156
156
  }
157
157
 
158
 
  drizzle_add_options(&drizzle, DRIZZLE_FREE_OBJECTS);
159
 
  drizzle_set_verbose(&drizzle, verbose);
 
158
  drizzle_add_options(drizzle, DRIZZLE_FREE_OBJECTS);
 
159
  drizzle_set_verbose(drizzle, verbose);
160
160
 
161
 
  if (drizzle_con_create(&drizzle, con_listen) == NULL)
 
161
  if (drizzle_con_create(drizzle, con_listen) == NULL)
162
162
  {
163
 
    printf("drizzle_con_create:NULL\n");
 
163
    fprintf(stderr, "drizzle_con_create:NULL\n");
164
164
    return 1;
165
165
  }
166
166
 
168
168
  drizzle_con_set_tcp(con_listen, server_host, server_port);
169
169
 
170
170
  if (server_mysql)
 
171
  {
171
172
    drizzle_con_add_options(con_listen, DRIZZLE_CON_MYSQL);
 
173
  }
172
174
 
173
175
  if (drizzle_con_listen(con_listen) != DRIZZLE_RETURN_OK)
174
176
  {
175
 
    printf("drizzle_con_listen:%s\n", drizzle_error(&drizzle));
 
177
    fprintf(stderr, "drizzle_con_listen:%s\n", drizzle_error(drizzle));
176
178
    return 1;
177
179
  }
178
180
 
179
181
  while (1)
180
182
  {
181
 
    (void)drizzle_con_accept(&drizzle, server, &ret);
 
183
    (void)drizzle_con_accept(drizzle, server, &ret);
182
184
    if (ret != DRIZZLE_RETURN_OK)
183
185
    {
184
 
      printf("drizzle_con_accept:%s\n", drizzle_error(&drizzle));
 
186
      fprintf(stderr, "drizzle_con_accept:%s\n", drizzle_error(drizzle));
185
187
      return 1;
186
188
    }
187
189
 
188
 
    if (drizzle_con_create(&drizzle, client) == NULL)
 
190
    if (drizzle_con_create(drizzle, client) == NULL)
189
191
    {
190
 
      printf("drizzle_con_create:NULL\n");
 
192
      fprintf(stderr, "drizzle_con_create:NULL\n");
191
193
      return 1;
192
194
    }
193
195
 
200
202
    ret= drizzle_con_connect(client);
201
203
    if (ret != DRIZZLE_RETURN_OK)
202
204
    {
203
 
      printf("drizzle_con_connect:%s\n", drizzle_error(&drizzle));
 
205
      fprintf(stderr, "drizzle_con_connect:%s\n", drizzle_error(drizzle));
204
206
      return 1;
205
207
    }
206
208
 
207
 
    proxy(&drizzle, server, client, &server_result, &client_result, &column);
 
209
    proxy(drizzle, server, client, &server_result, &client_result, &column);
208
210
 
209
211
    drizzle_con_free(client);
210
212
    drizzle_con_free(server);
219
221
  }
220
222
 
221
223
  drizzle_con_free(con_listen);
222
 
  drizzle_free(&drizzle);
 
224
  drizzle_free(drizzle);
223
225
 
224
226
  free(con_listen);
225
227
  free(server);