Skip to content

Commit 8c79f3c

Browse files
committed
i've spotted a following problem using DBD::Pg under win32. winsock
functions do not set errno, so some normal conditions are treated as fatal errors. e.g. fetching large tuples fails, as at some point recv() returns EWOULDBLOCK. here's a patch, which replaces errno with WSAGetLastError(). i've tried to to affect non-win32 code. Dmitry Yurtaev
1 parent 8f75c1b commit 8c79f3c

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.168 2001/07/16 20:05:51 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.169 2001/07/20 17:45:05 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -736,9 +736,6 @@ connectNoDelay(PGconn *conn)
736736
printfPQExpBuffer(&conn->errorMessage,
737737
libpq_gettext("could not set socket to TCP no delay mode: %s\n"),
738738
strerror(errno));
739-
#ifdef WIN32
740-
printf("Winsock error: %i\n", WSAGetLastError());
741-
#endif
742739
return 0;
743740
}
744741

@@ -937,11 +934,7 @@ connectDBStart(PGconn *conn)
937934
*/
938935
if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0)
939936
{
940-
#ifndef WIN32
941937
if (errno == EINPROGRESS || errno == 0)
942-
#else
943-
if (WSAGetLastError() == WSAEINPROGRESS)
944-
#endif
945938
{
946939

947940
/*
@@ -2142,7 +2135,11 @@ PQrequestCancel(PGconn *conn)
21422135
strcpy(conn->errorMessage.data,
21432136
"PQrequestCancel() -- connection is not open\n");
21442137
conn->errorMessage.len = strlen(conn->errorMessage.data);
2138+
#ifdef WIN32
2139+
WSASetLastError(save_errno);
2140+
#else
21452141
errno = save_errno;
2142+
#endif
21462143
return FALSE;
21472144
}
21482145

@@ -2184,11 +2181,12 @@ PQrequestCancel(PGconn *conn)
21842181
/* Sent it, done */
21852182
#ifdef WIN32
21862183
closesocket(tmpsock);
2184+
WSASetLastError(save_errno);
21872185
#else
21882186
close(tmpsock);
2187+
errno = save_errno;
21892188
#endif
21902189

2191-
errno = save_errno;
21922190
return TRUE;
21932191

21942192
cancel_errReturn:
@@ -2199,11 +2197,12 @@ PQrequestCancel(PGconn *conn)
21992197
{
22002198
#ifdef WIN32
22012199
closesocket(tmpsock);
2200+
WSASetLastError(save_errno);
22022201
#else
22032202
close(tmpsock);
2203+
errno = save_errno;
22042204
#endif
22052205
}
2206-
errno = save_errno;
22072206
return FALSE;
22082207
}
22092208

src/interfaces/libpq/fe-exec.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.103 2001/07/15 13:45:04 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.104 2001/07/20 17:45:06 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -223,7 +223,7 @@ pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary)
223223
}
224224

225225
/* If there's enough space in the current block, no problem. */
226-
if (nBytes <= res->spaceLeft)
226+
if (nBytes <= (size_t)res->spaceLeft)
227227
{
228228
space = res->curBlock->space + res->curOffset;
229229
res->curOffset += nBytes;
@@ -1024,7 +1024,7 @@ getAnotherTuple(PGconn *conn, int binary)
10241024
vlen = 0;
10251025
if (tup[i].value == NULL)
10261026
{
1027-
tup[i].value = (char *) pqResultAlloc(result, vlen + 1, binary);
1027+
tup[i].value = (char *) pqResultAlloc(result, vlen + 1, (bool)binary);
10281028
if (tup[i].value == NULL)
10291029
goto outOfMemory;
10301030
}
@@ -2051,7 +2051,11 @@ PQoidValue(const PGresult *res)
20512051
if (!res || !res->cmdStatus || strncmp(res->cmdStatus, "INSERT ", 7) != 0)
20522052
return InvalidOid;
20532053

2054+
#ifdef WIN32
2055+
WSASetLastError(0);
2056+
#else
20542057
errno = 0;
2058+
#endif
20552059
result = strtoul(res->cmdStatus + 7, &endptr, 10);
20562060

20572061
if (!endptr || (*endptr != ' ' && *endptr != '\0') || errno == ERANGE)

src/interfaces/libpq/fe-misc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@
2525
*
2626
*
2727
* IDENTIFICATION
28-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.51 2001/07/15 13:45:04 petere Exp $
28+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.52 2001/07/20 17:45:06 momjian Exp $
2929
*
3030
*-------------------------------------------------------------------------
3131
*/
3232

3333
#include "postgres_fe.h"
3434

35+
#include <errno.h>
36+
#include <signal.h>
37+
#include <time.h>
38+
3539
#ifdef WIN32
3640
#include "win32.h"
3741
#else
3842
#include <unistd.h>
3943
#include <sys/time.h>
4044
#endif
4145

42-
#include <errno.h>
43-
#include <signal.h>
44-
#include <time.h>
45-
4646
#ifdef HAVE_SYS_SELECT_H
4747
#include <sys/select.h>
4848
#endif

src/interfaces/libpq/win32.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,18 @@
2121
* crypt not available (yet)
2222
*/
2323
#define crypt(a,b) a
24+
25+
/*
26+
* assumes that errno is used for sockets only
27+
*
28+
*/
29+
30+
#undef errno
31+
#undef EINTR
32+
#undef EAGAIN /* doesn't apply on sockets */
33+
34+
#define errno WSAGetLastError()
35+
#define EINTR WSAEINTR
36+
#define EWOULDBLOCK WSAEWOULDBLOCK
37+
#define ECONNRESET WSAECONNRESET
38+
#define EINPROGRESS WSAEINPROGRESS

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy