Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > possible error in socketmodule / asyncore on win32

Reply
Thread Tools

possible error in socketmodule / asyncore on win32

 
 
Garth
Guest
Posts: n/a
 
      07-24-2003
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);
if (res == 0)
{
if( FD_ISSET( &exfds ) )
{
/* Get the real reason */
getsockopt(s->sock_fd,SOL_SOCKET,SO_ERROR,(char*)&res,sizeof(re s));
}
else
{
res = 0;
}
}
else if (res > 0)
{
res = WSAGetLastError();
}
}
} else if (res < 0)
res = WSAGetLastError();

This still doesn't solve the problem in asyncore as it doesn't test
exfss. I guess it should test exfs if it's not connected (again not tested)

def poll(timeout=0.0, map=None):
if map is None:
map = socket_map
if map:
r = []; w = []; e = []
for fd, obj in map.items():
if obj.readable():
r.append(fd)
if obj.writable():
w.append(fd)

if sys.platform == 'win32':
if not obj.connected:
e.append(fd)
if [] == r == w == e:
time.sleep(timeout)
else:
try:
r, w, e = select.select(r, w, e, timeout)
except select.error, err:
if err[0] != EINTR:
raise
else:
return

if sys.platform == 'win32':
for fd in e:
obj = map.get(fd)
if obj is None:
continue
errno = fs.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
raise socket.error,(errno,socketerrorTab[error])

for fd in r:
obj = map.get(fd)
if obj is None:
continue
read(obj)

for fd in w:
obj = map.get(fd)
if obj is None:
continue
write(obj)

Not really sure where to report this so I'm posting here.

This is all against 2.3c1

(Cheers to all for a wicked language.)

Garth



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hoe to build a patched socketmodule.c jacopo mondi Python 4 07-11-2009 05:55 PM
problem in Trying to include new address family in socketmodule.c viktough Python 0 07-19-2006 12:47 PM
asyncore question Stéphane Ninin Python 6 09-29-2003 02:42 PM
asyncore: handle_accept() question? Chris Python 3 08-28-2003 01:36 AM
asyncore asynchat Michael Welsh Python 0 07-15-2003 11:32 AM



Advertisments