*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.175 2001/08/17 15:11:15 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.176 2001/08/21 20:39:52 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not set socket to non-blocking mode: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
return 0;
}
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not set socket to TCP no delay mode: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
return 0;
}
"\tIs the server running locally and accepting\n"
"\tconnections on Unix domain socket \"%s\"?\n"
),
- strerror(errorno),
+ SOCK_STRERROR(errorno),
conn->raddr.un.sun_path);
else
printfPQExpBuffer(&conn->errorMessage,
"\tIs the server running on host %s and accepting\n"
"\tTCP/IP connections on port %s?\n"
),
- strerror(errorno),
+ SOCK_STRERROR(errorno),
conn->pghost
? conn->pghost
: (conn->pghostaddr
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not create socket: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
goto connect_errReturn;
}
*/
if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0)
{
- if (errno == EINPROGRESS || errno == EWOULDBLOCK || errno == 0)
+ if (SOCK_ERRNO == EINPROGRESS || SOCK_ERRNO == EWOULDBLOCK || SOCK_ERRNO == 0)
{
/*
* This is fine - we're in non-blocking mode, and the
else
{
/* Something's gone wrong */
- connectFailureMessage(conn, errno);
+ connectFailureMessage(conn, SOCK_ERRNO);
goto connect_errReturn;
}
}
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not send SSL negotiation packet: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
goto connect_errReturn;
}
/* Now receive the postmasters response */
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not receive server response to SSL negotiation packet: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
goto connect_errReturn;
}
if (SSLok == 'S')
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not get socket error status: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
goto error_return;
}
else if (optval != 0)
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not get client address from socket: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
goto error_return;
}
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not send startup packet: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
goto error_return;
}
int
PQrequestCancel(PGconn *conn)
{
- int save_errno = errno;
+ int save_errno = SOCK_ERRNO;
int tmpsock = -1;
struct
{
return TRUE;
cancel_errReturn:
- strcat(conn->errorMessage.data, strerror(errno));
+ strcat(conn->errorMessage.data, SOCK_STRERROR(SOCK_ERRNO));
strcat(conn->errorMessage.data, "\n");
conn->errorMessage.len = strlen(conn->errorMessage.data);
if (tmpsock >= 0)
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.107 2001/08/17 15:11:15 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.108 2001/08/21 20:39:53 momjian Exp $
*
*-------------------------------------------------------------------------
*/
return buf;
}
-#ifdef WIN32 /* need to get at normal errno here */
-#undef errno
-#endif
-
/*
PQoidValue -
a perhaps preferable form of the above which just returns
if (!res || !res->cmdStatus || strncmp(res->cmdStatus, "INSERT ", 7) != 0)
return InvalidOid;
+#ifdef WIN32
+ SetLastError(0);
+#else
errno = 0;
+#endif
result = strtoul(res->cmdStatus + 7, &endptr, 10);
if (!endptr || (*endptr != ' ' && *endptr != '\0') || errno == ERANGE)
return (Oid) result;
}
-#ifdef WIN32 /* back to socket errno */
-#define errno WSAGetLastError()
-#endif
/*
PQcmdTuples -
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.37 2001/08/17 15:11:15 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.38 2001/08/21 20:39:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#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
static int lo_initialize(PGconn *conn);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.53 2001/08/17 15:11:15 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.54 2001/08/21 20:39:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
if (select(conn->sock + 1, &input_mask, (fd_set *) NULL, (fd_set *) NULL,
&timeout) < 0)
{
- if (errno == EINTR)
+ if (SOCK_ERRNO == EINTR)
/* Interrupted system call - we'll just try again */
goto retry;
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("select() failed: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
return -1;
}
if (select(conn->sock + 1, (fd_set *) NULL, &input_mask, (fd_set *) NULL,
&timeout) < 0)
{
- if (errno == EINTR)
+ if (SOCK_ERRNO == EINTR)
/* Interrupted system call - we'll just try again */
goto retry;
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("select() failed: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
return -1;
}
return FD_ISSET(conn->sock, &input_mask) ? 1 : 0;
conn->inBufSize - conn->inEnd, 0);
if (nread < 0)
{
- if (errno == EINTR)
+ if (SOCK_ERRNO == EINTR)
goto tryAgain;
/* Some systems return EAGAIN/EWOULDBLOCK for no data */
#ifdef EAGAIN
- if (errno == EAGAIN)
+ if (SOCK_ERRNO == EAGAIN)
return someread;
#endif
#if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
- if (errno == EWOULDBLOCK)
+ if (SOCK_ERRNO == EWOULDBLOCK)
return someread;
#endif
/* We might get ECONNRESET here if using TCP and backend died */
#ifdef ECONNRESET
- if (errno == ECONNRESET)
+ if (SOCK_ERRNO == ECONNRESET)
goto definitelyFailed;
#endif
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not receive data from server: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
return -1;
}
if (nread > 0)
conn->inBufSize - conn->inEnd, 0);
if (nread < 0)
{
- if (errno == EINTR)
+ if (SOCK_ERRNO == EINTR)
goto tryAgain2;
/* Some systems return EAGAIN/EWOULDBLOCK for no data */
#ifdef EAGAIN
- if (errno == EAGAIN)
+ if (SOCK_ERRNO == EAGAIN)
return 0;
#endif
#if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
- if (errno == EWOULDBLOCK)
+ if (SOCK_ERRNO == EWOULDBLOCK)
return 0;
#endif
/* We might get ECONNRESET here if using TCP and backend died */
#ifdef ECONNRESET
- if (errno == ECONNRESET)
+ if (SOCK_ERRNO == ECONNRESET)
goto definitelyFailed;
#endif
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not receive data from server: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
return -1;
}
if (nread > 0)
* EPIPE or ECONNRESET, assume we've lost the backend
* connection permanently.
*/
- switch (errno)
+ switch (SOCK_ERRNO)
{
#ifdef EAGAIN
case EAGAIN:
default:
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not send data to server: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
/* We don't assume it's a fatal error... */
return EOF;
}
if (select(conn->sock + 1, &input_mask, &output_mask, &except_mask,
(struct timeval *) NULL) < 0)
{
- if (errno == EINTR)
+ if (SOCK_ERRNO == EINTR)
goto retry;
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("select() failed: %s\n"),
- strerror(errno));
+ SOCK_STRERROR(SOCK_ERRNO));
return EOF;
}
}
return dgettext("libpq", msgid);
}
#endif /* ENABLE_NLS */
+
+#ifdef WIN32
+/*
+ * strerror replacement for windows:
+ */
+const char*
+winsock_strerror(DWORD eno)
+{
+ if (!FormatMessage(
+ FORMAT_MESSAGE_IGNORE_INSERTS |
+ FORMAT_MESSAGE_FROM_SYSTEM | /* always consider system table */
+ ((netmsgModule != NULL) ? FORMAT_MESSAGE_FROM_HMODULE : 0),
+ netmsgModule, /* module to get message from (NULL == system) */
+ eno,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ winsock_strerror_buf,sizeof(winsock_strerror_buf)-1,
+ NULL
+ )){
+ sprintf(winsock_strerror_buf,"Unknown socket error(%u)",eno);
+ }
+ winsock_strerror_buf[sizeof(winsock_strerror_buf)-1]='\0';
+ return winsock_strerror_buf;
+}
+#endif
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-fe.h,v 1.71 2001/03/22 04:01:27 momjian Exp $
+ * $Id: libpq-fe.h,v 1.72 2001/08/21 20:39:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#endif
#include <stdio.h>
+
+#ifdef WIN32
+ #define SOCK_ERRNO (WSAGetLastError ())
+ #define SOCK_STRERROR winsock_strerror
+#else
+ #define SOCK_ERRNO errno
+ #define SOCK_STRERROR strerror
+#endif
+
+
/* postgres_ext.h defines the backend's externally visible types,
* such as Oid.
*/
#include "postgres_ext.h"
+
#ifdef USE_SSL
#include <openssl/ssl.h>
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock.h>
+#include "win32.h"
BOOL WINAPI
DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
*/
return FALSE;
}
+ if (netmsgModule == NULL){
+ netmsgModule=LoadLibraryEx("netmsg.dll",NULL,LOAD_LIBRARY_AS_DATAFILE);
+ }
break;
case DLL_PROCESS_DETACH:
+ if (netmsgModule != NULL)
+ FreeLibrary(netmsgModule);
WSACleanup();
break;
}
*/
#define crypt(a,b) (a)
-/*
- * 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.
- */
-
-#define errno WSAGetLastError()
-
#undef EAGAIN /* doesn't apply on sockets */
#undef EINTR
#define EINTR WSAEINTR
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ECONNRESET WSAECONNRESET
#define EINPROGRESS WSAEINPROGRESS
+
+/*
+ * Windows network messaging stuff:
+ */
+static HINSTANCE netmsgModule = NULL;
+
+static char winsock_strerror_buf[512];
+const char* winsock_strerror(DWORD eno);