File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ cdef inspect_isgenerator = inspect.isgenerator
64
64
cdef int has_SO_REUSEPORT = hasattr (socket, ' SO_REUSEPORT' )
65
65
cdef int SO_REUSEPORT = getattr (socket, ' SO_REUSEPORT' , 0 )
66
66
cdef int SO_BROADCAST = getattr (socket, ' SO_BROADCAST' )
67
+ cdef int SOCK_NONBLOCK = getattr (socket, ' SOCK_NONBLOCK' , - 1 )
67
68
68
69
cdef socket_gaierror = socket.gaierror
69
70
cdef socket_error = socket.error
Original file line number Diff line number Diff line change @@ -39,17 +39,23 @@ include "errors.pyx"
39
39
40
40
41
41
cdef _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
46
51
47
52
48
53
cdef _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
53
59
54
60
55
61
cdef isfuture(obj):
You can’t perform that action at this time.
0 commit comments