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 ...@@ -142,6 +142,8 @@ from medusa import asyncore, asynchat, filesys
from FTPResponse import make_response from FTPResponse import make_response
from FTPRequest import FTPRequest from FTPRequest import FTPRequest
from ZServer import CONNECTION_LIMIT
from cStringIO import StringIO from cStringIO import StringIO
import string import string
import os import os
...@@ -617,4 +619,6 @@ class FTPServer(ftp_server): ...@@ -617,4 +619,6 @@ class FTPServer(ftp_server):
print 'Incoming connection from %s:%d' % (addr[0], addr[1]) print 'Incoming connection from %s:%d' % (addr[0], addr[1])
self.ftp_channel_class (self, conn, addr, self.module) 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 ...@@ -120,16 +120,11 @@ from medusa.http_server import http_server, http_channel
from medusa import counter, producers, asyncore, max_sockets from medusa import counter, producers, asyncore, max_sockets
from medusa.default_handler import split_path, unquote, get_header 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) CONTENT_LENGTH = regex.compile('Content-Length: \([0-9]+\)',regex.casefold)
CONNECTION = regex.compile ('Connection: \(.*\)', 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. # maps request some headers to environment variables.
# (those that don't start with 'HTTP_') # (those that don't start with 'HTTP_')
header2env={'content-length' : 'CONTENT_LENGTH', header2env={'content-length' : 'CONTENT_LENGTH',
...@@ -337,12 +332,10 @@ class zhttp_server(http_server): ...@@ -337,12 +332,10 @@ class zhttp_server(http_server):
"http server" "http server"
SERVER_IDENT='Zope/%s ZServer/%s' % (ZOPE_VERSION,ZSERVER_VERSION) SERVER_IDENT='Zope/%s ZServer/%s' % (ZOPE_VERSION,ZSERVER_VERSION)
CONNECTION_LIMIT=max_sockets.max_select_sockets()
channel_class = zhttp_channel channel_class = zhttp_channel
def handle_accept(self): def readable(self):
if len(asyncore.socket_map.keys()) >= self.CONNECTION_LIMIT: return self.accepting and \
return len(asyncore.socket_map) < CONNECTION_LIMIT
http_server.handle_accept(self)
...@@ -104,6 +104,8 @@ from medusa import asynchat, asyncore, logger ...@@ -104,6 +104,8 @@ from medusa import asynchat, asyncore, logger
from medusa.counter import counter from medusa.counter import counter
from medusa.http_server import compute_timezone_for_log from medusa.http_server import compute_timezone_for_log
from ZServer import CONNECTION_LIMIT
from PubCore import handle from PubCore import handle
from PubCore.ZEvent import Wakeup from PubCore.ZEvent import Wakeup
from ZPublisher.HTTPResponse import HTTPResponse from ZPublisher.HTTPResponse import HTTPResponse
...@@ -337,6 +339,9 @@ class PCGIServer(asyncore.dispatcher): ...@@ -337,6 +339,9 @@ class PCGIServer(asyncore.dispatcher):
return return
self.channel_class(self, conn, addr) self.channel_class(self, conn, addr)
def readable(self):
return len(asyncore.socket_map) < CONNECTION_LIMIT
def writable (self): def writable (self):
return 0 return 0
......
...@@ -83,6 +83,16 @@ ...@@ -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 medusa import resolver, logger, asyncore
from HTTPServer import zhttp_server, zhttp_handler from HTTPServer import zhttp_server, zhttp_handler
from PCGIServer import PCGIServer from PCGIServer import PCGIServer
......
...@@ -142,6 +142,8 @@ from medusa import asyncore, asynchat, filesys ...@@ -142,6 +142,8 @@ from medusa import asyncore, asynchat, filesys
from FTPResponse import make_response from FTPResponse import make_response
from FTPRequest import FTPRequest from FTPRequest import FTPRequest
from ZServer import CONNECTION_LIMIT
from cStringIO import StringIO from cStringIO import StringIO
import string import string
import os import os
...@@ -617,4 +619,6 @@ class FTPServer(ftp_server): ...@@ -617,4 +619,6 @@ class FTPServer(ftp_server):
print 'Incoming connection from %s:%d' % (addr[0], addr[1]) print 'Incoming connection from %s:%d' % (addr[0], addr[1])
self.ftp_channel_class (self, conn, addr, self.module) 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 ...@@ -120,16 +120,11 @@ from medusa.http_server import http_server, http_channel
from medusa import counter, producers, asyncore, max_sockets from medusa import counter, producers, asyncore, max_sockets
from medusa.default_handler import split_path, unquote, get_header 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) CONTENT_LENGTH = regex.compile('Content-Length: \([0-9]+\)',regex.casefold)
CONNECTION = regex.compile ('Connection: \(.*\)', 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. # maps request some headers to environment variables.
# (those that don't start with 'HTTP_') # (those that don't start with 'HTTP_')
header2env={'content-length' : 'CONTENT_LENGTH', header2env={'content-length' : 'CONTENT_LENGTH',
...@@ -337,12 +332,10 @@ class zhttp_server(http_server): ...@@ -337,12 +332,10 @@ class zhttp_server(http_server):
"http server" "http server"
SERVER_IDENT='Zope/%s ZServer/%s' % (ZOPE_VERSION,ZSERVER_VERSION) SERVER_IDENT='Zope/%s ZServer/%s' % (ZOPE_VERSION,ZSERVER_VERSION)
CONNECTION_LIMIT=max_sockets.max_select_sockets()
channel_class = zhttp_channel channel_class = zhttp_channel
def handle_accept(self): def readable(self):
if len(asyncore.socket_map.keys()) >= self.CONNECTION_LIMIT: return self.accepting and \
return len(asyncore.socket_map) < CONNECTION_LIMIT
http_server.handle_accept(self)
...@@ -104,6 +104,8 @@ from medusa import asynchat, asyncore, logger ...@@ -104,6 +104,8 @@ from medusa import asynchat, asyncore, logger
from medusa.counter import counter from medusa.counter import counter
from medusa.http_server import compute_timezone_for_log from medusa.http_server import compute_timezone_for_log
from ZServer import CONNECTION_LIMIT
from PubCore import handle from PubCore import handle
from PubCore.ZEvent import Wakeup from PubCore.ZEvent import Wakeup
from ZPublisher.HTTPResponse import HTTPResponse from ZPublisher.HTTPResponse import HTTPResponse
...@@ -337,6 +339,9 @@ class PCGIServer(asyncore.dispatcher): ...@@ -337,6 +339,9 @@ class PCGIServer(asyncore.dispatcher):
return return
self.channel_class(self, conn, addr) self.channel_class(self, conn, addr)
def readable(self):
return len(asyncore.socket_map) < CONNECTION_LIMIT
def writable (self): def writable (self):
return 0 return 0
......
...@@ -83,6 +83,16 @@ ...@@ -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 medusa import resolver, logger, asyncore
from HTTPServer import zhttp_server, zhttp_handler from HTTPServer import zhttp_server, zhttp_handler
from PCGIServer import PCGIServer 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