Commit 9e651ded authored by Yury Selivanov's avatar Yury Selivanov

Update curio

parent 3728d87c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# A simple echo server # A simple echo server
from curio import Kernel, new_task, run_server from curio import run, tcp_server
from socket import * from socket import *
...@@ -14,12 +14,11 @@ async def echo_handler(client, addr): ...@@ -14,12 +14,11 @@ async def echo_handler(client, addr):
pass pass
while True: while True:
data = await client.recv(102400) data = await client.recv(1000000)
if not data: if not data:
break break
await client.sendall(data) await client.sendall(data)
print('Connection closed') print('Connection closed')
if __name__ == '__main__': if __name__ == '__main__':
kernel = Kernel() run(tcp_server('', 25000, echo_handler))
kernel.run(run_server('', 25000, echo_handler))
from curio import Kernel, new_task, run_server from curio import run, spawn, tcp_server
from socket import * from socket import *
async def echo_handler(client, addr): async def echo_handler(client, addr):
...@@ -7,16 +7,15 @@ async def echo_handler(client, addr): ...@@ -7,16 +7,15 @@ async def echo_handler(client, addr):
client.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) client.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1)
except (OSError, NameError): except (OSError, NameError):
pass pass
reader, writer = client.make_streams() s = client.as_stream()
async with reader, writer: while True:
while True: data = await s.read(102400)
data = await reader.read(102400) if not data:
if not data: break
break await s.write(data)
await writer.write(data) await s.close()
await client.close()
print('Connection closed') print('Connection closed')
if __name__ == '__main__': if __name__ == '__main__':
kernel = Kernel() run(tcp_server('', 25000, echo_handler))
kernel.run(run_server('', 25000, echo_handler))
curio==0.1 curio==0.4
aiohttp==0.21.5 aiohttp==0.21.5
gevent==1.1.1 gevent==1.1.1
tornado==4.3 tornado==4.3
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment