Skip to content

Commit 9cba749

Browse files
fantix1st1
authored andcommitted
Fixed #158: new SSL implementation (#176)
1 parent ee05420 commit 9cba749

20 files changed

+1593
-505
lines changed

Diff for: .ci/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ aiohttp
33
tinys3
44
twine
55
psutil
6+
pyOpenSSL==18.0.0

Diff for: examples/bench/echoserver.py

+31-3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ def data_received(self, data):
7474
self.transport.write(data)
7575

7676

77+
class EchoBufferedProtocol(asyncio.BufferedProtocol):
78+
def connection_made(self, transport):
79+
self.transport = transport
80+
# Here the buffer is intended to be copied, so that the outgoing buffer
81+
# won't be wrongly updated by next read
82+
self.buffer = bytearray(256 * 1024)
83+
84+
def connection_lost(self, exc):
85+
self.transport = None
86+
87+
def get_buffer(self, sizehint):
88+
return self.buffer
89+
90+
def buffer_updated(self, nbytes):
91+
self.transport.write(self.buffer[:nbytes])
92+
93+
7794
async def print_debug(loop):
7895
while True:
7996
print(chr(27) + "[2J") # clear screen
@@ -89,6 +106,7 @@ async def print_debug(loop):
89106
parser.add_argument('--addr', default='127.0.0.1:25000', type=str)
90107
parser.add_argument('--print', default=False, action='store_true')
91108
parser.add_argument('--ssl', default=False, action='store_true')
109+
parser.add_argument('--buffered', default=False, action='store_true')
92110
args = parser.parse_args()
93111

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

161+
if args.buffered:
162+
print('cannot use --stream and --buffered simultaneously')
163+
exit(1)
164+
143165
print('using asyncio/streams')
144166
if unix:
145167
coro = asyncio.start_unix_server(echo_client_streams,
@@ -155,12 +177,18 @@ async def print_debug(loop):
155177
print('cannot use --stream and --proto simultaneously')
156178
exit(1)
157179

158-
print('using simple protocol')
180+
if args.buffered:
181+
print('using buffered protocol')
182+
protocol = EchoBufferedProtocol
183+
else:
184+
print('using simple protocol')
185+
protocol = EchoProtocol
186+
159187
if unix:
160-
coro = loop.create_unix_server(EchoProtocol, addr,
188+
coro = loop.create_unix_server(protocol, addr,
161189
ssl=server_context)
162190
else:
163-
coro = loop.create_server(EchoProtocol, *addr,
191+
coro = loop.create_server(protocol, *addr,
164192
ssl=server_context)
165193
srv = loop.run_until_complete(coro)
166194
else:

Diff for: requirements.dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Cython==0.28.4
22
Sphinx>=1.4.1
33
psutil
4+
pyOpenSSL==18.0.0

0 commit comments

Comments
 (0)