473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

possible error in socketmodule / asyncore on win32

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

Jul 18 '05 #1
0 1772

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michael Welsh | last post by:
In order to learn sockets in Python I am trying to write a simple group chat server and client. I need a little nudge, please. My question contains some GUI but only as decoration. The root...
1
by: Gabby | last post by:
I am attempting to compile python 2.1 from the source on a RedHat 9.0 system. The problem is that a openssl header file (kssl.h) requires krb5.h which isn't in the usual place (/usr/include). ...
4
by: F.G.Testa | last post by:
Hi! Is there a way to access a specific connected socket when using a derived asyncore.dispatcher and derived asynchat.async_chat? class AcmeServer(asyncore.dispatcher): def __init__(self,...
5
by: george.trojan | last post by:
My application consists of Tkinter GUI that has to communicate with a remote server. The communication is bi-directional: the GUI responds to remote requests and user actions uch as pressing a...
2
by: Freddie | last post by:
Hi, I've been mangling python-irclib into an asyncore class, so it fits in nicely with the rest of my app. I ran into a problem with asyncore.dispatcher_with_send (Python 2.3.4), though. Not...
3
by: Anand Pillai | last post by:
This is for folks who are familiar with asynchronous event handling in Python using the asyncore module. If you have ever used the asyncore module, you will realize that it's event loop does not...
3
by: Jos | last post by:
Hello. I'm using the asyncore and _chat modules to create a network server. I also have, running in a separate thread(s), a "producer" which needs to "push" data onto the network connection(s)....
4
by: Giampaolo Rodola' | last post by:
Hi there. We're talking about an asyncore-based server. Just for the heck of it I'd like to set a timeout which will disconnects the clients if they're inactive (i.e., no command or data transfer...
8
by: Frank Millman | last post by:
Hi all I have been using my own home-brewed client/server technique for a while, using socket and select. It seems to work ok. The server can handle multiple clients. It does this by creating a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.