Skip to content

Commit 2b769c8

Browse files
committed
Fix residual breakage from Windows socket-errno patch: the routines
that should use regular errno, not WSAGetLastError(), now do so again.
1 parent 886d7de commit 2b769c8

File tree

4 files changed

+32
-38
lines changed

4 files changed

+32
-38
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 7 additions & 24 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.171 2001/07/31 02:14:49 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.172 2001/08/03 22:11:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -697,16 +697,16 @@ update_db_info(PGconn *conn)
697697
static int
698698
connectMakeNonblocking(PGconn *conn)
699699
{
700-
#ifdef WIN32
700+
#if defined(WIN32) || defined(__BEOS__)
701701
int on = 1;
702+
#endif
702703

704+
#if defined(WIN32)
703705
if (ioctlsocket(conn->sock, FIONBIO, &on) != 0)
704706
#elif defined(__BEOS__)
705-
int on = 1;
706-
707707
if (ioctl(conn->sock, FIONBIO, &on) != 0)
708708
#else
709-
if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
709+
if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
710710
#endif
711711
{
712712
printfPQExpBuffer(&conn->errorMessage,
@@ -1194,6 +1194,8 @@ PQconnectPoll(PGconn *conn)
11941194
case CONNECTION_STARTED:
11951195
{
11961196
ACCEPT_TYPE_ARG3 laddrlen;
1197+
int optval;
1198+
ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
11971199

11981200
/*
11991201
* Write ready, since we've made it here, so the
@@ -1205,10 +1207,6 @@ PQconnectPoll(PGconn *conn)
12051207
* state waiting for us on the socket.
12061208
*/
12071209

1208-
#ifndef WIN32
1209-
int optval;
1210-
ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
1211-
12121210
if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
12131211
(char *) &optval, &optlen) == -1)
12141212
{
@@ -1217,23 +1215,8 @@ PQconnectPoll(PGconn *conn)
12171215
strerror(errno));
12181216
goto error_return;
12191217
}
1220-
#else
1221-
char far optval[8];
1222-
ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
1223-
1224-
int OptResult=getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,optval, &optlen);
1225-
if (OptResult==SOCKET_ERROR)
1226-
{
1227-
printfPQExpBuffer(&conn->errorMessage,
1228-
"PQconnectPoll() -- getsockopt() failed: "
1229-
"errno=%i\n", errno);
1230-
connectFailureMessage(conn, OptResult);
1231-
goto error_return;
1232-
}
1233-
#endif
12341218
else if (optval != 0)
12351219
{
1236-
12371220
/*
12381221
* When using a nonblocking connect, we will typically
12391222
* see connect failures at this point, so provide a

src/interfaces/libpq/fe-exec.c

Lines changed: 9 additions & 5 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.104 2001/07/20 17:45:06 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.105 2001/08/03 22:11:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2037,6 +2037,10 @@ PQoidStatus(const PGresult *res)
20372037
return buf;
20382038
}
20392039

2040+
#ifdef WIN32 /* need to get at normal errno here */
2041+
#undef errno
2042+
#endif
2043+
20402044
/*
20412045
PQoidValue -
20422046
a perhaps preferable form of the above which just returns
@@ -2051,11 +2055,7 @@ PQoidValue(const PGresult *res)
20512055
if (!res || !res->cmdStatus || strncmp(res->cmdStatus, "INSERT ", 7) != 0)
20522056
return InvalidOid;
20532057

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

20612061
if (!endptr || (*endptr != ' ' && *endptr != '\0') || errno == ERANGE)
@@ -2064,6 +2064,10 @@ PQoidValue(const PGresult *res)
20642064
return (Oid) result;
20652065
}
20662066

2067+
#ifdef WIN32 /* back to socket errno */
2068+
#define errno WSAGetLastError()
2069+
#endif
2070+
20672071
/*
20682072
PQcmdTuples -
20692073
if the last command was an INSERT/UPDATE/DELETE, return number

src/interfaces/libpq/fe-lobj.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.35 2001/07/15 13:45:04 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.36 2001/08/03 22:11:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -31,6 +31,11 @@
3131
#include "libpq/libpq-fs.h" /* must come after sys/stat.h */
3232

3333

34+
#ifdef WIN32 /* need to use normal errno in this file */
35+
#undef errno
36+
#endif
37+
38+
3439
#define LO_BUFSIZE 8192
3540

3641
static int lo_initialize(PGconn *conn);

src/interfaces/libpq/win32.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define strncasecmp(a,b,c) _strnicmp(a,b,c)
88

99
/*
10-
* Some compat functions
10+
* Some other compat functions
1111
*/
1212
#define open(a,b,c) _open(a,b,c)
1313
#define close(a) _close(a)
@@ -21,18 +21,20 @@
2121
/*
2222
* crypt not available (yet)
2323
*/
24-
#define crypt(a,b) a
24+
#define crypt(a,b) (a)
2525

2626
/*
27-
* assumes that errno is used for sockets only
28-
*
27+
* Most of libpq uses "errno" to access error conditions from socket calls,
28+
* so on Windows we want to redirect those usages to WSAGetLastError().
29+
* Rather than #ifdef'ing every single place that has "errno", hack it up
30+
* with a macro instead. But there are a few places that do need to touch
31+
* the regular errno variable. For them, we #undef and then redefine errno.
2932
*/
3033

31-
#undef errno
32-
#undef EINTR
33-
#undef EAGAIN /* doesn't apply on sockets */
34-
3534
#define errno WSAGetLastError()
35+
36+
#undef EAGAIN /* doesn't apply on sockets */
37+
#undef EINTR
3638
#define EINTR WSAEINTR
3739
#define EWOULDBLOCK WSAEWOULDBLOCK
3840
#define ECONNRESET WSAECONNRESET

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