Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite sslproto.py #176

Merged
merged 1 commit into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .ci/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ aiohttp
tinys3
twine
psutil
pyOpenSSL==18.0.0
34 changes: 31 additions & 3 deletions examples/bench/echoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ def data_received(self, data):
self.transport.write(data)


class EchoBufferedProtocol(asyncio.BufferedProtocol):
def connection_made(self, transport):
self.transport = transport
# Here the buffer is intended to be copied, so that the outgoing buffer
# won't be wrongly updated by next read
self.buffer = bytearray(256 * 1024)

def connection_lost(self, exc):
self.transport = None

def get_buffer(self, sizehint):
return self.buffer

def buffer_updated(self, nbytes):
self.transport.write(self.buffer[:nbytes])


async def print_debug(loop):
while True:
print(chr(27) + "[2J") # clear screen
Expand All @@ -89,6 +106,7 @@ async def print_debug(loop):
parser.add_argument('--addr', default='127.0.0.1:25000', type=str)
parser.add_argument('--print', default=False, action='store_true')
parser.add_argument('--ssl', default=False, action='store_true')
parser.add_argument('--buffered', default=False, action='store_true')
args = parser.parse_args()

if args.uvloop:
Expand Down Expand Up @@ -140,6 +158,10 @@ async def print_debug(loop):
print('cannot use --stream and --proto simultaneously')
exit(1)

if args.buffered:
print('cannot use --stream and --buffered simultaneously')
exit(1)

print('using asyncio/streams')
if unix:
coro = asyncio.start_unix_server(echo_client_streams,
Expand All @@ -155,12 +177,18 @@ async def print_debug(loop):
print('cannot use --stream and --proto simultaneously')
exit(1)

print('using simple protocol')
if args.buffered:
print('using buffered protocol')
protocol = EchoBufferedProtocol
else:
print('using simple protocol')
protocol = EchoProtocol

if unix:
coro = loop.create_unix_server(EchoProtocol, addr,
coro = loop.create_unix_server(protocol, addr,
ssl=server_context)
else:
coro = loop.create_server(EchoProtocol, *addr,
coro = loop.create_server(protocol, *addr,
ssl=server_context)
srv = loop.run_until_complete(coro)
else:
Expand Down
1 change: 1 addition & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Cython==0.28.4
Sphinx>=1.4.1
psutil
pyOpenSSL==18.0.0
Loading