Message305432
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 |
|
Date |
User |
Action |
Args |
2017-11-02 15:48:27 | vmagamedov | set | recipients:
+ vmagamedov, vstinner, j1m, socketpair, python-dev, yselivanov |
2017-11-02 15:48:27 | vmagamedov | set | messageid: <1509637707.62.0.213398074469.issue27456@psf.upfronthosting.co.za> |
2017-11-02 15:48:27 | vmagamedov | link | issue27456 messages |
2017-11-02 15:48:27 | vmagamedov | create | |
|