Skip to content

Commit

Permalink
Remove unused (unreachable) code from maxsockets.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Oct 26, 2017
1 parent 51ab8e3 commit 56e7af2
Showing 1 changed file with 9 additions and 65 deletions.
74 changes: 9 additions & 65 deletions src/zope/server/maxsockets.py
Expand Up @@ -11,80 +11,24 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Find max number of sockets allowed.
"""
# Medusa max_sockets module.
Find max number of sockets allowed.
.. caution:: These functions are all hard coded to return a constant value
of 100. Attempting to dynamically compute them by looping and creating
sockets until failure was very time consuming.
import socket
import select
"""
# Medusa max_sockets module.

# several factors here we might want to test:
# 1) max we can create
# 2) max we can bind
# 3) max we can listen on
# 4) max we can connect

def max_server_sockets():
# TODO: This should be a configuration value as it takes a long time to
# compute on Mac OSX
return 100
sl = []
while 1:
try:
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.bind (('',0))
s.listen(5)
sl.append (s)
except:
break
num = len(sl)
for s in sl:
s.close()
del sl
return num

def max_client_sockets():
# TODO: This should be a configuration value as it takes a long time to
# compute on Mac OSX
return 100
# make a server socket
server = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
server.bind (('', 9999))
server.listen (5)
sl = []
while 1:
try:
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.connect (('', 9999))
conn, addr = server.accept()
sl.append ((s,conn))
except:
break
num = len(sl)
for s,c in sl:
s.close()
c.close()
del sl
return num

def max_select_sockets():
# TODO: This should be a configuration value as it takes a long time to
# compute on Mac OSX
return 100
sl = []
while 1:
try:
num = len(sl)
for i in range(1 + len(sl) // 20):
# Increase exponentially.
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
s.bind (('',0))
s.listen(5)
sl.append (s)
select.select(sl,[],[],0)
except:
break
for s in sl:
s.close()
del sl
return num

max_server_sockets = max_client_sockets = max_select_sockets

0 comments on commit 56e7af2

Please sign in to comment.