classification
Title: socket line buffering
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, ajaksu2, jbrouwers
Priority: normal Keywords:

Created on 2004-01-18 19:37 by jbrouwers, last changed 2010-08-19 00:35 by BreamoreBoy.

Messages (3)
msg60460 - (view) Author: Jean M. Brouwers (jbrouwers) Date: 2004-01-18 19:37
There is a bug in the line buffering code in the
Lib/socket.py module.

The write() method in the _fileobject class will flush
the buffered data at every call even if there no new
line character present in the data.

The problem is that the third part of the last if
statement will always be True if self._wbufsize equals 1.

<pre>
  if (self._wbufsize == 0 or
      self._wbufsize == 1 and '\n' in data or
      self._get_wbuf_len() >= self._wbufsize):
      self.flush()
</pre>

A possible fix would be the following:

<pre>
  if (self._wbufsize == 0 or
      self._wbufsize == 1 and '\n' in data or
      self._wbufsize > 1 and self._get_wbuf_len() >=
self._wbufsize):
      self.flush()
</pre>
msg82012 - (view) Author: Daniel Diniz (ajaksu2) Date: 2009-02-14 11:34
The code described by Jean is still present.
msg114312 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2010-08-19 00:35
I'm just wondering if the original code could be the cause of subtle bugs with socket.py, anyone?  (I'm no sockets guru). There's a proposed inline patch that's never been implemented, what do you (plural) make of it?.
History
Date User Action Args
2010-08-19 00:35:56BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
nosy: + BreamoreBoy

messages: + msg114312

stage: test needed -> patch review
2009-02-14 11:34:54ajaksu2settype: behavior
stage: test needed
messages: + msg82012
nosy: + ajaksu2
versions: + Python 2.6, - Python 2.3
2004-01-18 19:37:59jbrouwerscreate