Fixing socket.makefile()
Alan Kennedy
alanmk at hotmail.com
Tue Aug 10 09:12:26 EDT 2004
[Bryan Olson]
> The problem is that makefile() returns a Python object that has
> its own local buffer. The recv() call reads directly from the
> socket, oblivious to any data queued in the file object's
> buffer. The problem is not limited to recv(); select(), and
> perhaps other calls, will ignore the buffer and look directly at
> the socket. Output buffering appears to have a similar problem.
and
> The Python Library Reference is silent on whether the
> socket.makefile operations are supposed to interact correctly
> with the direct socket operations. If they are supposed to play
> well together, then read() is wrong. If they are not, then
> readline() is absurdly slow.
I'm glad you asked these questions ;-)
I also am interested in the answers, because I'm just coming to end of
my implementation of cpython 2.3 compatible socket, select and asyncore
modules for jython, i.e. asynchronous socket support, using the new
java.nio APIs in jdk1.4+.
Points to make in relation to jython include
1. The problem you describe doesn't arise very often, I think. Most
users who use makefile() on sockets are going to use the file-based
interface exclusively and not the underlying socket interface.
2. The problem does not exist in jython, because jython implements the
socket.makefile() method by returning wrappers on the java.net.socket's
InputStream and OutputStream, meaning that calling either file or socket
interface sends data through the same underlying streams.
3. I am eager to have the behaviour of cpython explicitly defined, since
I am working hard to make my jython implementation 100% cpython
compatible, right down to the exceptions. I want all cpython socket code
to not know that it's running on jython.
4. I'm particularly interested in seeing documentation on how read and
write operations on socket.makefile()s should behave when the socket is
in non-blocking mode: Should it raise an exception? Which exception? The
same exception on every platform?
P.S. To those who know I've working on this for *ages* now: apologies
(Hi Irmen :-) My finances have prevented me from spending too much time
working on this voluntary project. However, you may be encouraged to
know that I now have it passing most of the cpython 2.3 test_socket.py
unit tests (including the ones that use select.select). It's only a
matter of a month or two more now .....
Out of interest: Does anyone know if developing asynch-socket support
for jython is the sort of work that might fall under the auspices of the
PSF grant scheme?
--
alan kennedy
------------------------------------------------------
email alan: http://xhaus.com/contact/alan
More information about the Python-list
mailing list