File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ cdef inspect_isgenerator = inspect.isgenerator
6464cdef int has_SO_REUSEPORT = hasattr (socket, ' SO_REUSEPORT' )
6565cdef int SO_REUSEPORT = getattr (socket, ' SO_REUSEPORT' , 0 )
6666cdef int SO_BROADCAST = getattr (socket, ' SO_BROADCAST' )
67+ cdef int SOCK_NONBLOCK = getattr (socket, ' SOCK_NONBLOCK' , - 1 )
6768
6869cdef socket_gaierror = socket.gaierror
6970cdef socket_error = socket.error
Original file line number Diff line number Diff line change @@ -39,17 +39,23 @@ include "errors.pyx"
3939
4040
4141cdef _is_sock_stream(sock_type):
42- # Linux's socket.type is a bitmask that can include extra info
43- # about socket, therefore we can't do simple
44- # `sock_type == socket.SOCK_STREAM`.
45- return (sock_type & uv.SOCK_STREAM) == uv.SOCK_STREAM
42+ if SOCK_NONBLOCK == - 1 :
43+ return sock_type == uv.SOCK_STREAM
44+ else :
45+ # Linux's socket.type is a bitmask that can include extra info
46+ # about socket (like SOCK_NONBLOCK bit), therefore we can't do simple
47+ # `sock_type == socket.SOCK_STREAM`, see
48+ # https://github.com/torvalds/linux/blob/v4.13/include/linux/net.h#L77
49+ # for more details.
50+ return (sock_type & 0xF ) == uv.SOCK_STREAM
4651
4752
4853cdef _is_sock_dgram(sock_type):
49- # Linux's socket.type is a bitmask that can include extra info
50- # about socket, therefore we can't do simple
51- # `sock_type == socket.SOCK_DGRAM`.
52- return (sock_type & uv.SOCK_DGRAM) == uv.SOCK_DGRAM
54+ if SOCK_NONBLOCK == - 1 :
55+ return sock_type == uv.SOCK_DGRAM
56+ else :
57+ # Read the comment in `_is_sock_stream`.
58+ return (sock_type & 0xF ) == uv.SOCK_DGRAM
5359
5460
5561cdef isfuture(obj):
You can’t perform that action at this time.
0 commit comments