~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/conn.c

  • Committer: patrick crews
  • Date: 2010-09-29 15:15:19 UTC
  • mfrom: (1099.4.188 drizzle)
  • Revision ID: gleebix@gmail.com-20100929151519-6mrmzd1ciw2p9nws
Tags: 2010.09.1802
Update translations

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Copyright (C) 2008 Eric Day (eday@oddments.org)
5
5
 * All rights reserved.
6
6
 *
7
 
 * Redistribution and use in source and binary forms, with or without
8
 
 * modification, are permitted provided that the following conditions are
9
 
 * met:
10
 
 *
11
 
 *     * Redistributions of source code must retain the above copyright
12
 
 * notice, this list of conditions and the following disclaimer.
13
 
 *
14
 
 *     * Redistributions in binary form must reproduce the above
15
 
 * copyright notice, this list of conditions and the following disclaimer
16
 
 * in the documentation and/or other materials provided with the
17
 
 * distribution.
18
 
 *
19
 
 *     * The names of its contributors may not be used to endorse or
20
 
 * promote products derived from this software without specific prior
21
 
 * written permission.
22
 
 *
23
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
 
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
 
 *
 
7
 * Use and distribution licensed under the BSD license.  See
 
8
 * the COPYING.BSD file in the root source directory for full text.
35
9
 */
36
10
 
37
 
 
38
11
/**
39
12
 * @file
40
13
 * @brief Connection Definitions
950
923
    con->buffer_ptr= con->buffer;
951
924
  }
952
925
 
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
 
 
965
926
  while (1)
966
927
  {
967
 
    size_t available_buffer= (size_t)DRIZZLE_MAX_BUFFER_SIZE -
968
 
        ((size_t)(con->buffer_ptr - con->buffer) + con->buffer_size);
969
928
    read_size = recv(con->fd, (char *)con->buffer_ptr + con->buffer_size,
970
 
                     available_buffer, 0);
 
929
                     (size_t)DRIZZLE_MAX_BUFFER_SIZE -
 
930
                     ((size_t)(con->buffer_ptr - con->buffer) +
 
931
                      con->buffer_size),0); 
971
932
#ifdef _WIN32
972
933
    /*Get windows error codes and map it to Posix*/
973
934
    errno = WSAGetLastError();
993
954
    {
994
955
      if (errno == EAGAIN)
995
956
      {
996
 
        /* clear the read ready flag */
997
 
        con->revents&= ~POLLIN;
998
957
        ret= drizzle_con_set_events(con, POLLIN);
999
958
        if (ret != DRIZZLE_RETURN_OK)
1000
 
          return ret;
 
959
          return 0;
1001
960
 
1002
961
        if (con->drizzle->options & DRIZZLE_NON_BLOCKING)
1003
962
          return DRIZZLE_RETURN_IO_WAIT;
1030
989
      return DRIZZLE_RETURN_ERRNO;
1031
990
    }
1032
991
 
1033
 
    /* clear the "read ready" flag if we read all available data. */
1034
 
    if ((size_t) read_size < available_buffer) con->revents&= ~POLLIN;
1035
992
    con->buffer_size+= (size_t)read_size;
1036
993
    break;
1037
994
  }
1038
995
 
1039
 
  drizzle_state_pop(con);
 
996
  drizzle_state_pop(con);;
1040
997
  return DRIZZLE_RETURN_OK;
1041
998
}
1042
999
 
1050
1007
  while (con->buffer_size != 0)
1051
1008
  {
1052
1009
  
1053
 
    write_size = send(con->fd,(char *) con->buffer_ptr, con->buffer_size, 0);
 
1010
    write_size = send(con->fd,(char *) con->buffer_ptr, con->buffer_size,0);
1054
1011
 
1055
1012
    drizzle_log_crazy(con->drizzle, "write fd=%d return=%zd errno=%d", con->fd,
1056
1013
                      write_size, errno);
1319
1276
  }
1320
1277
 
1321
1278
#if defined (_WIN32)
1322
 
  {
1323
 
    unsigned long asyncmode;
1324
 
    asyncmode= 1;
1325
 
    ioctlsocket(con->fd, FIONBIO, &asyncmode);
1326
 
  }
 
1279
  unsigned long asyncmode = 1;
 
1280
  ioctlsocket(con->fd, FIONBIO, &asyncmode);
1327
1281
#else
1328
1282
  ret= fcntl(con->fd, F_GETFL, 0);
1329
1283
  if (ret == -1)