mirror of https://github.com/nocturn9x/giambio.git
Updated server example with context manager to close the server socket automatically
This commit is contained in:
parent
9bb091cdef
commit
e4a4c45f65
|
@ -19,10 +19,11 @@ async def serve(bind_address: tuple):
|
|||
await sock.listen(5)
|
||||
logging.info(f"Serving asynchronously at {bind_address[0]}:{bind_address[1]}")
|
||||
async with giambio.create_pool() as pool:
|
||||
while True:
|
||||
conn, address_tuple = await sock.accept()
|
||||
logging.info(f"{address_tuple[0]}:{address_tuple[1]} connected")
|
||||
await pool.spawn(handler, conn, address_tuple)
|
||||
async with sock:
|
||||
while True:
|
||||
conn, address_tuple = await sock.accept()
|
||||
logging.info(f"{address_tuple[0]}:{address_tuple[1]} connected")
|
||||
await pool.spawn(handler, conn, address_tuple)
|
||||
|
||||
|
||||
async def handler(sock: AsyncSocket, client_address: tuple):
|
||||
|
|
Loading…
Reference in New Issue