* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/port/win32/socket.c,v 1.1 2004/04/12 16:19:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/port/win32/socket.c,v 1.2 2004/04/22 03:50:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
return nummatches;
}
+
+/*
+ * Return win32 error string, since strerror can't
+ * handle winsock codes
+ */
+static char wserrbuf[256];
+const char *
+pgwin32_socket_strerror(int err)
+{
+ static HANDLE handleDLL = INVALID_HANDLE_VALUE;
+
+ if (handleDLL == INVALID_HANDLE_VALUE) {
+ handleDLL = LoadLibraryEx("netmsg.dll", NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
+ if (handleDLL == NULL)
+ ereport(FATAL,
+ (errmsg_internal("Failed to load netmsg.dll: %i",(int)GetLastError())));
+ }
+
+ ZeroMemory(&wserrbuf, sizeof(wserrbuf));
+ if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE,
+ handleDLL,
+ err,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ wserrbuf,
+ sizeof(wserrbuf)-1,
+ NULL) == 0) {
+ /* Failed to get id */
+ sprintf(wserrbuf,"Unknown winsock error %i",err);
+ }
+ return wserrbuf;
+}
+
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.134 2004/04/16 12:59:05 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.135 2004/04/22 03:51:09 momjian Exp $
*
*-------------------------------------------------------------------------
*/
static char errorstr_buf[48];
const char *str;
+#ifdef WIN32
+ /* Winsock error code range, per WinError.h */
+ if (errnum >= 10000 && errnum <= 11999)
+ return pgwin32_socket_strerror(errnum);
+#endif
str = strerror(errnum);
/*
-/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.22 2004/04/19 17:42:59 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.23 2004/04/22 03:51:24 momjian Exp $ */
/* undefine and redefine after #include */
#undef mkdir
int pgwin32_select(int nfds, fd_set* readfs, fd_set* writefds, fd_set* exceptfds, const struct timeval* timeout);
int pgwin32_recv(SOCKET s, char* buf, int len, int flags);
int pgwin32_send(SOCKET s, char* buf, int len, int flags);
+
+const char *pgwin32_socket_strerror(int err);
#endif