Commit 2b769c82 authored by Tom Lane's avatar Tom Lane

Fix residual breakage from Windows socket-errno patch: the routines

that should use regular errno, not WSAGetLastError(), now do so again.
parent 886d7dec
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.171 2001/07/31 02:14:49 tgl Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.172 2001/08/03 22:11:39 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -697,16 +697,16 @@ update_db_info(PGconn *conn) ...@@ -697,16 +697,16 @@ update_db_info(PGconn *conn)
static int static int
connectMakeNonblocking(PGconn *conn) connectMakeNonblocking(PGconn *conn)
{ {
#ifdef WIN32 #if defined(WIN32) || defined(__BEOS__)
int on = 1; int on = 1;
#endif
#if defined(WIN32)
if (ioctlsocket(conn->sock, FIONBIO, &on) != 0) if (ioctlsocket(conn->sock, FIONBIO, &on) != 0)
#elif defined(__BEOS__) #elif defined(__BEOS__)
int on = 1;
if (ioctl(conn->sock, FIONBIO, &on) != 0) if (ioctl(conn->sock, FIONBIO, &on) != 0)
#else #else
if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
#endif #endif
{ {
printfPQExpBuffer(&conn->errorMessage, printfPQExpBuffer(&conn->errorMessage,
...@@ -1194,6 +1194,8 @@ keep_going: /* We will come back to here until there ...@@ -1194,6 +1194,8 @@ keep_going: /* We will come back to here until there
case CONNECTION_STARTED: case CONNECTION_STARTED:
{ {
ACCEPT_TYPE_ARG3 laddrlen; ACCEPT_TYPE_ARG3 laddrlen;
int optval;
ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
/* /*
* Write ready, since we've made it here, so the * Write ready, since we've made it here, so the
...@@ -1205,10 +1207,6 @@ keep_going: /* We will come back to here until there ...@@ -1205,10 +1207,6 @@ keep_going: /* We will come back to here until there
* state waiting for us on the socket. * state waiting for us on the socket.
*/ */
#ifndef WIN32
int optval;
ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
(char *) &optval, &optlen) == -1) (char *) &optval, &optlen) == -1)
{ {
...@@ -1217,23 +1215,8 @@ keep_going: /* We will come back to here until there ...@@ -1217,23 +1215,8 @@ keep_going: /* We will come back to here until there
strerror(errno)); strerror(errno));
goto error_return; goto error_return;
} }
#else
char far optval[8];
ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
int OptResult=getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,optval, &optlen);
if (OptResult==SOCKET_ERROR)
{
printfPQExpBuffer(&conn->errorMessage,
"PQconnectPoll() -- getsockopt() failed: "
"errno=%i\n", errno);
connectFailureMessage(conn, OptResult);
goto error_return;
}
#endif
else if (optval != 0) else if (optval != 0)
{ {
/* /*
* When using a nonblocking connect, we will typically * When using a nonblocking connect, we will typically
* see connect failures at this point, so provide a * see connect failures at this point, so provide a
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.104 2001/07/20 17:45:06 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.105 2001/08/03 22:11:39 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2037,6 +2037,10 @@ PQoidStatus(const PGresult *res) ...@@ -2037,6 +2037,10 @@ PQoidStatus(const PGresult *res)
return buf; return buf;
} }
#ifdef WIN32 /* need to get at normal errno here */
#undef errno
#endif
/* /*
PQoidValue - PQoidValue -
a perhaps preferable form of the above which just returns a perhaps preferable form of the above which just returns
...@@ -2051,11 +2055,7 @@ PQoidValue(const PGresult *res) ...@@ -2051,11 +2055,7 @@ PQoidValue(const PGresult *res)
if (!res || !res->cmdStatus || strncmp(res->cmdStatus, "INSERT ", 7) != 0) if (!res || !res->cmdStatus || strncmp(res->cmdStatus, "INSERT ", 7) != 0)
return InvalidOid; return InvalidOid;
#ifdef WIN32
WSASetLastError(0);
#else
errno = 0; errno = 0;
#endif
result = strtoul(res->cmdStatus + 7, &endptr, 10); result = strtoul(res->cmdStatus + 7, &endptr, 10);
if (!endptr || (*endptr != ' ' && *endptr != '\0') || errno == ERANGE) if (!endptr || (*endptr != ' ' && *endptr != '\0') || errno == ERANGE)
...@@ -2064,6 +2064,10 @@ PQoidValue(const PGresult *res) ...@@ -2064,6 +2064,10 @@ PQoidValue(const PGresult *res)
return (Oid) result; return (Oid) result;
} }
#ifdef WIN32 /* back to socket errno */
#define errno WSAGetLastError()
#endif
/* /*
PQcmdTuples - PQcmdTuples -
if the last command was an INSERT/UPDATE/DELETE, return number if the last command was an INSERT/UPDATE/DELETE, return number
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.35 2001/07/15 13:45:04 petere Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.36 2001/08/03 22:11:39 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -31,6 +31,11 @@ ...@@ -31,6 +31,11 @@
#include "libpq/libpq-fs.h" /* must come after sys/stat.h */ #include "libpq/libpq-fs.h" /* must come after sys/stat.h */
#ifdef WIN32 /* need to use normal errno in this file */
#undef errno
#endif
#define LO_BUFSIZE 8192 #define LO_BUFSIZE 8192
static int lo_initialize(PGconn *conn); static int lo_initialize(PGconn *conn);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#define strncasecmp(a,b,c) _strnicmp(a,b,c) #define strncasecmp(a,b,c) _strnicmp(a,b,c)
/* /*
* Some compat functions * Some other compat functions
*/ */
#define open(a,b,c) _open(a,b,c) #define open(a,b,c) _open(a,b,c)
#define close(a) _close(a) #define close(a) _close(a)
...@@ -21,18 +21,20 @@ ...@@ -21,18 +21,20 @@
/* /*
* crypt not available (yet) * crypt not available (yet)
*/ */
#define crypt(a,b) a #define crypt(a,b) (a)
/* /*
* assumes that errno is used for sockets only * Most of libpq uses "errno" to access error conditions from socket calls,
* * so on Windows we want to redirect those usages to WSAGetLastError().
* Rather than #ifdef'ing every single place that has "errno", hack it up
* with a macro instead. But there are a few places that do need to touch
* the regular errno variable. For them, we #undef and then redefine errno.
*/ */
#undef errno
#undef EINTR
#undef EAGAIN /* doesn't apply on sockets */
#define errno WSAGetLastError() #define errno WSAGetLastError()
#undef EAGAIN /* doesn't apply on sockets */
#undef EINTR
#define EINTR WSAEINTR #define EINTR WSAEINTR
#define EWOULDBLOCK WSAEWOULDBLOCK #define EWOULDBLOCK WSAEWOULDBLOCK
#define ECONNRESET WSAECONNRESET #define ECONNRESET WSAECONNRESET
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment