Bug #641: LIBPQ Linking with the static library on the WIN32 platform fails connections with "unknown host name".

From: pgsql-bugs(at)postgresql(dot)org
To: pgsql-bugs(at)postgresql(dot)org
Subject: Bug #641: LIBPQ Linking with the static library on the WIN32 platform fails connections with "unknown host name".
Date: 2002-04-22 20:57:50
Message-ID: 20020422205750.47BFC47589E@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Jason Erickson (jerickso(at)indian(dot)com) reports a bug with a severity of 3
The lower the number the more severe it is.

Short Description
LIBPQ Linking with the static library on the WIN32 platform fails connections with "unknown host name".

Long Description
I was having problems connecting up to a remote PostgreSQL database when I linked a program with the static library, receiving the error "unknown host name: 198.168.100.254". I was not experiencing this problem when I linked with the DLL.

Client: Microsoft Visual C++ 6.0, PostgreSQL 7.2.1
Server: FreeBSD 4.4-Stable, PosotgreSQL 7.2.1

I traced this down to the fact that with the static version of the library, the WinSock initialization functions are not being called (WSAStartup). The DLL calls the WinSock initialization function in the DllMain function.

I have included what I used to patch the file fe-connect.c in the example code section. This solution calls WSAStartup for every connection and WSACleanup for every closing call. I am not sure if I have all the exit paths. This patch might not be the best way to solve the problem, since the initialization function only needs to be called once, not for every connection.

Sample Code
834c834,843
<
---
> #if WIN32
> WSADATA wsaData;
> if (WSAStartup(MAKEWORD(1, 1), &wsaData))
> {
> printfPQExpBuffer(&conn->errorMessage,
> libpq_gettext("Unable to Initialize WSA\n"));
> goto connect_errReturn;
> }
> WSASetLastError(0);
> #endif
988a998
> WSACleanup();
1029a1040
> WSACleanup();
1909a1921
> WSACleanup();
1982a1995
> WSACleanup();
2159a2173
> WSACleanup();

No file was uploaded with this report

Browse pgsql-bugs by date

  From Date Subject
Next Message pgsql-bugs 2002-04-23 02:02:15 Bug #642: Need "Alter table drop column"
Previous Message pgsql-bugs 2002-04-22 16:41:43 Bug #640: ECPG: inserting float numbers