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

From pgsql-bugs@postgresql.org
Subject Bug #641: LIBPQ Linking with the static library on the WIN32 platform fails connections with "unknown host name".
Date
Msg-id 20020422205750.47BFC47589E@postgresql.org
Whole thread Raw
List pgsql-bugs
Jason Erickson (jerickso@indian.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,
receivingthe 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
notbeing 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
forevery connection and WSACleanup for every closing call.  I am not sure if I have all the exit paths.  This patch
mightnot be the best way to solve the problem, since the initialization function only needs to be called once, not for
everyconnection.
 



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

pgsql-bugs by date:

Previous
From: Thomas Lockhart
Date:
Subject: Re: Bug #638: Buggy select statment with numeric
Next
From: pgsql-bugs@postgresql.org
Date:
Subject: Bug #642: Need "Alter table drop column"