~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle-1.0/conn.c

  • Committer: Brian Aker
  • Date: 2011-11-04 21:06:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2450.
  • Revision ID: brian@tangent.org-20111104210616-2at42agch94dkwb0
Additional fixes for libdrizzle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 * @brief Connection Definitions
41
41
 */
42
42
 
43
 
#include <libdrizzle-1.0/common.h>
 
43
#include "common.h"
44
44
 
45
45
/**
46
46
 * @addtogroup drizzle_con_static Static Connection Declarations
89
89
  (void)closesocket(con->fd);
90
90
  con->fd= -1;
91
91
 
92
 
  con->options&= int(~DRIZZLE_CON_READY);
 
92
  con->options&= (drizzle_con_options_t)~DRIZZLE_CON_READY;
93
93
  con->packet_number= 0;
94
94
  con->buffer_ptr= con->buffer;
95
95
  con->buffer_size= 0;
179
179
 
180
180
drizzle_con_options_t drizzle_con_options(const drizzle_con_st *con)
181
181
{
182
 
  return drizzle_con_options_t(con->options);
 
182
  return con->options;
183
183
}
184
184
 
185
185
void drizzle_con_set_options(drizzle_con_st *con,
196
196
  /* If asking for the experimental Drizzle protocol, clean the MySQL flag. */
197
197
  if (con->options & DRIZZLE_CON_EXPERIMENTAL)
198
198
  {
199
 
    con->options&= int(~DRIZZLE_CON_MYSQL);
 
199
    con->options&= (drizzle_con_options_t)~DRIZZLE_CON_MYSQL;
200
200
  }
201
201
}
202
202
 
356
356
 
357
357
drizzle_capabilities_t drizzle_con_capabilities(const drizzle_con_st *con)
358
358
{
359
 
  return drizzle_capabilities_t(con->capabilities);
 
359
  return con->capabilities;
360
360
}
361
361
 
362
362
drizzle_charset_t drizzle_con_charset(const drizzle_con_st *con)
487
487
{
488
488
  drizzle_result_st *old_result;
489
489
 
490
 
  drizzle_return_t unused;
491
 
  if (ret_ptr == NULL)
492
 
  {
493
 
    ret_ptr= &unused;
494
 
  }
495
 
 
496
490
  if (!(con->options & DRIZZLE_CON_READY))
497
491
  {
498
492
    if (con->options & DRIZZLE_CON_RAW_PACKET)
654
648
  drizzle_con_set_server_version(con, from->server_version);
655
649
  drizzle_con_set_thread_id(con, from->thread_id);
656
650
  drizzle_con_set_scramble(con, from->scramble);
657
 
  drizzle_con_set_capabilities(con, drizzle_capabilities_t(from->capabilities));
 
651
  drizzle_con_set_capabilities(con, from->capabilities);
658
652
  drizzle_con_set_charset(con, from->charset);
659
653
  drizzle_con_set_status(con, from->status);
660
654
  drizzle_con_set_max_packet_size(con, from->max_packet_size);
692
686
                                 drizzle_command_t *command, size_t *total,
693
687
                                 drizzle_return_t *ret_ptr)
694
688
{
 
689
  uint8_t *command_data;
695
690
  size_t offset= 0;
696
691
  size_t size= 0;
697
692
 
698
 
  char *command_data= (char *)drizzle_con_command_read(con, command, &offset, &size, total, ret_ptr);
 
693
  command_data= drizzle_con_command_read(con, command, &offset, &size, total, ret_ptr);
699
694
  if (*ret_ptr != DRIZZLE_RETURN_OK)
700
695
    return NULL;
701
696
 
707
702
 
708
703
  if (con->command_buffer == NULL)
709
704
  {
710
 
    con->command_buffer= (uint8_t*)malloc((*total) + 1);
 
705
    con->command_buffer= malloc((*total) + 1);
711
706
    if (con->command_buffer == NULL)
712
707
    {
713
708
      drizzle_set_error(con->drizzle, "drizzle_command_buffer", "malloc");
720
715
 
721
716
  while ((offset + size) != (*total))
722
717
  {
723
 
    command_data= (char *)drizzle_con_command_read(con, command, &offset, &size, total, ret_ptr);
 
718
    command_data= drizzle_con_command_read(con, command, &offset, &size, total,
 
719
                                           ret_ptr);
724
720
    if (*ret_ptr != DRIZZLE_RETURN_OK)
725
721
      return NULL;
726
722
 
727
723
    memcpy(con->command_buffer + offset, command_data, size);
728
724
  }
729
725
 
730
 
  command_data= (char *)con->command_buffer;
 
726
  command_data= con->command_buffer;
731
727
  con->command_buffer= NULL;
732
728
  command_data[*total]= 0;
733
729
 
1217
1213
{
1218
1214
  char host[NI_MAXHOST];
1219
1215
  char port[NI_MAXSERV];
 
1216
  int ret;
1220
1217
  int fd;
1221
1218
  int opt;
1222
1219
  drizzle_con_st *new_con;
1224
1221
  for (; con->addrinfo_next != NULL;
1225
1222
       con->addrinfo_next= con->addrinfo_next->ai_next)
1226
1223
  {
1227
 
    int ret= getnameinfo(con->addrinfo_next->ai_addr,
1228
 
                         con->addrinfo_next->ai_addrlen, host, NI_MAXHOST, port,
1229
 
                         NI_MAXSERV, NI_NUMERICHOST | NI_NUMERICSERV);
 
1224
    ret= getnameinfo(con->addrinfo_next->ai_addr,
 
1225
                     con->addrinfo_next->ai_addrlen, host, NI_MAXHOST, port,
 
1226
                     NI_MAXSERV, NI_NUMERICHOST | NI_NUMERICSERV);
1230
1227
    if (ret != 0)
1231
1228
    {
1232
 
      drizzle_set_error(con->drizzle, "drizzle_state_listen", "getnameinfo:%s", gai_strerror(ret));
 
1229
      drizzle_set_error(con->drizzle, "drizzle_state_listen", "getnameinfo:%s",
 
1230
                        gai_strerror(ret));
1233
1231
      return DRIZZLE_RETURN_GETADDRINFO;
1234
1232
    }
1235
1233
 
1303
1301
    }
1304
1302
 
1305
1303
    /* Wait for read events on the listening socket. */
1306
 
    drizzle_return_t local_ret= drizzle_con_set_events(new_con, POLLIN);
1307
 
    if (local_ret != DRIZZLE_RETURN_OK)
 
1304
    ret= drizzle_con_set_events(new_con, POLLIN);
 
1305
    if (ret != DRIZZLE_RETURN_OK)
1308
1306
    {
1309
1307
      drizzle_con_free(new_con);
1310
 
      return local_ret;
 
1308
      return ret;
1311
1309
    }
1312
1310
 
1313
1311
    drizzle_log_info(con->drizzle, "listening on %s:%s", host, port);