RE: libpq sockets on win32

Поиск
Список
Период
Сортировка
От Jeff Johnson
Тема RE: libpq sockets on win32
Дата
Msg-id B9C9130B5D27D4119D5D00A0C9D3A98710945F@SERVER
обсуждение исходный текст
Ответ на libpq sockets on win32  ("Jeff Johnson" <jeff@jeffjohnson.net>)
Ответы Re: libpq sockets on win32  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: libpq sockets on win32
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: libpq sockets on win32