~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/conn.c

  • Committer: Lee Bieber
  • Date: 2011-01-05 05:15:02 UTC
  • mfrom: (2055.1.2 build)
  • Revision ID: kalebral@gmail.com-20110105051502-9v4xuoozzpkka8rs
Merge Evan - fix bug 682773 libdrizzle performance: in non-blocking mode don't attempt to read after write
Merge Stewart - add in more tests from the suites directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
950
950
    con->buffer_ptr= con->buffer;
951
951
  }
952
952
 
 
953
  if ((con->revents & POLLIN) == 0 &&
 
954
      (con->drizzle->options & DRIZZLE_NON_BLOCKING))
 
955
  {
 
956
    /* non-blocking mode: return IO_WAIT instead of attempting to read. This
 
957
     * avoids reading immediately after writing a command, which typically
 
958
     * returns EAGAIN. This improves performance. */
 
959
    ret= drizzle_con_set_events(con, POLLIN);
 
960
    if (ret != DRIZZLE_RETURN_OK)
 
961
      return ret;
 
962
    return DRIZZLE_RETURN_IO_WAIT;
 
963
  }
 
964
 
953
965
  while (1)
954
966
  {
 
967
    size_t available_buffer= (size_t)DRIZZLE_MAX_BUFFER_SIZE -
 
968
        ((size_t)(con->buffer_ptr - con->buffer) + con->buffer_size);
955
969
    read_size = recv(con->fd, (char *)con->buffer_ptr + con->buffer_size,
956
 
                     (size_t)DRIZZLE_MAX_BUFFER_SIZE -
957
 
                     ((size_t)(con->buffer_ptr - con->buffer) +
958
 
                      con->buffer_size),0); 
 
970
                     available_buffer, 0);
959
971
#ifdef _WIN32
960
972
    /*Get windows error codes and map it to Posix*/
961
973
    errno = WSAGetLastError();
981
993
    {
982
994
      if (errno == EAGAIN)
983
995
      {
 
996
        /* clear the read ready flag */
 
997
        con->revents&= ~POLLIN;
984
998
        ret= drizzle_con_set_events(con, POLLIN);
985
999
        if (ret != DRIZZLE_RETURN_OK)
986
 
          return 0;
 
1000
          return ret;
987
1001
 
988
1002
        if (con->drizzle->options & DRIZZLE_NON_BLOCKING)
989
1003
          return DRIZZLE_RETURN_IO_WAIT;
1016
1030
      return DRIZZLE_RETURN_ERRNO;
1017
1031
    }
1018
1032
 
 
1033
    /* clear the "read ready" flag if we read all available data. */
 
1034
    if ((size_t) read_size < available_buffer) con->revents&= ~POLLIN;
1019
1035
    con->buffer_size+= (size_t)read_size;
1020
1036
    break;
1021
1037
  }
1022
1038
 
1023
 
  drizzle_state_pop(con);;
 
1039
  drizzle_state_pop(con);
1024
1040
  return DRIZZLE_RETURN_OK;
1025
1041
}
1026
1042