RE: [HACKERS] LIBPQ for WIN32

From: Magnus Hagander <mha(at)edu(dot)sollentuna(dot)se>
To: "'Hiroshi Inoue'" <Inoue(at)tpf(dot)co(dot)jp>, pgsql-hackers <pgsql-hackers(at)postgreSQL(dot)org>
Subject: RE: [HACKERS] LIBPQ for WIN32
Date: 1998-09-28 08:30:01
Message-ID: 215896B6B5E1CF11BC5600805FFEA821F3FBF9@sirius.edu.sollentuna.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Hartwig 1998-09-28 13:21:08 Re: [GENERAL] Long update query ?
Previous Message Jan Wieck 1998-09-28 08:01:28 rewrite rules patch