@@ -82,26 +82,6 @@ def _set_reuseport(sock):
8282 'SO_REUSEPORT defined but not implemented.' )
8383
8484
85- def _is_stream_socket (sock_type ):
86- if hasattr (socket , 'SOCK_NONBLOCK' ):
87- # Linux's socket.type is a bitmask that can include extra info
88- # about socket (like SOCK_NONBLOCK bit), therefore we can't do simple
89- # `sock_type == socket.SOCK_STREAM`, see
90- # https://github.com/torvalds/linux/blob/v4.13/include/linux/net.h#L77
91- # for more details.
92- return (sock_type & 0xF ) == socket .SOCK_STREAM
93- else :
94- return sock_type == socket .SOCK_STREAM
95-
96-
97- def _is_dgram_socket (sock_type ):
98- if hasattr (socket , 'SOCK_NONBLOCK' ):
99- # See the comment in `_is_stream_socket`.
100- return (sock_type & 0xF ) == socket .SOCK_DGRAM
101- else :
102- return sock_type == socket .SOCK_DGRAM
103-
104-
10585def _ipaddr_info (host , port , family , type , proto ):
10686 # Try to skip getaddrinfo if "host" is already an IP. Users might have
10787 # handled name resolution in their own code and pass in resolved IPs.
@@ -112,9 +92,9 @@ def _ipaddr_info(host, port, family, type, proto):
11292 host is None :
11393 return None
11494
115- if _is_stream_socket ( type ) :
95+ if type == socket . SOCK_STREAM :
11696 proto = socket .IPPROTO_TCP
117- elif _is_dgram_socket ( type ) :
97+ elif type == socket . SOCK_DGRAM :
11898 proto = socket .IPPROTO_UDP
11999 else :
120100 return None
@@ -759,7 +739,7 @@ async def create_connection(self, protocol_factory, host=None, port=None,
759739 if sock is None :
760740 raise ValueError (
761741 'host and port was not specified and no sock specified' )
762- if not _is_stream_socket ( sock .type ) :
742+ if sock .type != socket . SOCK_STREAM :
763743 # We allow AF_INET, AF_INET6, AF_UNIX as long as they
764744 # are SOCK_STREAM.
765745 # We support passing AF_UNIX sockets even though we have
@@ -809,7 +789,7 @@ async def create_datagram_endpoint(self, protocol_factory,
809789 allow_broadcast = None , sock = None ):
810790 """Create datagram connection."""
811791 if sock is not None :
812- if not _is_dgram_socket ( sock .type ) :
792+ if sock .type != socket . SOCK_DGRAM :
813793 raise ValueError (
814794 f'A UDP Socket was expected, got { sock !r} ' )
815795 if (local_addr or remote_addr or
@@ -1037,7 +1017,7 @@ async def create_server(self, protocol_factory, host=None, port=None,
10371017 else :
10381018 if sock is None :
10391019 raise ValueError ('Neither host/port nor sock were specified' )
1040- if not _is_stream_socket ( sock .type ) :
1020+ if sock .type != socket . SOCK_STREAM :
10411021 raise ValueError (f'A Stream Socket was expected, got { sock !r} ' )
10421022 sockets = [sock ]
10431023
@@ -1060,7 +1040,7 @@ async def connect_accepted_socket(self, protocol_factory, sock,
10601040 This method is a coroutine. When completed, the coroutine
10611041 returns a (transport, protocol) pair.
10621042 """
1063- if not _is_stream_socket ( sock .type ) :
1043+ if sock .type != socket . SOCK_STREAM :
10641044 raise ValueError (f'A Stream Socket was expected, got { sock !r} ' )
10651045
10661046 transport , protocol = await self ._create_connection_transport (
0 commit comments