~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle-1.0/conn.c

  • Committer: Mark Atwood
  • Date: 2011-11-14 07:30:41 UTC
  • Revision ID: me@mark.atwood.name-20111114073041-mo2hgg8ouseo2kpu
releaseĀ 2011.11.29

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)
654
654
  drizzle_con_set_server_version(con, from->server_version);
655
655
  drizzle_con_set_thread_id(con, from->thread_id);
656
656
  drizzle_con_set_scramble(con, from->scramble);
657
 
  drizzle_con_set_capabilities(con, drizzle_capabilities_t(from->capabilities));
 
657
  drizzle_con_set_capabilities(con, from->capabilities);
658
658
  drizzle_con_set_charset(con, from->charset);
659
659
  drizzle_con_set_status(con, from->status);
660
660
  drizzle_con_set_max_packet_size(con, from->max_packet_size);
692
692
                                 drizzle_command_t *command, size_t *total,
693
693
                                 drizzle_return_t *ret_ptr)
694
694
{
 
695
  uint8_t *command_data;
695
696
  size_t offset= 0;
696
697
  size_t size= 0;
697
698
 
698
 
  char *command_data= (char *)drizzle_con_command_read(con, command, &offset, &size, total, ret_ptr);
 
699
  command_data= drizzle_con_command_read(con, command, &offset, &size, total, ret_ptr);
699
700
  if (*ret_ptr != DRIZZLE_RETURN_OK)
700
701
    return NULL;
701
702
 
707
708
 
708
709
  if (con->command_buffer == NULL)
709
710
  {
710
 
    con->command_buffer= (uint8_t*)malloc((*total) + 1);
 
711
    con->command_buffer= malloc((*total) + 1);
711
712
    if (con->command_buffer == NULL)
712
713
    {
713
714
      drizzle_set_error(con->drizzle, "drizzle_command_buffer", "malloc");
720
721
 
721
722
  while ((offset + size) != (*total))
722
723
  {
723
 
    command_data= (char *)drizzle_con_command_read(con, command, &offset, &size, total, ret_ptr);
 
724
    command_data= drizzle_con_command_read(con, command, &offset, &size, total,
 
725
                                           ret_ptr);
724
726
    if (*ret_ptr != DRIZZLE_RETURN_OK)
725
727
      return NULL;
726
728
 
727
729
    memcpy(con->command_buffer + offset, command_data, size);
728
730
  }
729
731
 
730
 
  command_data= (char *)con->command_buffer;
 
732
  command_data= con->command_buffer;
731
733
  con->command_buffer= NULL;
732
734
  command_data[*total]= 0;
733
735
 
1217
1219
{
1218
1220
  char host[NI_MAXHOST];
1219
1221
  char port[NI_MAXSERV];
 
1222
  int ret;
1220
1223
  int fd;
1221
1224
  int opt;
1222
1225
  drizzle_con_st *new_con;
1224
1227
  for (; con->addrinfo_next != NULL;
1225
1228
       con->addrinfo_next= con->addrinfo_next->ai_next)
1226
1229
  {
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);
 
1230
    ret= getnameinfo(con->addrinfo_next->ai_addr,
 
1231
                     con->addrinfo_next->ai_addrlen, host, NI_MAXHOST, port,
 
1232
                     NI_MAXSERV, NI_NUMERICHOST | NI_NUMERICSERV);
1230
1233
    if (ret != 0)
1231
1234
    {
1232
 
      drizzle_set_error(con->drizzle, "drizzle_state_listen", "getnameinfo:%s", gai_strerror(ret));
 
1235
      drizzle_set_error(con->drizzle, "drizzle_state_listen", "getnameinfo:%s",
 
1236
                        gai_strerror(ret));
1233
1237
      return DRIZZLE_RETURN_GETADDRINFO;
1234
1238
    }
1235
1239
 
1303
1307
    }
1304
1308
 
1305
1309
    /* 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)
 
1310
    ret= drizzle_con_set_events(new_con, POLLIN);
 
1311
    if (ret != DRIZZLE_RETURN_OK)
1308
1312
    {
1309
1313
      drizzle_con_free(new_con);
1310
 
      return local_ret;
 
1314
      return ret;
1311
1315
    }
1312
1316
 
1313
1317
    drizzle_log_info(con->drizzle, "listening on %s:%s", host, port);