Created
September 20, 2010 20:28
-
-
Save eklitzke/588594 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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