Mercurial > p > roundup > code
comparison roundup/scripts/roundup_server.py @ 4273:0a684518d609
More SSL fixes.
SSL wants the underlying socket non-blocking. So we don't call
socket.setdefaulttimeout in case of SSL. This apparently now never
raises a WantReadError from SSL. This also fixes a case where a
WantReadError is raised and apparently the bytes already read are
dropped (seems the WantReadError is really an error, not just an
indication to retry).
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Tue, 13 Oct 2009 09:05:21 +0000 |
| parents | 6432c9bfd385 |
| children | 0c024cf74252 |
comparison
equal
deleted
inserted
replaced
| 4272:05600cc5e4af | 4273:0a684518d609 |
|---|---|
| 122 def __init__(self, fileobj): | 122 def __init__(self, fileobj): |
| 123 self.__fileobj = fileobj | 123 self.__fileobj = fileobj |
| 124 | 124 |
| 125 def readline(self, *args): | 125 def readline(self, *args): |
| 126 """ SSL.Connection can return WantRead """ | 126 """ SSL.Connection can return WantRead """ |
| 127 line = None | 127 while True: |
| 128 while not line: | |
| 129 try: | 128 try: |
| 130 line = self.__fileobj.readline(*args) | 129 return self.__fileobj.readline(*args) |
| 131 except SSL.WantReadError: | 130 except SSL.WantReadError: |
| 132 sleep (.1) | 131 sleep (.1) |
| 133 line = None | |
| 134 return line | |
| 135 | 132 |
| 136 def read(self, *args): | 133 def read(self, *args): |
| 137 """ SSL.Connection can return WantRead """ | 134 """ SSL.Connection can return WantRead """ |
| 138 while True: | 135 while True: |
| 139 try: | 136 try: |
| 594 CONFIG = self | 591 CONFIG = self |
| 595 | 592 |
| 596 if self["SSL"]: | 593 if self["SSL"]: |
| 597 base_server = SecureHTTPServer | 594 base_server = SecureHTTPServer |
| 598 else: | 595 else: |
| 596 # time out after a minute if we can | |
| 597 # This sets the socket to non-blocking. SSL needs a blocking | |
| 598 # socket, so we do this only for non-SSL connections. | |
| 599 if hasattr(socket, 'setdefaulttimeout'): | |
| 600 socket.setdefaulttimeout(60) | |
| 599 base_server = BaseHTTPServer.HTTPServer | 601 base_server = BaseHTTPServer.HTTPServer |
| 600 | 602 |
| 601 # obtain request server class | 603 # obtain request server class |
| 602 if self["MULTIPROCESS"] not in MULTIPROCESS_TYPES: | 604 if self["MULTIPROCESS"] not in MULTIPROCESS_TYPES: |
| 603 print _("Multiprocess mode \"%s\" is not available, " | 605 print _("Multiprocess mode \"%s\" is not available, " |
| 815 | 817 |
| 816 undefined = [] | 818 undefined = [] |
| 817 def run(port=undefined, success_message=None): | 819 def run(port=undefined, success_message=None): |
| 818 ''' Script entry point - handle args and figure out what to to. | 820 ''' Script entry point - handle args and figure out what to to. |
| 819 ''' | 821 ''' |
| 820 # time out after a minute if we can | |
| 821 if hasattr(socket, 'setdefaulttimeout'): | |
| 822 socket.setdefaulttimeout(60) | |
| 823 | |
| 824 config = ServerConfig() | 822 config = ServerConfig() |
| 825 # additional options | 823 # additional options |
| 826 short_options = "hvS" | 824 short_options = "hvS" |
| 827 if RoundupService: | 825 if RoundupService: |
| 828 short_options += 'c' | 826 short_options += 'c' |
