@@ -1041,8 +1041,27 @@ cdef class Loop:
1041
1041
system.addrinfo * lai
1042
1042
UVTCPTransport tr
1043
1043
1044
- if ssl is not None :
1045
- raise NotImplementedError (' SSL is not yet supported' )
1044
+ object app_protocol
1045
+ object protocol
1046
+ object ssl_waiter
1047
+
1048
+ app_protocol = protocol = protocol_factory()
1049
+ ssl_waiter = None
1050
+ if ssl:
1051
+ if server_hostname is None :
1052
+ if not host:
1053
+ raise ValueError (' You must set server_hostname '
1054
+ ' when using ssl without a host' )
1055
+ server_hostname = host
1056
+
1057
+ ssl_waiter = aio_Future(loop = self )
1058
+ sslcontext = None if isinstance (ssl, bool ) else ssl
1059
+ protocol = aio_SSLProtocol(
1060
+ self , app_protocol, sslcontext, ssl_waiter,
1061
+ False , server_hostname)
1062
+ else :
1063
+ if server_hostname is not None :
1064
+ raise ValueError (' server_hostname is only meaningful with ssl' )
1046
1065
1047
1066
if host is not None or port is not None :
1048
1067
f1 = self ._getaddrinfo(host, port, family,
@@ -1075,8 +1094,6 @@ cdef class Loop:
1075
1094
raise OSError (
1076
1095
' getaddrinfo() returned empty list for local_addr' )
1077
1096
1078
- protocol = protocol_factory()
1079
-
1080
1097
exceptions = []
1081
1098
rai = ai_remote.data
1082
1099
while rai is not NULL :
@@ -1146,7 +1163,11 @@ cdef class Loop:
1146
1163
tr._close()
1147
1164
raise
1148
1165
1149
- return tr, protocol
1166
+ if ssl:
1167
+ await ssl_waiter
1168
+ return protocol._app_transport, app_protocol
1169
+ else :
1170
+ return tr, protocol
1150
1171
1151
1172
@aio_coroutine
1152
1173
async def create_unix_server(self , protocol_factory, str path = None ,
@@ -1204,10 +1225,27 @@ cdef class Loop:
1204
1225
ssl = None , sock = None ,
1205
1226
server_hostname = None ):
1206
1227
1207
- cdef UVPipeTransport tr
1208
-
1209
- if ssl is not None :
1210
- raise NotImplementedError (' SSL is not yet supported' )
1228
+ cdef:
1229
+ UVPipeTransport tr
1230
+ object app_protocol
1231
+ object protocol
1232
+ object ssl_waiter
1233
+
1234
+ app_protocol = protocol = protocol_factory()
1235
+ ssl_waiter = None
1236
+ if ssl:
1237
+ if server_hostname is None :
1238
+ raise ValueError (' You must set server_hostname '
1239
+ ' when using ssl without a host' )
1240
+
1241
+ ssl_waiter = aio_Future(loop = self )
1242
+ sslcontext = None if isinstance (ssl, bool ) else ssl
1243
+ protocol = aio_SSLProtocol(
1244
+ self , app_protocol, sslcontext, ssl_waiter,
1245
+ False , server_hostname)
1246
+ else :
1247
+ if server_hostname is not None :
1248
+ raise ValueError (' server_hostname is only meaningful with ssl' )
1211
1249
1212
1250
if path is not None :
1213
1251
if isinstance (path, str ):
@@ -1217,7 +1255,6 @@ cdef class Loop:
1217
1255
raise ValueError (
1218
1256
' path and sock can not be specified at the same time' )
1219
1257
1220
- protocol = protocol_factory()
1221
1258
waiter = aio_Future(loop = self )
1222
1259
tr = UVPipeTransport.new(self , protocol, None , waiter)
1223
1260
tr.connect(path)
@@ -1236,7 +1273,6 @@ cdef class Loop:
1236
1273
' A UNIX Domain Socket was expected, got {!r}' .format(sock))
1237
1274
1238
1275
waiter = aio_Future(loop = self )
1239
- protocol = protocol_factory()
1240
1276
tr = UVPipeTransport.new(self , protocol, None , waiter)
1241
1277
try :
1242
1278
# libuv will make socket non-blocking
@@ -1249,7 +1285,11 @@ cdef class Loop:
1249
1285
tr._close()
1250
1286
raise
1251
1287
1252
- return tr, protocol
1288
+ if ssl:
1289
+ await ssl_waiter
1290
+ return protocol._app_transport, app_protocol
1291
+ else :
1292
+ return tr, protocol
1253
1293
1254
1294
def default_exception_handler (self , context ):
1255
1295
message = context.get(' message' )
0 commit comments