FD_SETSIZE not working in 2.3.2?

  • Thread starter Krister Liljedahl
  • Start date
K

Krister Liljedahl

Hi,

I'm getting an "10055, An operation on a socket could not be performed
because
the system lacked sufficient buffer space or because a queue was full"
error message when opening 64 or more sockets in a single thread when
using Python 2.3.2 under Windows XP.

I think this is because Python fails to increase the value of
FD_SETSIZE before it invokes winsock.h. If I'm reading the Python
source right then winsock.h is invoked by errnomodule.c before
selectmodule.c increases the value of FD_SETSIZE to 512 from the
default 64, which would explain my problems.

Does anyone else experience problem with large numbers (>63) of
sockets under Windows? Can anyone else succesfully open 64 or more
sockets under Windows and poll them using select?

Anyone got any other explanations/thoughs/ideas?

/Krister
 
C

Colin Brown

Krister Liljedahl said:
Hi, ....
Does anyone else experience problem with large numbers (>63) of
sockets under Windows?

Yes, see details of previous post of mine below.

======================================================
windows under Win2K does not work properly (missed & very delayed
transmissions). Under Redhat Linux 9 (where I will be using it) it works
fine (with up to 250 sending threads; I hit the thread limit at 255!)

Any idea why do I not get any errors reported under Windows?

Colin Brown
PyNZ

--[Sender.py]--------------------------------------------------------
# Send 50 'simultaneous' tcp transmissions to receiver

import os,socket,sys,time,thread,traceback

def error():
tb =
traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info(
)[2])
return tb[len(tb)-1].replace('\n','')

class client:
def __init__(self,nodeport):
self.nodeport = nodeport
self.cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.cli.settimeout(60.0)
def connect(self):
self.cli.connect((self.nodeport))
def write(self,data):
self.cli.sendall(data)
def close(self):
self.cli.close()

def send(v,data):
cli = client(('localhost',20031))
for cnt in range(5):
try:
cli.connect()
break
except:
if cnt == 4:
print v,'Connect failure: ',error()
else:
time.sleep(0.3)
try:
cli.write(data)
except:
print v,'Send failure: ',error()
cli.close()
print v

def action(data,number):
for ii in range(1,1+number):
thread.start_new_thread(send,(str(ii),data))

if __name__ == '__main__':
action(''.join(['00001000',chr(32)*1000]),50)
time.sleep(75.0)

--[Receiver.py]------------------------------------------------------
import select,socket,thread, time

COUNTER = 0
TIME0 = 0.0

class rx:
def __init__(self,LocPort=20031,NumConn=100):
self.svr = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.svr.bind (('', LocPort))
self.svr.listen(NumConn)

def nextConnAddr(self):
if select.select([self.svr], [], [], None)[0]:
return self.svr.accept()
else:
raise 'SocketReceiver.rx.nextConnAddr','connection lost'

def rxThread(self,recvr):
thread.start_new_thread(newSession,(recvr,))

def close(self):
self.svr.close()

def newSession(conn):
sess = session(conn)
sess.run()

class session:
def __init__(self,conn,timeout=180.0):
self.conn = conn
self.conn.settimeout(timeout)

def recvblock(self,length):
block = []
size = length
while size > 0:
chunk = self.conn.recv(size)
if chunk:
block.append(chunk)
size = size - len(chunk)
else:
raise 'Session.recvblock','connection lost'
return ''.join(block)

def getsize(self):
length = self.recvblock(8)
return int(length)

def getdata(self,size):
return self.recvblock(size)

def run(self):
global COUNTER, TIME0
data = self.getdata(self.getsize())
if len(data) != 1000:
print 'Transmission error'
else:
COUNTER = COUNTER + 1
if TIME0 == 0.0:
TIME0 = time.time()
print '%i%s%0.3f' % (COUNTER,'\t',time.time()-TIME0)

rcvr = rx()
while 1:
rcvr.rxThread(rcvr.nextConnAddr()[0])

----------------------------------------------------------------------
 
K

Krister Liljedahl

Does anyone else experience problem with large numbers (>63) of
sockets under Windows? Can anyone else succesfully open 64 or more
sockets under Windows and poll them using select?

Sorry for the confusion. The questions above should have ended with
the words "in a single thread". I'm only concerned with not being able
to open more than 64 sockets per thread.

/Krister
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top