@@ -771,9 +771,13 @@ def create_connection(self, protocol_factory, host=None, port=None, *,
771
771
raise OSError ('Multiple exceptions: {}' .format (
772
772
', ' .join (str (exc ) for exc in exceptions )))
773
773
774
- elif sock is None :
775
- raise ValueError (
776
- 'host and port was not specified and no sock specified' )
774
+ else :
775
+ if sock is None :
776
+ raise ValueError (
777
+ 'host and port was not specified and no sock specified' )
778
+ if sock .family not in {socket .AF_INET , socket .AF_INET6 }:
779
+ raise ValueError (
780
+ 'A TCP Stream Socket was expected, got {!r}' .format (sock ))
777
781
778
782
transport , protocol = yield from self ._create_connection_transport (
779
783
sock , protocol_factory , ssl , server_hostname )
@@ -1027,6 +1031,9 @@ def create_server(self, protocol_factory, host=None, port=None,
1027
1031
else :
1028
1032
if sock is None :
1029
1033
raise ValueError ('Neither host/port nor sock were specified' )
1034
+ if sock .family not in {socket .AF_INET , socket .AF_INET6 }:
1035
+ raise ValueError (
1036
+ 'A TCP Stream Socket was expected, got {!r}' .format (sock ))
1030
1037
sockets = [sock ]
1031
1038
1032
1039
server = Server (self , sockets )
@@ -1048,6 +1055,9 @@ def connect_accepted_socket(self, protocol_factory, sock, *, ssl=None):
1048
1055
This method is a coroutine. When completed, the coroutine
1049
1056
returns a (transport, protocol) pair.
1050
1057
"""
1058
+ if sock .family not in {socket .AF_INET , socket .AF_INET6 }:
1059
+ raise ValueError (
1060
+ 'A TCP Stream Socket was expected, got {!r}' .format (sock ))
1051
1061
transport , protocol = yield from self ._create_connection_transport (
1052
1062
sock , protocol_factory , ssl , '' , server_side = True )
1053
1063
if self ._debug :
0 commit comments