RE: [HACKERS] LIBPQ for WIN32 - Mailing list pgsql-hackers

From Magnus Hagander
Subject RE: [HACKERS] LIBPQ for WIN32
Date
Msg-id 215896B6B5E1CF11BC5600805FFEA821F3FBF9@sirius.edu.sollentuna.se
Whole thread Raw
Responses RE: [HACKERS] LIBPQ for WIN32  ("Hiroshi Inoue" <Inoue@tpf.co.jp>)
List pgsql-hackers
> Hi All.
> I tested libpq for win32 coming with 6.4-BETA and have a
> question about
> LIBPQ.
>
> I used LIBPQ from a C program,but coundn't connect PostgreSQL DB.
>
> Calling pg_connect() without WSAStartup() failed because of
> gethostbyname()
> error in LIBPQ.
> so I modified DllMain in LIBPQ as follows.
>
> BOOL WINAPI DllMain( HINSTANCE hinstDLL,   DWORD fdwReason,
>                      LPVOID lpReserved ){
>
>     WSADATA wsaData;
>     switch (fdwReason)
>            {
>      case DLL_PROCESS_ATTACH:
>           WSAStartup( WSAStartup(MAKEWORD(1, 1), &wsaData);
>           break;
>      case DLL_PROCESS_DETACH:
>           WSACleanup();
>           break;
>            }
>
>     return (TRUE);
> }
>
> and the connection to DB was OK.
>
> Why WSAStartup() is  not called in LIBPQ?

This is probably a good thing to do :-)
When I wrote the code, I thought that I was only allowed to
a) Call WSAStartup() once or
b) All calls to WSAStartup() had to have the same version number
But after reading the specs a little more careful, I see that this is not
the case.

The specs say:
An application or DLL can call WSAStartup more than once if it needs to
obtain the WSAData structure information more than once. On each such call
the application can specify any version number supported by the DLL.

The question is - what will happen when you call it with different versions.
Say the application asks for Winsock 2.0, and then the Libpq library goes in
and asks for Winsock 1.1. Will the application still have access to Winsock
2.0 functions?
With the current implementation, I don't beleive it will make a difference -
I don't think that any part of the Winsock system is actually hidden if you
ask for a lower version. But it is _permitted_ by the specification that the
DLL can hide parts that belong to a higher version than the one requested.

So I'm not 100% sure... Does anybody have access to a Winsock that actually
hides some details when you ask for the wrong version?


//Magnus

pgsql-hackers by date:

Previous
From: jwieck@debis.com (Jan Wieck)
Date:
Subject: rewrite rules patch
Next
From: Tom Lane
Date:
Subject: Proper cleanup at backend exit