Commits

Denis Bilenko  committed ae6d5b5

remove baseserver.DEFAULT_MAX_ACCEPT variable; add get_listener() class methods on StreamServer and DatagramServer

  • Participants
  • Parent commits 6406c92

Comments (0)

Files changed (3)

File gevent/baseserver.py

 __all__ = ['BaseServer']
 
 
-DEFAULT_MAX_ACCEPT = 100
-
-
 class BaseServer(object):
     """An abstract base class that implements some common functionality for the servers in gevent.
 
     # Default is 100. Note, that in case of multiple working processes on the same
     # listening value, it should be set to a lower value. (pywsgi.WSGIServer sets it
     # to 1 when environ["wsgi.multiprocess"] is true)
-    max_accept = None
+    max_accept = 100
 
     _spawn = Greenlet.spawn
 
-    reuse_addr = 1
-
     # the default timeout that we wait for the client connections to close in stop()
     stop_timeout = 1
 
             self.set_handle(handle)
             self.delay = self.min_delay
             self.loop = gevent.get_hub().loop
-            if self.max_accept is None:
-                self.max_accept = DEFAULT_MAX_ACCEPT
             if self.max_accept < 1:
                 raise ValueError('max_accept must be positive int: %r' % (self.max_accept, ))
         except:

File gevent/pywsgi.py

 from gevent import socket
 import gevent
 from gevent.server import StreamServer
-from gevent import server
 from gevent.hub import GreenletExit
 
 
             self.environ['wsgi.errors'] = sys.stderr
 
     def set_max_accept(self):
-        if self.max_accept is None:
-            if self.environ.get('wsgi.multiprocess'):
-                self.max_accept = 1
-            else:
-                self.max_accept = server.DEFAULT_MAX_ACCEPT
+        if self.environ.get('wsgi.multiprocess'):
+            self.max_accept = 1
 
     def get_environ(self):
         return self.environ.copy()

File gevent/server.py

     # the default backlog to use if none was provided in __init__
     backlog = 256
 
+    reuse_addr = 1
+
     def __init__(self, listener, handle=None, backlog=None, spawn='default', **ssl_args):
         BaseServer.__init__(self, listener, handle=handle, spawn=spawn)
         try:
 
     def init_socket(self):
         if not hasattr(self, 'socket'):
-            self.socket = _tcp_listener(self.address, backlog=self.backlog,
-                                        reuse_addr=self.reuse_addr, family=self.family)
+            self.socket = self.get_listener(self.address, self.backlog, self.family)
             self.address = self.socket.getsockname()
         if self.ssl_args:
             self._handle = self.wrap_socket_and_handle
         else:
             self._handle = self.handle
 
+    @classmethod
+    def get_listener(self, address, backlog=None, family=None):
+        if backlog is None:
+            backlog = self.backlog
+        return _tcp_listener(address, backlog=backlog, reuse_addr=self.reuse_addr, family=family)
+
     def do_read(self):
         try:
             client_socket, address = self.socket.accept()
 class DatagramServer(BaseServer):
     """A UDP server"""
 
+    reuse_addr = 1
+
     def __init__(self, *args, **kwargs):
         BaseServer.__init__(self, *args, **kwargs)
         from gevent.coros import Semaphore
 
     def init_socket(self):
         if not hasattr(self, 'socket'):
-            self.socket = _udp_socket(self.address, reuse_addr=self.reuse_addr, family=self.family)
+            self.socket = self.get_listener(self.address, self.family)
             self.address = self.socket.getsockname()
         self._socket = self.socket
         try:
         except AttributeError:
             pass
 
+    @classmethod
+    def get_listener(self, address, family=None):
+        return _udp_socket(address, reuse_addr=self.reuse_addr, family=family)
+
     def do_read(self):
         try:
             data, address = self._socket.recvfrom(8192)