@@ -232,7 +232,10 @@ cdef class UVStream(UVBaseTransport):
232
232
233
233
UVBaseTransport._set_protocol(self , protocol)
234
234
235
- if (hasattr (protocol, ' get_buffer' ) and
235
+ if isinstance (protocol, SSLProtocol):
236
+ self ._protocol_buffer_updated = protocol.buffer_updated
237
+ self .__buffered = 1
238
+ elif (hasattr (protocol, ' get_buffer' ) and
236
239
not isinstance (protocol, aio_Protocol)):
237
240
try :
238
241
self ._protocol_get_buffer = protocol.get_buffer
@@ -924,9 +927,21 @@ cdef void __uv_stream_buffered_alloc(
924
927
" UVStream alloc buffer callback" ) == 0 :
925
928
return
926
929
930
+ cdef UVStream sc = < UVStream> stream.data
931
+
932
+ # Fast pass for our own SSLProtocol
933
+ # avoid python calls, memoryviews, etc
934
+ if isinstance (sc._protocol, SSLProtocol):
935
+ try :
936
+ (< SSLProtocol> sc._protocol).get_buffer_c(
937
+ suggested_size, & uvbuf.base, & uvbuf.len)
938
+ return
939
+ except BaseException as exc:
940
+ uvbuf.len = 0
941
+ uvbuf.base = NULL
942
+ return
943
+
927
944
cdef:
928
- UVStream sc = < UVStream> stream.data
929
- Loop loop = sc._loop
930
945
Py_buffer* pybuf = & sc._read_pybuf
931
946
int got_buf = 0
932
947
@@ -987,7 +1002,7 @@ cdef void __uv_stream_buffered_on_read(
987
1002
return
988
1003
989
1004
try :
990
- if nread > 0 and not sc._read_pybuf_acquired:
1005
+ if nread > 0 and not isinstance (sc._protocol, SSLProtocol) and not sc._read_pybuf_acquired:
991
1006
# From libuv docs:
992
1007
# nread is > 0 if there is data available or < 0 on error. When
993
1008
# we’ve reached EOF, nread will be set to UV_EOF. When
@@ -1015,5 +1030,6 @@ cdef void __uv_stream_buffered_on_read(
1015
1030
1016
1031
sc._fatal_error(exc, False )
1017
1032
finally :
1018
- sc._read_pybuf_acquired = 0
1019
- PyBuffer_Release(pybuf)
1033
+ if sc._read_pybuf_acquired:
1034
+ sc._read_pybuf_acquired = 0
1035
+ PyBuffer_Release(pybuf)
0 commit comments