possible error in socketmodule / asyncore on win32
Garth
news at garthy.com
Thu Jul 24 17:36:55 EDT 2003
Garth wrote:
> Hi,
>
> I think there's an error in ther socketmodule.c code
> under windows. The code in internal connect should test
> exceptfds to check for connecttion refused. If this is so it
> should call getsockopt(SOL_SOCKET, SO_ERROR,..) to get the error
> status. (Source microsoft Platform SDK)
>
> If this isn't then the asynccore module fails on windows and never
> returns connection refused.
>
> The code should probably look something like this (untested)
>
> if (s->sock_timeout > 0.0) {
> if (res < 0 && WSAGetLastError() == WSAEWOULDBLOCK) {
> /* This is a mess. Best solution: trust select */
> fd_set exfds;
> struct timeval tv;
> tv.tv_sec = (int)s->sock_timeout;
> tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
> FD_ZERO(&exfds);
> FD_SET(s->sock_fd, &exfds);
> /* Platform SDK says so */
> res = select(s->sock_fd+1, NULL, NULL, &exfds, &tv);
/* CORRECTION! */
if (res > 0)
> {
> if( FD_ISSET( &exfds ) )
> {
> /* Get the real reason */
>
> getsockopt(s->sock_fd,SOL_SOCKET,SO_ERROR,(char*)&res,sizeof(res));
> }
> else
> {
> res = 0;
> }
> }
/* CORRECTION */
else if( res == 0 )
{
res = WSAEWOULDBLOCK;
}
else
{
/* Not sure we should return the erro from select? */
res = WSAGetLastError()
}
> }
> } else if (res < 0)
> res = WSAGetLastError();
The first code I wrote left in writefd testmaybe I should have left it
in. I'll have to wait till I get to work to test it but looking at the
platform sdk on select should explain what my code is trying to do. ;-)
Laters
Garth
More information about the Python-list
mailing list