Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"lag" when recv() reads multiple occurrences of delimiter #4

Open
accounts01 opened this issue Nov 26, 2011 · 1 comment
Open

"lag" when recv() reads multiple occurrences of delimiter #4

accounts01 opened this issue Nov 26, 2011 · 1 comment

Comments

@accounts01
Copy link

given the current definition of _read_until(), if recv() reads multiple occurrences of the frame-ending delimiter, only the content of the frame ending at the first delimiter is handled right away (by calback())... the remaining content will only be handled the next time _read_until() is triggered (e.g., by an incoming socket message or heartbeat)... so you basically get sort of a lag situation where new messages only get handled when newer ones come in...

my _read_until() addresses this... it also includes the fix from https://github.com/mtah/python-websocket/issues/1

def _read_until(self, delimiter, callback):
      def lookForAndHandleCompletedFrame():
          pos = self._read_buffer.find(delimiter)
          if pos >= 0:
              pos += len(delimiter)
              data = self._read_buffer[:pos]
              self._read_buffer = self._read_buffer[pos:]
              if data:
                 callback(data)
                 lookForAndHandleCompletedFrame()

      self._read_buffer += self.recv(4096)
      lookForAndHandleCompletedFrame()

enjoy!

@accounts01
Copy link
Author

solution in first post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant