RE: libpq sockets on win32 - Mailing list pgsql-interfaces

From Jeff Johnson
Subject RE: libpq sockets on win32
Date
Msg-id B9C9130B5D27D4119D5D00A0C9D3A98710945F@SERVER
Whole thread Raw
In response to libpq sockets on win32  ("Jeff Johnson" <jeff@jeffjohnson.net>)
Responses Re: libpq sockets on win32  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-interfaces
Bruce Momjian wrote:
> Can you try this patch and let me know if it helps?  It is a
different
> approach.  This was the only place I saw errno checked for a
> non-predefined value.

Setting errno = 0 doesn't help, the error handling code is entered
when recv returns -1, then even if errno == 0, it'll bomb out.

> I hate to litter this through the whole source.  I wonder if
> we have to
> bracket the errno checkes with #define/#undef.  Can you try that
with
> the fix described on the web page.  The above would convert to:
>
>     #ifdef WIN32
>     #define errno WSAGetLastError
>     #endif
>             if (errno == EINPROGRESS || errno == 0)
>     #ifdef WIN32
>     #undef errno
>     #endif
>
> Maybe make these into their own macros somehow.

Even when I was a C programmer I never did much more than simple
defines with the pre-compiler so I'll leave this to those that know
how :)

As Tom Lane points out in another post, the "define errno
WSAGetLastError" seems to confuse a variable with a function.  I was
surprised that such a thing could work.  I'm happy to hear that it
doesn't.

What about something like this:

#ifdef WIN32
#define s_errno WSAGetLastError()
#else
#define s_errno errno
#endif

/* for socket functions, check s_errno */
if (s_errno == EINPROGRESS || s_errno == 0)
...

/* for non-socket functions, check errno as usual */
if (errno == ENOENT)
...


Then replace only errno with s_errno when it is used with socket code.
I'm not sure if strerror would work with all the errors returned by
WSAGetLastError().  The Win32 SDK says to use FormatMessage(a ton of
stuff here).


Regards,
Jeff


pgsql-interfaces by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: libpq sockets on win32
Next
From: Bruce Momjian
Date:
Subject: Re: libpq sockets on win32