1212import os
1313import sys
1414
15- from curio import Kernel , Event , spawn , socket , ssl
15+ from curio import Event , spawn , socket , ssl , run
1616
1717import h2 .config
1818import h2 .connection
2323READ_CHUNK_SIZE = 8192
2424
2525
26- def create_listening_ssl_socket (address , certfile , keyfile ):
26+ async def create_listening_ssl_socket (address , certfile , keyfile ):
2727 """
2828 Create and return a listening TLS socket on a given address.
2929 """
@@ -37,7 +37,7 @@ def create_listening_ssl_socket(address, certfile, keyfile):
3737
3838 sock = socket .socket ()
3939 sock .setsockopt (socket .SOL_SOCKET , socket .SO_REUSEADDR , 1 )
40- sock = ssl_context .wrap_socket (sock )
40+ sock = await ssl_context .wrap_socket (sock )
4141 sock .bind (address )
4242 sock .listen ()
4343
@@ -48,7 +48,7 @@ async def h2_server(address, root, certfile, keyfile):
4848 """
4949 Create an HTTP/2 server at the given address.
5050 """
51- sock = create_listening_ssl_socket (address , certfile , keyfile )
51+ sock = await create_listening_ssl_socket (address , certfile , keyfile )
5252 print ("Now listening on %s:%d" % address )
5353
5454 async with sock :
@@ -196,13 +196,11 @@ async def window_updated(self, event):
196196
197197if __name__ == '__main__' :
198198 host = sys .argv [2 ] if len (sys .argv ) > 2 else "localhost"
199- kernel = Kernel (with_monitor = True )
200199 print ("Try GETting:" )
201200 print (" On OSX after 'brew install curl --with-c-ares --with-libidn --with-nghttp2 --with-openssl':" )
202201 print ("/usr/local/opt/curl/bin/curl --tlsv1.2 --http2 -k https://localhost:5000/bundle.js" )
203202 print ("Or open a browser to: https://localhost:5000/" )
204203 print (" (Accept all the warnings)" )
205- kernel .run (h2_server ((host , 5000 ),
206- sys .argv [1 ],
207- "{}.crt.pem" .format (host ),
208- "{}.key" .format (host )))
204+ run (h2_server ((host , 5000 ), sys .argv [1 ],
205+ "{}.crt.pem" .format (host ),
206+ "{}.key" .format (host )), with_monitor = True )
0 commit comments