~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle-2.0/libdrizzle/drizzle.cc

  • Committer: Olaf van der Spek
  • Date: 2011-06-16 14:52:39 UTC
  • mto: (2318.6.3 refactor7)
  • mto: This revision was merged to the branch mainline in revision 2340.
  • Revision ID: olafvdspek@gmail.com-20110616145239-h3eqc3gojcj7bqkz
Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
 * Common Definitions
67
67
 */
68
68
 
69
 
const char *drizzle_version(void)
 
69
const char *drizzle_version()
70
70
{
71
71
  return PACKAGE_VERSION;
72
72
}
73
73
 
74
 
const char *drizzle_bugreport(void)
 
74
const char *drizzle_bugreport()
75
75
{
76
76
  return PACKAGE_BUGREPORT;
77
77
}
136
136
 
137
137
drizzle_st *drizzle_clone(drizzle_st *drizzle, const drizzle_st *from)
138
138
{
139
 
  drizzle_con_st *con;
140
 
 
141
139
  drizzle= drizzle_create(drizzle);
142
140
  if (drizzle == NULL)
143
141
    return NULL;
144
142
 
145
143
  drizzle->options|= (from->options & ~DRIZZLE_ALLOCATED);
146
144
 
147
 
  for (con= from->con_list; con != NULL; con= con->next)
 
145
  for (drizzle_con_st* con= from->con_list; con != NULL; con= con->next)
148
146
  {
149
147
    if (drizzle_con_clone(drizzle, NULL, con) == NULL)
150
148
    {
169
167
  else if (drizzle->options & DRIZZLE_ASSERT_DANGLING)
170
168
  {
171
169
    assert(drizzle->con_list == NULL);
172
 
    assert(drizzle->con_list == NULL);
 
170
    assert(drizzle->query_list == NULL);
173
171
  }
174
172
 
175
173
  if (drizzle->pfds != NULL)
185
183
 
186
184
const char *drizzle_error(const drizzle_st *drizzle)
187
185
{
188
 
  return (const char *)drizzle->last_error;
 
186
  return drizzle->last_error;
189
187
}
190
188
 
191
189
int drizzle_errno(const drizzle_st *drizzle)
364
362
  case DRIZZLE_CON_SOCKET_UDS:
365
363
    drizzle_con_set_uds(con, from->socket.uds.sockaddr.sun_path);
366
364
    break;
367
 
 
368
 
  default:
369
 
    break;
370
365
  }
371
366
 
372
367
  return con;
407
402
 
408
403
drizzle_return_t drizzle_con_wait(drizzle_st *drizzle)
409
404
{
410
 
  drizzle_con_st *con;
411
405
  struct pollfd *pfds;
412
 
  uint32_t x;
413
406
  int ret;
414
407
  drizzle_return_t dret;
415
408
 
428
421
  else
429
422
    pfds= drizzle->pfds;
430
423
 
431
 
  x= 0;
432
 
  for (con= drizzle->con_list; con != NULL; con= con->next)
 
424
  uint32_t x= 0;
 
425
  for (drizzle_con_st* con= drizzle->con_list; con != NULL; con= con->next)
433
426
  {
434
427
    if (con->events == 0)
435
428
      continue;
476
469
  }
477
470
 
478
471
  x= 0;
479
 
  for (con= drizzle->con_list; con != NULL; con= con->next)
 
472
  for (drizzle_con_st* con= drizzle->con_list; con != NULL; con= con->next)
480
473
  {
481
474
    if (con->events == 0)
482
475
      continue;
493
486
 
494
487
drizzle_con_st *drizzle_con_ready(drizzle_st *drizzle)
495
488
{
496
 
  drizzle_con_st *con;
497
 
 
498
489
  /* We can't keep state between calls since connections may be removed during
499
490
     processing. If this list ever gets big, we may want something faster. */
500
491
 
501
 
  for (con= drizzle->con_list; con != NULL; con= con->next)
 
492
  for (drizzle_con_st* con= drizzle->con_list; con != NULL; con= con->next)
502
493
  {
503
494
    if (con->options & DRIZZLE_CON_IO_READY)
504
495
    {
506
497
      return con;
507
498
    }
508
499
  }
509
 
 
510
500
  return NULL;
511
501
}
512
502
 
513
503
drizzle_con_st *drizzle_con_ready_listen(drizzle_st *drizzle)
514
504
{
515
 
  drizzle_con_st *con;
516
 
 
517
505
  /* We can't keep state between calls since connections may be removed during
518
506
     processing. If this list ever gets big, we may want something faster. */
519
507
 
520
 
  for (con= drizzle->con_list; con != NULL; con= con->next)
 
508
  for (drizzle_con_st* con= drizzle->con_list; con != NULL; con= con->next)
521
509
  {
522
510
    if ((con->options & (DRIZZLE_CON_IO_READY | DRIZZLE_CON_LISTEN)) ==
523
511
        (DRIZZLE_CON_IO_READY | DRIZZLE_CON_LISTEN))
526
514
      return con;
527
515
    }
528
516
  }
529
 
 
530
517
  return NULL;
531
518
}
532
519
 
609
596
drizzle_con_st *drizzle_con_accept(drizzle_st *drizzle, drizzle_con_st *con,
610
597
                                   drizzle_return_t *ret_ptr)
611
598
{
612
 
  drizzle_con_st *ready;
613
 
  int fd;
614
 
 
615
599
  while (1)
616
600
  {
617
 
    if ((ready= drizzle_con_ready_listen(drizzle)) != NULL)
 
601
    if (drizzle_con_st* ready= drizzle_con_ready_listen(drizzle))
618
602
    {
619
 
      fd= accept(ready->fd, NULL, NULL);
 
603
      int fd= accept(ready->fd, NULL, NULL);
620
604
 
621
605
      con= drizzle_con_create(drizzle, con);
622
606
      if (con == NULL)
646
630
      return NULL;
647
631
    }
648
632
 
649
 
    for (ready= drizzle->con_list; ready != NULL; ready= ready->next)
 
633
    for (drizzle_con_st* ready= drizzle->con_list; ready != NULL; ready= ready->next)
650
634
    {
651
635
      if (ready->options & DRIZZLE_CON_LISTEN)
652
636
        drizzle_con_set_events(ready, POLLIN);
665
649
void drizzle_set_error(drizzle_st *drizzle, const char *function,
666
650
                       const char *format, ...)
667
651
{
668
 
  size_t size;
669
 
  int written;
670
 
  char *ptr;
671
652
  char log_buffer[DRIZZLE_MAX_ERROR_SIZE];
672
 
  va_list args;
673
653
 
674
 
  size= strlen(function);
675
 
  ptr= (char *)memcpy(log_buffer, function, size);
 
654
  size_t size= strlen(function);
 
655
  char* ptr= (char *)memcpy(log_buffer, function, size);
676
656
  ptr+= size;
677
657
  ptr[0]= ':';
678
658
  size++;
679
659
  ptr++;
680
660
 
 
661
  va_list args;
681
662
  va_start(args, format);
682
 
  written= vsnprintf(ptr, DRIZZLE_MAX_ERROR_SIZE - size, format, args);
 
663
  int written= vsnprintf(ptr, DRIZZLE_MAX_ERROR_SIZE - size, format, args);
683
664
  va_end(args);
684
665
 
685
666
  if (written < 0) size= DRIZZLE_MAX_ERROR_SIZE;