Speed up frame helpers (#696)

This commit is contained in:
J. Nick Koston 2023-11-24 12:40:33 -06:00 committed by GitHub
parent 065c8e715d
commit c0a153c9f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 13 deletions

View File

@ -26,11 +26,11 @@ cdef class APIFrameHelper:
cdef bytes _read(self, int length)
@cython.locals(bytes_data=bytes)
cdef _add_to_buffer(self, object data)
cdef void _add_to_buffer(self, object data)
@cython.locals(end_of_frame_pos="unsigned int")
cdef _remove_from_buffer(self)
cdef void _remove_from_buffer(self)
cpdef write_packets(self, list packets, bint debug_enabled)
cdef _write_bytes(self, bytes data, bint debug_enabled)
cdef void _write_bytes(self, bytes data, bint debug_enabled)

View File

@ -36,22 +36,22 @@ cdef class APINoiseFrameHelper(APIFrameHelper):
type_high="unsigned char",
type_low="unsigned char"
)
cdef _handle_frame(self, bytes frame)
cdef void _handle_frame(self, bytes frame)
@cython.locals(
chosen_proto=char,
server_name_i=int
)
cdef _handle_hello(self, bytes server_hello)
cdef void _handle_hello(self, bytes server_hello)
cdef _handle_handshake(self, bytes msg)
cdef void _handle_handshake(self, bytes msg)
cdef _handle_closed(self, bytes frame)
cdef void _handle_closed(self, bytes frame)
@cython.locals(handshake_frame=bytearray, frame_len="unsigned int")
cdef _send_hello_handshake(self)
cdef void _send_hello_handshake(self)
cdef _setup_proto(self)
cdef void _setup_proto(self)
@cython.locals(psk_bytes=bytes)
cdef _decode_noise_psk(self)

View File

@ -135,7 +135,7 @@ class APINoiseFrameHelper(APIFrameHelper):
def data_received(self, data: bytes | bytearray | memoryview) -> None:
self._add_to_buffer(data)
while self._buffer:
while self._buffer_len:
self._pos = 0
if (header := self._read(3)) is None:
return

View File

@ -27,7 +27,7 @@ cdef class APIPlaintextFrameHelper(APIFrameHelper):
)
cpdef data_received(self, object data)
cdef _error_on_incorrect_preamble(self, object preamble)
cdef void _error_on_incorrect_preamble(self, object preamble)
@cython.locals(
type_="unsigned int",

View File

@ -80,7 +80,7 @@ class APIPlaintextFrameHelper(APIFrameHelper):
self, data: bytes | bytearray | memoryview
) -> None:
self._add_to_buffer(data)
while self._buffer:
while self._buffer_len:
# Read preamble, which should always 0x00
# Also try to get the length and msg type
# to avoid multiple calls to _read

View File

@ -89,7 +89,7 @@ cdef class APIConnection:
cdef send_messages(self, tuple messages)
@cython.locals(handlers=set, handlers_copy=set)
cpdef process_packet(self, object msg_type_proto, object data)
cpdef void process_packet(self, object msg_type_proto, object data)
cpdef _async_cancel_pong_timer(self)