Обсуждение: RE: [INTERFACES] Win32 interface
It does just that. The problem is that in the DllMain() of the libpq.dll file, WSAStartup() is called, and that is required before any winsock functions will work. If you link statically, you have to manually run WSAStartup. This should probably be documented :-) //Magnus On Friday, September 03, 1999 10:27 PM, David Giffin [SMTP:david@agent911.com] wrote: > > I figured out what was happening... Or at least what seem to happen. When > I linked in lipq.lib it would return unknown hostname. I switched it to > the libpqdll.lib and it worked fine. > > I thought that libpq.lib would statically complie postgres into the .exe > but it didn't seem to work. > > David > > On Fri, 3 Sep 1999, Tom Lane wrote: > > > David Giffin <david@agent911.com> writes: > > > Yep I'm using the PQconnectDB("host=blah user=blah dbname=blah"); > > > I noticed that psql.c uses the PQsetdbLogin maybe I should switch to that > > > function if this one is broken? Would have to parse a little extra but.. > > >>>> > > >>>> connectDB() -- unknown hostname: mobile > > > > Assuming that "mobile" is the hostname you gave it, then parsing the > > connectinfo string is not the problem. > > > > The error message is coming out because gethostbyname() is failing --- > > cf. connectDB() in interfaces/libpq/fe-connect.c. (Or, perchance, > > it is succeeding but delivering a non-INET address? Seems unlikely > > but if your LAN runs on non-TCP protocols then that's possible.) > > > > My guess is that there is something broken with DNS name resolution > > on your setup. Hard to tell what from this much info. You might > > try making a one-liner program that just calls gethostbyname, and > > work on debugging that simpler situation. > > > > regards, tom lane > > > > > ************
Magnus Hagander <mha@sollentuna.net> writes: > The problem is that in the DllMain() of the libpq.dll file, WSAStartup() is > called, and that is required before any winsock functions will work. > If you link statically, you have to manually run WSAStartup. > > This should probably be documented :-) Didn't we talk about having fe-connect.c call WSAStartup() (conditionally compiled of course) to avoid this problem? ISTM there was some reason it wouldn't work, like maybe you can only call WSAStartup once per program, but I don't recall for sure. If it *would* work it would probably be a better answer than making users remember to call the thing. regards, tom lane
> -----Original Message----- > From: owner-pgsql-interfaces@postgreSQL.org > [mailto:owner-pgsql-interfaces@postgreSQL.org]On Behalf Of Tom Lane > Sent: Sunday, September 05, 1999 12:21 AM > To: Magnus Hagander > Cc: 'David Giffin'; Ken J. Wright; pgsql-interfaces@postgreSQL.org > Subject: Re: [INTERFACES] Win32 interface > > > Magnus Hagander <mha@sollentuna.net> writes: > > The problem is that in the DllMain() of the libpq.dll file, > WSAStartup() is > > called, and that is required before any winsock functions will work. > > If you link statically, you have to manually run WSAStartup. > > > > This should probably be documented :-) > > Didn't we talk about having fe-connect.c call WSAStartup() > (conditionally compiled of course) to avoid this problem? > Sorry,I forgot to take static link cases into account when I proposed to call WSAStartup() in DllMain(). > ISTM there was some reason it wouldn't work, like maybe you can > only call WSAStartup once per program, but I don't recall for sure. We can call WSAStartup() more than once. However,there must be a call to WSACleanup() for every successful call to WSAStartup() made by a task. Only the final WSACleanup() for that task does the actual cleanup. . The simplest way may be to call WSAStartup() while connecting and to call WSACleanup() while finishing(including error cases). Regards. Hiroshi Inoue Inoue@tpf.co.jp
"Hiroshi Inoue" <Inoue@tpf.co.jp> writes: >> ISTM there was some reason it wouldn't work, like maybe you can >> only call WSAStartup once per program, but I don't recall for sure. > We can call WSAStartup() more than once. However,there must be a > call to WSACleanup() for every successful call to WSAStartup() > made by a task. Only the final WSACleanup() for that task does the > actual cleanup. > > The simplest way may be to call WSAStartup() while connecting and > to call WSACleanup() while finishing(including error cases). That would be an easy change. Are these functions fast enough that calling them for every connect/disconnect cycle would be tolerable? regards, tom lane