bug 663096 update mochitest/pywebsocket to drain input to avoid RST r=biesi
authorPatrick McManus <mcmanus@ducksong.com>
Fri, 10 Jun 2011 16:52:30 -0400
changeset 71420 2146642133c4cc1ec110788bd352e028ec41be9a
parent 71419 30653af91633061c0179398f726606298d623e65
child 71421 76d7b28ca1ba4f27a9655873faf03ee914e20b13
push idunknown
push userunknown
push dateunknown
reviewersbiesi
bugs663096
milestone7.0a1
bug 663096 update mochitest/pywebsocket to drain input to avoid RST r=biesi
testing/mochitest/pywebsocket/README
testing/mochitest/pywebsocket/mod_pywebsocket/_stream_base.py
testing/mochitest/pywebsocket/mod_pywebsocket/_stream_hybi06.py
testing/mochitest/pywebsocket/mod_pywebsocket/util.py
testing/mochitest/pywebsocket/standalone.py
--- a/testing/mochitest/pywebsocket/README
+++ b/testing/mochitest/pywebsocket/README
@@ -1,15 +1,18 @@
 mod_pywebsocket http://pywebsocket.googlecode.com/svn
 version 489
 supporting ietf-07
 
 includes the following minor patch:: (first bit supports symlinked wsh
 files, the second allows python 2.5 to work)
 
+also includes patch for 663096 to drain input buffers before closing
+in order to avoid RST
+
 diff --git a/testing/mochitest/pywebsocket/mod_pywebsocket/dispatch.py b/testing/mochitest/pywebsocket/mod_pywebsocket/dispatch.py
 --- a/testing/mochitest/pywebsocket/mod_pywebsocket/dispatch.py
 +++ b/testing/mochitest/pywebsocket/mod_pywebsocket/dispatch.py
 @@ -60,17 +60,18 @@ def _normalize_path(path):
          path: the path to normalize.
  
      Path is converted to the absolute path.
      The input path can use either '\\' or '/' as the separator.
--- a/testing/mochitest/pywebsocket/mod_pywebsocket/_stream_base.py
+++ b/testing/mochitest/pywebsocket/mod_pywebsocket/_stream_base.py
@@ -124,16 +124,22 @@ class StreamBase(object):
 
         bytes = []
         while length > 0:
             new_bytes = self._read(length)
             bytes.append(new_bytes)
             length -= len(new_bytes)
         return ''.join(bytes)
 
+    def flushread(self):
+        try:
+          self._request.connection.flushread()
+        except:
+          pass
+
     def _read_until(self, delim_char):
         """Reads bytes until we encounter delim_char. The result will not
         contain delim_char.
 
         Raises:
             ConnectionTerminatedException: when read returns empty string.
         """
 
--- a/testing/mochitest/pywebsocket/mod_pywebsocket/_stream_hybi06.py
+++ b/testing/mochitest/pywebsocket/mod_pywebsocket/_stream_hybi06.py
@@ -386,16 +386,19 @@ class Stream(StreamBase):
                         'If a close frame has status code, the length of '
                         'status code must be 2 octet')
                 elif len(message) >= 2:
                     self._request.ws_close_code = struct.unpack(
                         '!H', message[0:2])[0]
                     self._request.ws_close_reason = message[2:].decode(
                         'utf-8', 'replace')
 
+                self._logger.debug('Initiated flush read')
+                self.flushread()
+
                 if self._request.server_terminated:
                     self._logger.debug(
                         'Received ack for server-initiated closing '
                         'handshake')
                     return None
 
                 self._logger.debug(
                     'Received client-initiated closing handshake')
--- a/testing/mochitest/pywebsocket/mod_pywebsocket/util.py
+++ b/testing/mochitest/pywebsocket/mod_pywebsocket/util.py
@@ -383,10 +383,20 @@ class DeflateConnection(object):
             if not read_data:
                 break
             self._inflater.append(read_data)
         return data
 
     def write(self, bytes):
         self._connection.write(self._deflater.compress_and_flush(bytes))
 
+    def flushread(self):
+        self._connection.setblocking(0)
+        while True:
+            try:
+              data = self._connection.read(1)
+              self._logger.debug('flushing unused byte %r', data)
+              if len(data) < 1:
+                break
+            except:
+              break
 
 # vi:sts=4 sw=4 et
--- a/testing/mochitest/pywebsocket/standalone.py
+++ b/testing/mochitest/pywebsocket/standalone.py
@@ -135,16 +135,18 @@ class _StandaloneConnection(object):
     def read(self, length):
         """Mimic mp_conn.read()."""
         return self._request_handler.rfile.read(length)
 
     def get_memorized_lines(self):
         """Get memorized lines."""
         return self._request_handler.rfile.get_memorized_lines()
 
+    def setblocking(self, blocking): 
+        self._request_handler.rfile._file._sock.setblocking(0)
 
 class _StandaloneRequest(object):
     """Mimic mod_python request."""
 
     def __init__(self, request_handler, use_tls):
         """Construct an instance.
 
         Args: