Author martin.panter
Recipients martin.panter
Date 2016-04-09.12:19:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1460204395.72.0.250418211057.issue26721@psf.upfronthosting.co.za>
In-reply-to
Content
This is a follow-on from Issue 24291. Currently, for stream servers (as opposed to datagram servers), the wfile attribute is a raw SocketIO object. This means that wfile.write() is a simple wrapper around socket.send(), and can do partial writes.

There is a comment inherited from Python 2 that reads:

# . . . we make
# wfile unbuffered because (a) often after a write() we want to
# read and we need to flush the line; (b) big writes to unbuffered
# files are typically optimized by stdio even when big reads
# aren't.

Python 2 only has one kind of “file” object, and it seems partial writes are impossible: <https://docs.python.org/2/library/stdtypes.html#file.write>. But in Python 3, unbuffered mode means that the lower-level RawIOBase API is involved rather than the higher-level BufferedIOBase API.

I propose to change the “wfile” attribute to be a BufferedIOBase object, yet still be “unbuffered”. This could be implemented with a class that looks something like

class _SocketWriter(BufferedIOBase):
    """Simple writable BufferedIOBase implementation for a socket
    
    Does not hold data in a buffer, avoiding any need to call flush()."""
    def write(self, b):
        self._sock.sendall(b)
        return len(b)
History
Date User Action Args
2016-04-09 12:19:55martin.pantersetrecipients: + martin.panter
2016-04-09 12:19:55martin.pantersetmessageid: <1460204395.72.0.250418211057.issue26721@psf.upfronthosting.co.za>
2016-04-09 12:19:55martin.panterlinkissue26721 messages
2016-04-09 12:19:55martin.pantercreate