~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle-2.0/conn.cc

  • Committer: Brian Aker
  • Date: 2011-11-18 16:11:02 UTC
  • mto: (2463.1.1 drizzle-include)
  • mto: This revision was merged to the branch mainline in revision 2462.
  • Revision ID: brian@tangent.org-20111118161102-d1mbswn88iwc2iv1
Pass through refactoring.

Never throw exceptions from libraries. You can not have the assumption that in a driver that the above language can handle this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
586
586
    {
587
587
      drizzle_set_error(con->drizzle, "drizzle_command_write", "connection not ready");
588
588
      *ret_ptr= DRIZZLE_RETURN_NOT_READY;
589
 
      return result;
 
589
      return NULL;
590
590
    }
591
591
 
592
592
    *ret_ptr= drizzle_con_connect(con);
593
593
    if (*ret_ptr != DRIZZLE_RETURN_OK)
594
594
    {
595
 
      return result;
 
595
      return NULL;
596
596
    }
597
597
  }
598
598
 
610
610
        {
611
611
          drizzle_set_error(con->drizzle, "drizzle_command_write", "result struct already in use");
612
612
          *ret_ptr= DRIZZLE_RETURN_INTERNAL_ERROR;
613
 
          return result;
 
613
          return NULL;
614
614
        }
615
615
      }
616
616
 
697
697
  con->backlog= backlog;
698
698
}
699
699
 
700
 
void drizzle_con_set_protocol_version(drizzle_con_st *con,
701
 
                                      uint8_t protocol_version)
 
700
void drizzle_con_set_protocol_version(drizzle_con_st *con, uint8_t protocol_version)
702
701
{
703
702
  if (con == NULL)
704
703
  {
897
896
 
898
897
  if (con->command_buffer == NULL)
899
898
  {
900
 
    con->command_buffer= new uint8_t[(*total) + 1];
 
899
    con->command_buffer= new (std::nothrow) uint8_t[(*total) + 1];
 
900
 
 
901
    if (con->command_buffer == NULL)
 
902
    {
 
903
      *total= 0;
 
904
      *ret_ptr= DRIZZLE_RETURN_MEMORY;
 
905
      return NULL;
 
906
    }
901
907
  }
902
908
 
903
909
  memcpy(con->command_buffer + offset, command_data, size);
1168
1174
    if (ret != DRIZZLE_RETURN_OK)
1169
1175
      return ret;
1170
1176
 
1171
 
    if (con->drizzle->options & DRIZZLE_NON_BLOCKING)
 
1177
    if (con->drizzle->options.is_non_blocking)
 
1178
    {
1172
1179
      return DRIZZLE_RETURN_IO_WAIT;
 
1180
    }
1173
1181
 
1174
1182
    ret= drizzle_con_wait(con->drizzle);
1175
1183
    if (ret != DRIZZLE_RETURN_OK)
 
1184
    {
1176
1185
      return ret;
 
1186
    }
1177
1187
  }
1178
1188
}
1179
1189
 
1192
1202
  }
1193
1203
 
1194
1204
  if ((con->revents & POLLIN) == 0 &&
1195
 
      (con->drizzle->options & DRIZZLE_NON_BLOCKING))
 
1205
      (con->drizzle->options.is_non_blocking))
1196
1206
  {
1197
1207
    /* non-blocking mode: return IO_WAIT instead of attempting to read. This
1198
1208
     * avoids reading immediately after writing a command, which typically
1265
1275
        if (ret != DRIZZLE_RETURN_OK)
1266
1276
          return ret;
1267
1277
 
1268
 
        if (con->drizzle->options & DRIZZLE_NON_BLOCKING)
 
1278
        if (con->drizzle->options.is_non_blocking)
 
1279
        {
1269
1280
          return DRIZZLE_RETURN_IO_WAIT;
 
1281
        }
1270
1282
 
1271
1283
        ret= drizzle_con_wait(con->drizzle);
1272
1284
        if (ret != DRIZZLE_RETURN_OK)
 
1285
        {
1273
1286
          return ret;
 
1287
        }
1274
1288
 
1275
1289
        continue;
1276
1290
      }
1368
1382
      {
1369
1383
        ret= drizzle_con_set_events(con, POLLOUT);
1370
1384
        if (ret != DRIZZLE_RETURN_OK)
 
1385
        {
1371
1386
          return ret;
 
1387
        }
1372
1388
 
1373
 
        if (con->drizzle->options & DRIZZLE_NON_BLOCKING)
 
1389
        if (con->drizzle->options.is_non_blocking)
 
1390
        {
1374
1391
          return DRIZZLE_RETURN_IO_WAIT;
 
1392
        }
1375
1393
 
1376
1394
        ret= drizzle_con_wait(con->drizzle);
1377
1395
        if (ret != DRIZZLE_RETURN_OK)
 
1396
        {
1378
1397
          return ret;
 
1398
        }
1379
1399
 
1380
1400
        continue;
1381
1401
      }
1382
1402
      else if (errno == EINTR)
 
1403
      {
1383
1404
        continue;
 
1405
      }
1384
1406
      else if (errno == EPIPE || errno == ECONNRESET)
1385
1407
      {
1386
1408
        drizzle_set_error(con->drizzle, "drizzle_state_write",