Author vmagamedov
Recipients j1m, python-dev, socketpair, vmagamedov, vstinner, yselivanov
Date 2017-11-02.15:48:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1509637707.62.0.213398074469.issue27456@psf.upfronthosting.co.za>
In-reply-to
Content
Seems like this fix is incomplete. It contains this check:

    sock.type == socket.SOCK_STREAM

But sock.type is not only a type (at least in Linux and FreeBSD), it also may contain SOCK_NONBLOCK and SOCK_CLOEXEC flags. So I'm hitting the same problem: on the Linux in asyncio I have:

    > sock.type == socket.SOCK_STREAM | socket.SOCK_NONBLOCK == 2049
    True

So this check isn't working and TCP_NODELAY still disabled by default.

Links:
- http://man7.org/linux/man-pages/man2/socket.2.html
- https://github.com/torvalds/linux/blob/v4.13/include/linux/net.h#L77
- https://github.com/freebsd/freebsd/blob/stable/11/sys/sys/socket.h#L110

Linux has SOCK_TYPE_MASK definition equal to 0xf, but I can't find such definition in the FreeBSD sources. And I don't know how to reliably and with forward compatibility check sock.type without calling getsockopt() syscall.

Currently I have a fix in my project, where:

    _sock_type_mask = 0xf if hasattr(socket, 'SOCK_NONBLOCK') else 0xffffffff

And then in my own _set_nodelay(sock) function:

    sock.type & _sock_type_mask == socket.SOCK_STREAM

Should I make a pull request or someone knows more reliable check? Or it is ok to add one more syscall?

    sock.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE) == socket.SOCK_STREAM
History
Date User Action Args
2017-11-02 15:48:27vmagamedovsetrecipients: + vmagamedov, vstinner, j1m, socketpair, python-dev, yselivanov
2017-11-02 15:48:27vmagamedovsetmessageid: <1509637707.62.0.213398074469.issue27456@psf.upfronthosting.co.za>
2017-11-02 15:48:27vmagamedovlinkissue27456 messages
2017-11-02 15:48:27vmagamedovcreate