[Stackless] Networking code
Adam Bark
adam.jtm30 at gmail.com
Tue Feb 20 19:32:06 CET 2007
Here's some pretty low level networking code I knocked up to encapsulate the
actual sending and recieving. It runs in the main thread along with
everything else so should be useful for anywhere without them or whatever. I
hope somebody else might find it useful considering the amount of talk on
here about networking. Oh yeah it's public domain I suppose, don't want
anybody stopping others using it or something :p
def recv_data(sock):
print "receiving"
sock.setblocking(0)
poller = select.poll()
poller.register(sock, select.POLLIN)
while True:
if poller.poll(0):
return sock.recv(1024)
stackless.schedule()
def send_data(sock, data):
sock.setblocking(0)
poller = select.poll()
poller.register(sock, select.POLLOUT)
while True:
if poller.poll(0):
sent = sock.send(data)
if sent == len(data):
break
else:
data = data[sent:]
stackless.schedule()
Adam.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stackless.com/pipermail/stackless/attachments/20070220/8ff17d2b/attachment.htm>
-------------- next part --------------
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list