4
4
* Copyright (C) 2008 Eric Day (eday@oddments.org)
5
5
* All rights reserved.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are
11
* * Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
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
19
* * The names of its contributors may not be used to endorse or
20
* promote products derived from this software without specific prior
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.
7
* Use and distribution licensed under the BSD license. See
8
* the COPYING.BSD file in the root source directory for full text.
40
13
* @brief Connection Definitions
950
923
con->buffer_ptr= con->buffer;
953
if ((con->revents & POLLIN) == 0 &&
954
(con->drizzle->options & DRIZZLE_NON_BLOCKING))
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)
962
return DRIZZLE_RETURN_IO_WAIT;
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);
972
933
/*Get windows error codes and map it to Posix*/
973
934
errno = WSAGetLastError();
994
955
if (errno == EAGAIN)
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)
1002
961
if (con->drizzle->options & DRIZZLE_NON_BLOCKING)
1003
962
return DRIZZLE_RETURN_IO_WAIT;
1030
989
return DRIZZLE_RETURN_ERRNO;
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;
1039
drizzle_state_pop(con);
996
drizzle_state_pop(con);;
1040
997
return DRIZZLE_RETURN_OK;
1050
1007
while (con->buffer_size != 0)
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);
1055
1012
drizzle_log_crazy(con->drizzle, "write fd=%d return=%zd errno=%d", con->fd,
1056
1013
write_size, errno);
1321
1278
#if defined (_WIN32)
1323
unsigned long asyncmode;
1325
ioctlsocket(con->fd, FIONBIO, &asyncmode);
1279
unsigned long asyncmode = 1;
1280
ioctlsocket(con->fd, FIONBIO, &asyncmode);
1328
1282
ret= fcntl(con->fd, F_GETFL, 0);