Commit cf2486a5 authored by Amos Latteier's avatar Amos Latteier

Redid socket limiting as per Jim's advice. Now HTTP, FTP, and PCGI severs will...

Redid socket limiting as per Jim's advice. Now HTTP, FTP, and PCGI severs will refuse to accept new connections once the connection limit is reached.
parent faee30d4
......@@ -142,6 +142,8 @@ from medusa import asyncore, asynchat, filesys
from FTPResponse import make_response
from FTPRequest import FTPRequest
from ZServer import CONNECTION_LIMIT
from cStringIO import StringIO
import string
import os
......@@ -617,4 +619,6 @@ class FTPServer(ftp_server):
print 'Incoming connection from %s:%d' % (addr[0], addr[1])
self.ftp_channel_class (self, conn, addr, self.module)
def readable(self):
return len(asyncore.socket_map) < CONNECTION_LIMIT
......@@ -120,16 +120,11 @@ from medusa.http_server import http_server, http_channel
from medusa import counter, producers, asyncore, max_sockets
from medusa.default_handler import split_path, unquote, get_header
from ZServer import CONNECTION_LIMIT, ZOPE_VERSION, ZSERVER_VERSION
CONTENT_LENGTH = regex.compile('Content-Length: \([0-9]+\)',regex.casefold)
CONNECTION = regex.compile ('Connection: \(.*\)', regex.casefold)
ZSERVER_VERSION='1.1b1'
try:
import App.version_txt
ZOPE_VERSION=App.version_txt.version_txt()
except:
ZOPE_VERSION='experimental'
# maps request some headers to environment variables.
# (those that don't start with 'HTTP_')
header2env={'content-length' : 'CONTENT_LENGTH',
......@@ -337,12 +332,10 @@ class zhttp_server(http_server):
"http server"
SERVER_IDENT='Zope/%s ZServer/%s' % (ZOPE_VERSION,ZSERVER_VERSION)
CONNECTION_LIMIT=max_sockets.max_select_sockets()
channel_class = zhttp_channel
def handle_accept(self):
if len(asyncore.socket_map.keys()) >= self.CONNECTION_LIMIT:
return
http_server.handle_accept(self)
def readable(self):
return self.accepting and \
len(asyncore.socket_map) < CONNECTION_LIMIT
......@@ -104,6 +104,8 @@ from medusa import asynchat, asyncore, logger
from medusa.counter import counter
from medusa.http_server import compute_timezone_for_log
from ZServer import CONNECTION_LIMIT
from PubCore import handle
from PubCore.ZEvent import Wakeup
from ZPublisher.HTTPResponse import HTTPResponse
......@@ -336,7 +338,10 @@ class PCGIServer(asyncore.dispatcher):
sys.stderr.write('warning: server accept() threw an exception\n')
return
self.channel_class(self, conn, addr)
def readable(self):
return len(asyncore.socket_map) < CONNECTION_LIMIT
def writable (self):
return 0
......
......@@ -83,6 +83,16 @@
#
##############################################################################
from medusa import max_sockets
CONNECTION_LIMIT=max_sockets.max_select_sockets()
ZSERVER_VERSION='1.1b1'
try:
import App.version_txt
ZOPE_VERSION=App.version_txt.version_txt()
except:
ZOPE_VERSION='experimental'
from medusa import resolver, logger, asyncore
from HTTPServer import zhttp_server, zhttp_handler
from PCGIServer import PCGIServer
......
......@@ -142,6 +142,8 @@ from medusa import asyncore, asynchat, filesys
from FTPResponse import make_response
from FTPRequest import FTPRequest
from ZServer import CONNECTION_LIMIT
from cStringIO import StringIO
import string
import os
......@@ -617,4 +619,6 @@ class FTPServer(ftp_server):
print 'Incoming connection from %s:%d' % (addr[0], addr[1])
self.ftp_channel_class (self, conn, addr, self.module)
def readable(self):
return len(asyncore.socket_map) < CONNECTION_LIMIT
......@@ -120,16 +120,11 @@ from medusa.http_server import http_server, http_channel
from medusa import counter, producers, asyncore, max_sockets
from medusa.default_handler import split_path, unquote, get_header
from ZServer import CONNECTION_LIMIT, ZOPE_VERSION, ZSERVER_VERSION
CONTENT_LENGTH = regex.compile('Content-Length: \([0-9]+\)',regex.casefold)
CONNECTION = regex.compile ('Connection: \(.*\)', regex.casefold)
ZSERVER_VERSION='1.1b1'
try:
import App.version_txt
ZOPE_VERSION=App.version_txt.version_txt()
except:
ZOPE_VERSION='experimental'
# maps request some headers to environment variables.
# (those that don't start with 'HTTP_')
header2env={'content-length' : 'CONTENT_LENGTH',
......@@ -337,12 +332,10 @@ class zhttp_server(http_server):
"http server"
SERVER_IDENT='Zope/%s ZServer/%s' % (ZOPE_VERSION,ZSERVER_VERSION)
CONNECTION_LIMIT=max_sockets.max_select_sockets()
channel_class = zhttp_channel
def handle_accept(self):
if len(asyncore.socket_map.keys()) >= self.CONNECTION_LIMIT:
return
http_server.handle_accept(self)
def readable(self):
return self.accepting and \
len(asyncore.socket_map) < CONNECTION_LIMIT
......@@ -104,6 +104,8 @@ from medusa import asynchat, asyncore, logger
from medusa.counter import counter
from medusa.http_server import compute_timezone_for_log
from ZServer import CONNECTION_LIMIT
from PubCore import handle
from PubCore.ZEvent import Wakeup
from ZPublisher.HTTPResponse import HTTPResponse
......@@ -336,7 +338,10 @@ class PCGIServer(asyncore.dispatcher):
sys.stderr.write('warning: server accept() threw an exception\n')
return
self.channel_class(self, conn, addr)
def readable(self):
return len(asyncore.socket_map) < CONNECTION_LIMIT
def writable (self):
return 0
......
......@@ -83,6 +83,16 @@
#
##############################################################################
from medusa import max_sockets
CONNECTION_LIMIT=max_sockets.max_select_sockets()
ZSERVER_VERSION='1.1b1'
try:
import App.version_txt
ZOPE_VERSION=App.version_txt.version_txt()
except:
ZOPE_VERSION='experimental'
from medusa import resolver, logger, asyncore
from HTTPServer import zhttp_server, zhttp_handler
from PCGIServer import PCGIServer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment