Skip to content

Commit

Permalink
Fixed #158, rewrite sslproto
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Sep 7, 2018
1 parent ee05420 commit d7f7f17
Show file tree
Hide file tree
Showing 20 changed files with 1,593 additions and 505 deletions.
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

0 comments on commit d7f7f17

Please sign in to comment.