RE: [HACKERS] LIBPQ for WIN32

From: Magnus Hagander <mha(at)edu(dot)sollentuna(dot)se>
To: "'Vince Vielhaber'" <vev(at)michvhf(dot)com>, pgsql-hackers <pgsql-hackers(at)postgreSQL(dot)org>
Subject: RE: [HACKERS] LIBPQ for WIN32
Date: 1998-09-29 12:23:17
Message-ID: 215896B6B5E1CF11BC5600805FFEA821F3FC39@sirius.edu.sollentuna.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> > > On 28-Sep-98 Hiroshi Inoue wrote:
> > > > I think that current DLL supports version
> 1.0,1.1,2.0,2.1 and 2.2 and we
> > > > can
> > > > specify any version from 1.0 to 2.2 .
> > > > For example,if we call
> WSAStartup(MAKEWORD(1.0),&wsaData) from libpq
> > > > and call WSAStartup(MAKEWORD(2,2),&wsaData) from
> psql,both return OK
> > > > and wsaData.wVersion is 1.0 for libpq and 2.2 for psql.
> > >
> > > Whichever is done, try not to ever request a version
> higher than what is
> > > required. It forces upgrades that may not even be
> necessary. It's been
> > > awhile since I've done windows code, but I've been bitten
> by requiring a
> > > higher version of a library than necessary - more than
> once without even
> > > realising it. It's not very fun when it comes time to fix it.
> > >
> >
> > How about my sample code at the end of my previous post.
> > In that code,libpq does nothing if main application calls
> WSAStartup().
>
> According to the winsock 1.1 spec an intermediate dll should
> handle it's
> own startup and cleanup functions. Thinking about it, you
> really have
> no way of knowing if the app is going to stop using and unload winsock
> if you're not done with it. It may have loaded it for any number of
> reasons not necessarily related to the database access.

Yes, that is true. The problem lies in how Winsock really will handle
requests for different versions. If the DLL requires 1.1 and the main
program requires 2.0. Will it then open up 2.0 interfaces for both, just the
main app, or none of them? It can't very well do it for just the main app,
since they are both in the same process & thread.
On the other hand, thinking a bit more of it. If we load version 1.1 in
DllMain(), we are safe in most cases. Since if the app loads winsock later
with 2.0, it will probably switch to 2.0, and 2.0 is backwards compatible
with 1.1.
The problem with that scenario is if the DLL is loaded later on in the
program using LoadLibrary(). In that case, the application will have loaded
v2.0, and the DLL will then open up and load v1.1. Will the application then
still be able to use v2.0? With the current Microsoft implementation of
Winsock, it will. But reading the specs, I can't find out if we are allowed
to do this or not.
On the other hand, 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."
And what would the point of this be, if a later call might break an earlier
code. So it will probably "unlock" parts of the Winsock to support all the
requested versions.

If that's the way it works, then we should just make sure we call
WSAStartup() once _and_ WSACleanup() once. And again, if this is how it
works, then the original change with putting it all in DllMain() seems like
the smartest move again. We should probably go with that one, unless
somebody knows another good reason not to :-)

//Magnus

Browse pgsql-hackers by date

  From Date Subject
Next Message The Hermit Hacker 1998-09-29 12:40:46 Re: [HACKERS] Patch - please apply
Previous Message Magnus Hagander 1998-09-29 12:06:25 RE: [HACKERS] LIBPQ for WIN32