105
107
drizzle= new (std::nothrow) drizzle_st;
106
108
if (drizzle == NULL)
109
113
drizzle->options= DRIZZLE_ALLOCATED;
112
117
drizzle->options= DRIZZLE_NONE;
114
120
/* @todo remove this default free flag with new API. */
115
121
drizzle->options|= DRIZZLE_FREE_OBJECTS;
141
147
drizzle_st *drizzle_clone(drizzle_st *drizzle, const drizzle_st *from)
145
149
drizzle= drizzle_create(drizzle);
146
150
if (drizzle == NULL)
149
155
drizzle->options|= (from->options & int(~DRIZZLE_ALLOCATED));
151
for (con= from->con_list; con != NULL; con= con->next)
157
for (drizzle_con_st *con= from->con_list; con != NULL; con= con->next)
153
159
if (drizzle_con_clone(drizzle, NULL, con) == NULL)
163
169
void drizzle_free(drizzle_st *drizzle)
165
176
if (drizzle->context != NULL && drizzle->context_free_fn != NULL)
166
178
drizzle->context_free_fn(drizzle, drizzle->context);
168
181
if (drizzle->options & DRIZZLE_FREE_OBJECTS)
191
204
const char *drizzle_error(const drizzle_st *drizzle)
193
211
return (const char *)drizzle->last_error;
196
214
int drizzle_errno(const drizzle_st *drizzle)
198
221
return drizzle->last_errno;
201
224
uint16_t drizzle_error_code(const drizzle_st *drizzle)
203
231
return drizzle->error_code;
206
234
const char *drizzle_sqlstate(const drizzle_st *drizzle)
208
241
return drizzle->sqlstate;
211
244
drizzle_options_t drizzle_options(const drizzle_st *drizzle)
248
return drizzle_options_t();
213
251
return drizzle_options_t(drizzle->options);
216
254
void drizzle_set_options(drizzle_st *drizzle, drizzle_options_t options)
218
261
drizzle->options= options;
221
264
void drizzle_add_options(drizzle_st *drizzle, drizzle_options_t options)
223
271
drizzle->options|= options;
226
274
void drizzle_remove_options(drizzle_st *drizzle, drizzle_options_t options)
228
281
drizzle->options&= ~options;
231
284
void *drizzle_context(const drizzle_st *drizzle)
233
291
return drizzle->context;
236
294
void drizzle_set_context(drizzle_st *drizzle, void *context)
238
301
drizzle->context= context;
241
304
void drizzle_set_context_free_fn(drizzle_st *drizzle,
242
305
drizzle_context_free_fn *function)
244
312
drizzle->context_free_fn= function;
247
315
int drizzle_timeout(const drizzle_st *drizzle)
249
322
return drizzle->timeout;
252
325
void drizzle_set_timeout(drizzle_st *drizzle, int timeout)
254
332
drizzle->timeout= timeout;
257
335
drizzle_verbose_t drizzle_verbose(const drizzle_st *drizzle)
339
return drizzle_verbose_t();
259
342
return drizzle->verbose;
262
345
void drizzle_set_verbose(drizzle_st *drizzle, drizzle_verbose_t verbose)
264
352
drizzle->verbose= verbose;
267
355
void drizzle_set_log_fn(drizzle_st *drizzle, drizzle_log_fn *function,
270
363
drizzle->log_fn= function;
271
364
drizzle->log_context= context;
275
368
drizzle_event_watch_fn *function,
278
376
drizzle->event_watch_fn= function;
279
377
drizzle->event_watch_context= context;
282
380
drizzle_con_st *drizzle_con_create(drizzle_st *drizzle, drizzle_con_st *con)
286
389
con= new (std::nothrow) drizzle_con_st;
289
392
if (drizzle != NULL)
290
394
drizzle_set_error(drizzle, "drizzle_con_create", "malloc");
294
400
con->options= DRIZZLE_CON_ALLOCATED;
299
407
if (drizzle->con_list != NULL)
300
409
drizzle->con_list->prev= con;
301
411
con->next= drizzle->con_list;
303
413
drizzle->con_list= con;
354
464
drizzle_con_st *drizzle_con_clone(drizzle_st *drizzle, drizzle_con_st *con,
355
465
const drizzle_con_st *from)
357
472
con= drizzle_con_create(drizzle, con);
361
478
/* Clear "operational" options such as IO status. */
362
479
con->options|= (from->options & int(~(
388
505
void drizzle_con_free(drizzle_con_st *con)
390
if (con->context != NULL && con->context_free_fn != NULL)
512
if (con->context != NULL and con->context_free_fn != NULL)
391
514
con->context_free_fn(con, con->context);
393
517
if (con->drizzle->options & DRIZZLE_FREE_OBJECTS)
394
519
drizzle_result_free_all(con);
395
521
else if (con->drizzle->options & DRIZZLE_ASSERT_DANGLING)
396
523
assert(con->result_list == NULL);
398
526
if (con->fd != -1)
399
528
drizzle_con_close(con);
401
531
drizzle_con_reset_addrinfo(con);
403
533
if (con->drizzle->con_list == con)
404
534
con->drizzle->con_list= con->next;
405
536
if (con->prev != NULL)
406
537
con->prev->next= con->next;
407
539
if (con->next != NULL)
408
540
con->next->prev= con->prev;
409
542
con->drizzle->con_count--;
411
544
if (con->options & DRIZZLE_CON_ALLOCATED)
423
556
drizzle_return_t drizzle_con_wait(drizzle_st *drizzle)
560
return DRIZZLE_RETURN_INVALID_ARGUMENT;
426
563
struct pollfd *pfds;
429
drizzle_return_t dret;
431
564
if (drizzle->pfds_size < drizzle->con_count)
433
566
pfds= (struct pollfd *)realloc(drizzle->pfds, drizzle->con_count * sizeof(struct pollfd));
494
for (con= drizzle->con_list; con != NULL; con= con->next)
634
for (drizzle_con_st *con= drizzle->con_list; con != NULL; con= con->next)
496
636
if (con->events == 0)
499
dret= drizzle_con_set_revents(con, pfds[x].revents);
641
drizzle_return_t dret= drizzle_con_set_revents(con, pfds[x].revents);
500
642
if (dret != DRIZZLE_RETURN_OK)
509
653
drizzle_con_st *drizzle_con_ready(drizzle_st *drizzle)
513
660
/* We can't keep state between calls since connections may be removed during
514
661
processing. If this list ever gets big, we may want something faster. */
516
for (con= drizzle->con_list; con != NULL; con= con->next)
663
for (drizzle_con_st *con= drizzle->con_list; con != NULL; con= con->next)
518
665
if (con->options & DRIZZLE_CON_IO_READY)
528
675
drizzle_con_st *drizzle_con_ready_listen(drizzle_st *drizzle)
532
682
/* We can't keep state between calls since connections may be removed during
533
683
processing. If this list ever gets big, we may want something faster. */
535
for (con= drizzle->con_list; con != NULL; con= con->next)
685
for (drizzle_con_st *con= drizzle->con_list; con != NULL; con= con->next)
537
687
if ((con->options & (DRIZZLE_CON_IO_READY | DRIZZLE_CON_LISTEN)) ==
538
688
(DRIZZLE_CON_IO_READY | DRIZZLE_CON_LISTEN))
556
706
drizzle_con_options_t options)
558
713
con= drizzle_con_create(drizzle, con);
562
719
drizzle_con_set_tcp(con, host, port);
563
720
drizzle_con_set_auth(con, user, password);
572
729
const char *password, const char *db,
573
730
drizzle_con_options_t options)
575
737
con= drizzle_con_create(drizzle, con);
579
743
drizzle_con_set_uds(con, uds);
580
744
drizzle_con_set_auth(con, user, password);
595
759
drizzle_con_options_t options)
597
766
con= drizzle_con_create(drizzle, con);
601
772
drizzle_con_set_tcp(con, host, port);
602
773
drizzle_con_set_backlog(con, backlog);
610
781
const char *uds, int backlog,
611
782
drizzle_con_options_t options)
613
789
con= drizzle_con_create(drizzle, con);
617
795
drizzle_con_set_uds(con, uds);
618
796
drizzle_con_set_backlog(con, backlog);
624
802
drizzle_con_st *drizzle_con_accept(drizzle_st *drizzle, drizzle_con_st *con,
625
803
drizzle_return_t *ret_ptr)
627
drizzle_con_st *ready;
805
drizzle_return_t unused_ret;
808
ret_ptr= &unused_ret;
818
drizzle_con_st *ready;
632
820
if ((ready= drizzle_con_ready_listen(drizzle)) != NULL)
634
fd= accept(ready->fd, NULL, NULL);
822
int fd= accept(ready->fd, NULL, NULL);
636
824
con= drizzle_con_create(drizzle, con);
696
889
written= vsnprintf(ptr, DRIZZLE_MAX_ERROR_SIZE - size, format, args);
699
if (written < 0) size= DRIZZLE_MAX_ERROR_SIZE;
894
size= DRIZZLE_MAX_ERROR_SIZE;
701
901
if (size >= DRIZZLE_MAX_ERROR_SIZE)
702
903
size= DRIZZLE_MAX_ERROR_SIZE - 1;
703
905
log_buffer[size]= 0;
705
907
if (drizzle->log_fn == NULL)
706
909
memcpy(drizzle->last_error, log_buffer, size + 1);
708
913
drizzle->log_fn(log_buffer, DRIZZLE_VERBOSE_ERROR, drizzle->log_context);
711
917
void drizzle_log(drizzle_st *drizzle, drizzle_verbose_t verbose,
712
918
const char *format, va_list args)
714
925
char log_buffer[DRIZZLE_MAX_ERROR_SIZE];
716
927
if (drizzle->log_fn == NULL)