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-10-01 10:53:15
Message-ID: 215896B6B5E1CF11BC5600805FFEA821F3FC83@sirius.edu.sollentuna.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> > > > 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?(at)that
> > > actually
> > > > hides some details when you ask for the wrong version?
> > > >
> > >
> > > By the specs there may be the DLL that doesn't support
> lower versions.
> > > In that case my code doesn't work well.
> > > But we can delay to call WSAStartup() after the first socket
> > > call in LIBPQ.
> > > My example code in fe-connect.c is such as follows.
> > This looks like a great way to do it :-)
> >
> >
> > > hp = gethostbyname(conn->pghost);
> > > #ifdef WIN32
> > > if ((hp == NULL) && (GetLastError() == WSANOTINITIALISED))
> > > {
> > > WSADATA wsaData;
> > > if (WSAStartup(MAKEWORD(1,1),&wsaData))
> > > {
> > > fprintf(stderr, "Failed to start
> > > winsock: %i\n", WSAGetLastError());
> > > exit(1);
> >
> > This is not the way to do it, though - what if it's a gui program.
> > Should instead be, like the other error handling:
> >
> > sprintf(conn->errorMessage,
> > "connectDB() -- Failed to start
> > winsock: %i\n",
> > WSAGetLstError());
> > goto connect_errReturn;
> >
> > > }
> > > ....
> > > ???? for WSACleanup() ????
> > > ....
> > Yes, this is the problem. Perhaps set a global flag in the
> DLL that is set
> > if we have ever called WSAStartup() from the DLL. Then we
> can check in
> > DllMain() at process detachment if we have to close the winsock?
> >
> > Will you write up a patch or should I?
> >
>
> Judging from your reply to Vince,it is preferable to call
> WSAStartup() and
> corrspoiding WSACleanup() in DllMain.
> If so,my original code is OK except error handling and the
> value of version
> number ?

Yes, I think that is where we ended up :-)

BTW, I came to think of another thing - the Win32 library does _not_ support
crypt-password authentication as it is now. Because there is no crypt()
function.
Any chance to have a file with crypt() included in the source as we did with
getopt? If that can be done, and one of you FreeBSD (or someone else who has
it under BSD license) could mail it to me/put it in the tree, I can take a
look at implementing it - shouldn't bve hard at all.

//Magnus

Browse pgsql-hackers by date

  From Date Subject
Next Message Jan Wieck 1998-10-01 11:06:42 Patch for libpgtcl
Previous Message Hiroshi Inoue 1998-10-01 10:44:25 RE: [HACKERS] LIBPQ for WIN32