Skip site navigation (1) Skip section navigation (2)

RE: [INTERFACES] libpq sockets on win32

From: "Jeff Johnson" <jeff(at)jeffjohnson(dot)net>
To: "'Bruce Momjian'" <pgman(at)candle(dot)pha(dot)pa(dot)us>, <jeff(at)jeffjohnson(dot)net>
Cc: <pgsql-interfaces(at)postgresql(dot)org>, <pgsql-docs(at)postgresql(dot)org>
Subject: RE: [INTERFACES] libpq sockets on win32
Date: 2001-06-04 19:03:35
Message-ID: B9C9130B5D27D4119D5D00A0C9D3A98710945F@SERVER (view raw or flat)
Thread:
Lists: pgsql-docspgsql-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


Responses

pgsql-docs by date

Next:From: Bruce MomjianDate: 2001-06-04 19:21:49
Subject: Re: [INTERFACES] libpq sockets on win32
Previous:From: Bruce MomjianDate: 2001-06-04 18:32:17
Subject: Re: [INTERFACES] libpq sockets on win32

pgsql-interfaces by date

Next:From: Bruce MomjianDate: 2001-06-04 19:21:49
Subject: Re: [INTERFACES] libpq sockets on win32
Previous:From: Bruce MomjianDate: 2001-06-04 18:32:17
Subject: Re: [INTERFACES] libpq sockets on win32

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group