Skip to content

Instantly share code, notes, and snippets.

@eklitzke
Created September 20, 2010 20:28
Show Gist options
  • Save eklitzke/588594 to your computer and use it in GitHub Desktop.
Save eklitzke/588594 to your computer and use it in GitHub Desktop.
def flush(self):
wout = self.__wbuf.getvalue()
wsz = len(wout)
# reset wbuf before write/flush to preserve state on underlying failure
self.__wbuf = StringIO()
# N.B.: Doing this string concatenation is WAY cheaper than making
# two separate calls to the underlying socket object. Socket writes in
# Python turn out to be REALLY expensive, but it seems to do a pretty
# good job of managing string buffer operations without excessive copies
buf = pack("!i", wsz) + wout
self.__trans.write(buf)
self.__trans.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment