1- cdef enum :
1+ cdef enum :
22 __PREALLOCED_BUFS = 4
33
44
@@ -213,14 +213,15 @@ cdef class UVStream(UVBaseTransport):
213213 self .__shutting_down = 0
214214 self .__reading = 0
215215 self .__read_error_close = 0
216- self .__buffered = 0
217- self ._eof = 0
218- self ._buffer = []
219- self ._buffer_size = 0
220216
217+ self .__protocol_type = ProtocolType.SIMPLE
221218 self ._protocol_get_buffer = None
222219 self ._protocol_buffer_updated = None
223220
221+ self ._eof = 0
222+ self ._buffer = []
223+ self ._buffer_size = 0
224+
224225 self ._read_pybuf_acquired = False
225226
226227 cdef _set_protocol(self , object protocol):
@@ -230,23 +231,23 @@ cdef class UVStream(UVBaseTransport):
230231 UVBaseTransport._set_protocol(self , protocol)
231232
232233 if isinstance (protocol, SSLProtocol):
233- self .__buffered = 1
234+ self .__protocol_type = ProtocolType.SSL_PROTOCOL
234235 elif (hasattr (protocol, ' get_buffer' ) and
235236 not isinstance (protocol, aio_Protocol)):
236237 try :
237238 self ._protocol_get_buffer = protocol.get_buffer
238239 self ._protocol_buffer_updated = protocol.buffer_updated
239- self .__buffered = 1
240+ self .__protocol_type = ProtocolType.BUFFERED
240241 except AttributeError :
241242 pass
242243 else :
243- self .__buffered = 0
244+ self .__protocol_type = ProtocolType.SIMPLE
244245
245246 cdef _clear_protocol(self ):
246247 UVBaseTransport._clear_protocol(self )
247248 self ._protocol_get_buffer = None
248249 self ._protocol_buffer_updated = None
249- self .__buffered = 0
250+ self .__protocol_type = ProtocolType.SIMPLE
250251
251252 cdef inline _shutdown(self ):
252253 cdef int err
@@ -296,14 +297,14 @@ cdef class UVStream(UVBaseTransport):
296297 if self .__reading:
297298 return
298299
299- if self .__buffered:
300- err = uv.uv_read_start(< uv.uv_stream_t* > self ._handle,
301- __uv_stream_buffered_alloc,
302- __uv_stream_buffered_on_read)
303- else :
300+ if self .__protocol_type == ProtocolType.SIMPLE:
304301 err = uv.uv_read_start(< uv.uv_stream_t* > self ._handle,
305302 __loop_alloc_buffer,
306303 __uv_stream_on_read)
304+ else :
305+ err = uv.uv_read_start(< uv.uv_stream_t * > self ._handle,
306+ __uv_stream_buffered_alloc,
307+ __uv_stream_buffered_on_read)
307308 if err < 0 :
308309 exc = convert_error(err)
309310 self ._fatal_error(exc, True )
@@ -927,7 +928,7 @@ cdef void __uv_stream_buffered_alloc(
927928
928929 # Fast pass for our own SSLProtocol
929930 # avoid python calls, memoryviews, context enter/exit, etc
930- if isinstance ( sc._protocol, SSLProtocol) :
931+ if sc.__protocol_type == ProtocolType.SSL_PROTOCOL :
931932 try :
932933 (< SSLProtocol> sc._protocol).get_buffer_impl(
933934 suggested_size, & uvbuf.base, & uvbuf.len)
@@ -1001,7 +1002,7 @@ cdef void __uv_stream_buffered_on_read(
10011002 return
10021003
10031004 try :
1004- if nread > 0 and not isinstance ( sc._protocol, SSLProtocol) and not sc._read_pybuf_acquired:
1005+ if nread > 0 and sc.__protocol_type ! = ProtocolType.SSL_PROTOCOL and not sc._read_pybuf_acquired:
10051006 # From libuv docs:
10061007 # nread is > 0 if there is data available or < 0 on error. When
10071008 # we’ve reached EOF, nread will be set to UV_EOF. When
@@ -1022,7 +1023,7 @@ cdef void __uv_stream_buffered_on_read(
10221023 if UVLOOP_DEBUG:
10231024 loop._debug_stream_read_cb_total += 1
10241025
1025- if isinstance ( sc._protocol, SSLProtocol) :
1026+ if sc.__protocol_type == ProtocolType.SSL_PROTOCOL :
10261027 Context_Enter(sc.context)
10271028 try :
10281029 (< SSLProtocol> sc._protocol).buffer_updated_impl(nread)
0 commit comments