feat: speed up connect and disconnect (#247)

This commit is contained in:
J. Nick Koston 2023-09-11 18:50:05 -05:00 committed by GitHub
parent cbcea89509
commit 8f39ba3ada
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 7 deletions

View File

@ -28,6 +28,7 @@ def build(setup_kwargs):
"src/dbus_fast/service.py",
"src/dbus_fast/signature.py",
"src/dbus_fast/unpack.py",
"src/dbus_fast/_private/address.py",
"src/dbus_fast/_private/marshaller.py",
"src/dbus_fast/_private/unmarshaller.py",
],

View File

@ -0,0 +1,15 @@
"""cdefs for address.py"""
import cython
cdef object unquote
@cython.locals(kv=cython.str, opt_string=cython.str, address=cython.str)
cpdef parse_address(cython.str address_str)
cpdef get_bus_address(object bus_type)
cpdef get_session_bus_address()
cpdef get_system_bus_address()

View File

@ -8,8 +8,10 @@ from ..errors import InvalidAddressError
invalid_address_chars_re = re.compile(r"[^-0-9A-Za-z_/.%]")
str_ = str
def parse_address(address_str: str) -> List[Tuple[str, Dict[str, str]]]:
def parse_address(address_str: str_) -> List[Tuple[str, Dict[str, str]]]:
"""Parse a dbus address string into a list of addresses."""
addresses: List[Tuple[str, Dict[str, str]]] = []

View File

@ -43,7 +43,7 @@ cdef class Message:
cdef public object error_name
cdef public object reply_serial
cdef public object sender
cdef public object unix_fds
cdef public cython.list unix_fds
cdef public object signature
cdef public object signature_tree
cdef public object body

View File

@ -1,5 +1,6 @@
import cython
from ._private.address cimport get_bus_address, parse_address
from .message cimport Message
from .service cimport ServiceInterface, _Method
@ -10,18 +11,19 @@ cdef object MessageFlag
cdef object MESSAGE_TYPE_CALL
cdef object MESSAGE_TYPE_SIGNAL
cdef object NO_REPLY_EXPECTED_VALUE
cdef cython.uint NO_REPLY_EXPECTED_VALUE
cdef object BLOCK_UNEXPECTED_REPLY
cdef object assert_object_path_valid
cdef object assert_bus_name_valid
cdef _expects_reply(Message msg)
@cython.locals(flag_value=cython.uint)
cdef bint _expects_reply(Message msg)
cdef class BaseMessageBus:
cdef public object unique_name
cdef public object _disconnected
cdef public bint _disconnected
cdef public object _user_disconnect
cdef public cython.dict _method_return_handlers
cdef public object _serial
@ -48,3 +50,5 @@ cdef class BaseMessageBus:
interfaces=cython.list,
)
cdef _find_message_handler(self, Message msg)
cdef _setup_socket(self)

View File

@ -36,7 +36,8 @@ _Message = Message
def _expects_reply(msg: _Message) -> bool:
"""Whether a message expects a reply."""
return not (msg.flags.value & NO_REPLY_EXPECTED_VALUE)
flag_value = msg.flags.value
return not (flag_value & NO_REPLY_EXPECTED_VALUE)
def _block_unexpected_reply(reply: _Message) -> None:
@ -153,6 +154,9 @@ class BaseMessageBus:
# machine id is lazy loaded
self._machine_id: Optional[int] = None
self._sock: Optional[socket.socket] = None
self._fd: Optional[int] = None
self._stream: Optional[Any] = None
self._setup_socket()
@ -587,7 +591,7 @@ class BaseMessageBus:
self._method_return_handlers.clear()
for path in list(self._path_exports.keys()):
for path in list(self._path_exports):
self.unexport(path)
self._user_message_handlers.clear()