[Date Prev][Date Next] [Chronological] [Thread] [Top]

RE: signal() behavior

> From: Kurt D. Zeilenga [mailto:Kurt@OpenLDAP.Org]

> Seems to me that we can do away with this whole socket pair business if we
> just close all the listeners on shutdown (as is done when -DHAVE_WINSOCK)
> is defined...

I tried something like that - closing a "read" descriptor doesn't seem to
have any effect on the select() call though - it still just waits. The pipe
trick worked by closing the write side of the pipe, which caused an EOF
condition on the read side of the pipe. Just closing the read side had no
effect. Perhaps using shutdown() to close down the connections would work, I
didn't try that. But basically, in order to cause the select() to terminate,
data or an EOF must be generated by the remote side of a connection.
> Also:
> #define sock_errstr()	STRERROR(errno)
> is bogus!
> errno may change from the time it was saved in the local variable and
> the time it is printed.  Hence, sock_errstr must be written to expect
> the local variable.
> 	err = sock_errno();
> 	...
> 	printf("error e=%d s=%s\n", err, sock_errstr(err));

I know, that's pretty much how I wrote it the first time, but Hallvard
objected because the Winsock implementation WSAGetLastErrorString() doesn't
accept an argument, so the macro is misleading there. This bit of semantic
difference is tough to accomodate reasonably in all cases.

I have another idea: a single sock_err() macro that sets both an error
number and an error string pointer:

#define	sock_err(num, str)	\
		num = errno; \
		str = STRERROR(errno)

#undef sock_err
#define	sock_err(num, str)	\
		num = WSAGetLastError(); \
		str = WSAGetLastErrorString()

It seems the only way to get consistent behavior in both cases is to insure
that both the number and the string are obtained "atomically"...