socket vs _socketobject

T

ts1

[ Sorry if you see this message twice (or more), mail.python.org
seems rejecting my posts.]

Hello,

I've found strangeness in socket.

Normal socket is wrapped by Python code in socket.py.
<socket._socketobject object at 0xb7d23a04>

However, socket created with fromfd() is not wrapped, raw socket
object
from socketmodule.c.
<socket object, fd=4, family=2, type=1, protocol=0>

Is this intended?
If so, why?

(0 is not really a socket, but it is irrelevant here, this is just an
example)

When makefile() of wrapped socket is called, it returns file-like
object written in Python. It supports timeout. This is good.
When makefile() of raw socket is called, it returns real file object,
which knows nothing about socket's timeout. If timeout was set on the
socket, calls to read() etc to the file can raise EAGAIN, since
O_NONBLOCK is inherited to the dup'ed fd and PyFile doesn't know about
it.
(Document states socket must be blocking mode when calling makefile
but nothing about timeout.)

I can workaround this problem by adding something like
sock = socket.socket(_sock=sock)
but this is ugly.

Python versions:
'2.5.1 (r251:54863, May 2 2007, 16:56:35) \n[GCC 4.1.2 (Ubuntu
4.1.2-0ubuntu4)]''linux2'

Takeshi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top