aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-misc.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2001-08-21 20:39:54 +0000
committerBruce Momjian <bruce@momjian.us>2001-08-21 20:39:54 +0000
commit5db5c2db61e7b6493c3a92742bf5ee1e49e3e511 (patch)
tree8c5a7c63a35bd3dcded2edbae31a6c910beb7c1d /src/interfaces/libpq/fe-misc.c
parentf933766ba7c5446a28d714904ae0c46d8b21b86a (diff)
downloadpostgresql-5db5c2db61e7b6493c3a92742bf5ee1e49e3e511.tar.gz
postgresql-5db5c2db61e7b6493c3a92742bf5ee1e49e3e511.zip
> Ok, where's a "system dependent hack" :)
> It seems that win9x doesn't have the "netmsg.dll" so it defaults to "normal" > FormatMessage. > I wonder if one could load wsock32.dll or winsock.dll on those systems > instead of netmsg.dll. > > Mikhail, could you please test this code on your nt4 system? > Could someone else test this code on a win98/95 system? > > It works on win2k over here. It works on win2k here too but not on win98/95 or winNT. Anyway, attached is the patch which uses Magnus's my_sock_strerror function (renamed to winsock_strerror). The only difference is that I put the code to load and unload netmsg.dll in the libpqdll.c (is this OK Magnus?). Mikhail Terekhov
Diffstat (limited to 'src/interfaces/libpq/fe-misc.c')
-rw-r--r--src/interfaces/libpq/fe-misc.c62
1 files changed, 43 insertions, 19 deletions
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index 4fb21578369..81af3be7532 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -25,7 +25,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
@@ -347,13 +347,13 @@ retry:
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;
}
@@ -381,13 +381,13 @@ retry:
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;
@@ -467,25 +467,25 @@ tryAgain:
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)
@@ -553,25 +553,25 @@ tryAgain2:
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)
@@ -653,7 +653,7 @@ pqFlush(PGconn *conn)
* EPIPE or ECONNRESET, assume we've lost the backend
* connection permanently.
*/
- switch (errno)
+ switch (SOCK_ERRNO)
{
#ifdef EAGAIN
case EAGAIN:
@@ -689,7 +689,7 @@ pqFlush(PGconn *conn)
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;
}
@@ -772,11 +772,11 @@ retry:
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;
}
}
@@ -851,3 +851,27 @@ libpq_gettext(const char *msgid)
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