On Thu, Mar 08, 2007 at 12:47:42PM +0100, Andreas Pflug wrote:
> Magnus Hagander wrote:
> >
> > The easy fix for this is to remove the calls. Which obviously will break
> > some client apps. A fairly easy fix for the WSAStartup() call is to have
> > a check in the connection functions against a global variable that will
> > then make sure to call WSAStartup() the first time it's called.
> >
> > That would leave us "leaking" the WSAStartup() call, but only one per
> > application. This is not perfect, but I'm thinking we can maybe live
> > with that. 
> >
> > If not, perhaps we can have it call WSAStartup() everytime we connect to
> > a server, and then WSACleanup() when we shut down that connection with
> > PQfinish(). 
> 
> Taken from MSDN docs, this seems the recommended solution. After the
> first WSAStartup call subsequent calls are cheap because they only
> increment a counter.

Now that I look closer at it, we *already* do WSAStartup() in
makeEmptyPGconn... And free it in  freePGconn().

So I suggest the following simple patch.. Any objections?

//Magnus
Index: fe-connect.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v
retrieving revision 1.344
diff -c -r1.344 fe-connect.c
*** fe-connect.c        20 Feb 2007 15:20:51 -0000      1.344
--- fe-connect.c        8 Mar 2007 12:16:42 -0000
***************
*** 1840,1848 ****
  #ifdef WIN32

        /*
!        * Make sure socket support is up and running. Even though this is done 
in
!        * libpqdll.c, that is only for MSVC and BCC builds and doesn't work for
!        * static builds at all, so we have to do it in the main code too.
         */
        WSADATA         wsaData;

--- 1840,1846 ----
  #ifdef WIN32

        /*
!        * Make sure socket support is up and running.
         */
        WSADATA         wsaData;

Index: libpqdll.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/interfaces/libpq/libpqdll.c,v
retrieving revision 1.10
diff -c -r1.10 libpqdll.c
*** libpqdll.c  11 Mar 2006 04:38:40 -0000      1.10
--- libpqdll.c  8 Mar 2007 12:05:59 -0000
***************
*** 15,31 ****
        switch (fdwReason)
        {
                case DLL_PROCESS_ATTACH:
!                       if (WSAStartup(MAKEWORD(1, 1), &wsaData))
!                       {
!                               /*
!                                * No really good way to do error handling 
here, since we
!                                * don't know how we were loaded
!                                */
!                               return FALSE;
!                       }
                        break;
                case DLL_PROCESS_DETACH:
!                       WSACleanup();
                        break;
        }

--- 15,24 ----
        switch (fdwReason)
        {
                case DLL_PROCESS_ATTACH:
!                       /* We used to call WSAStartup() here, but this may 
cause deadlocks */
                        break;
                case DLL_PROCESS_DETACH:
!                       /* We used to call WSACleanup() here, but this may 
cause deadlocks */
                        break;
        }

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Reply via email to