Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions examples/curio/curio-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import os
import sys

from curio import Kernel, Event, spawn, socket, ssl
from curio import Event, spawn, socket, ssl, run

import h2.config
import h2.connection
Expand All @@ -23,7 +23,7 @@
READ_CHUNK_SIZE = 8192


def create_listening_ssl_socket(address, certfile, keyfile):
async def create_listening_ssl_socket(address, certfile, keyfile):
"""
Create and return a listening TLS socket on a given address.
"""
Expand All @@ -37,7 +37,7 @@ def create_listening_ssl_socket(address, certfile, keyfile):

sock = socket.socket()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock = ssl_context.wrap_socket(sock)
sock = await ssl_context.wrap_socket(sock)
sock.bind(address)
sock.listen()

Expand All @@ -48,7 +48,7 @@ async def h2_server(address, root, certfile, keyfile):
"""
Create an HTTP/2 server at the given address.
"""
sock = create_listening_ssl_socket(address, certfile, keyfile)
sock = await create_listening_ssl_socket(address, certfile, keyfile)
print("Now listening on %s:%d" % address)

async with sock:
Expand Down Expand Up @@ -196,13 +196,11 @@ async def window_updated(self, event):

if __name__ == '__main__':
host = sys.argv[2] if len(sys.argv) > 2 else "localhost"
kernel = Kernel(with_monitor=True)
print("Try GETting:")
print(" On OSX after 'brew install curl --with-c-ares --with-libidn --with-nghttp2 --with-openssl':")
print("/usr/local/opt/curl/bin/curl --tlsv1.2 --http2 -k https://localhost:5000/bundle.js")
print("Or open a browser to: https://localhost:5000/")
print(" (Accept all the warnings)")
kernel.run(h2_server((host, 5000),
sys.argv[1],
"{}.crt.pem".format(host),
"{}.key".format(host)))
run(h2_server((host, 5000), sys.argv[1],
"{}.crt.pem".format(host),
"{}.key".format(host)), with_monitor=True)