diff options
-rw-r--r-- | cython/imobiledevice.pxd | 2 | ||||
-rw-r--r-- | cython/imobiledevice.pyx | 30 |
2 files changed, 32 insertions, 0 deletions
diff --git a/cython/imobiledevice.pxd b/cython/imobiledevice.pxd index 684368b..8523c94 100644 --- a/cython/imobiledevice.pxd +++ b/cython/imobiledevice.pxd @@ -38,6 +38,8 @@ cdef class iDeviceEvent: cdef class iDeviceConnection(Base): cdef idevice_connection_t _c_connection + cpdef bytes receive_timeout(self, uint32_t max_len, unsigned int timeout) + cpdef bytes receive(self, max_len) cpdef disconnect(self) cdef class iDevice(Base): diff --git a/cython/imobiledevice.pyx b/cython/imobiledevice.pyx index e011223..bc861b3 100644 --- a/cython/imobiledevice.pyx +++ b/cython/imobiledevice.pyx @@ -128,6 +128,36 @@ cdef class iDeviceConnection(Base): def __init__(self, *args, **kwargs): raise TypeError("iDeviceConnection cannot be instantiated. Please use iDevice.connect()") + cpdef bytes receive_timeout(self, uint32_t max_len, unsigned int timeout): + cdef: + uint32_t bytes_received + char* c_data = <char *>malloc(max_len) + bytes result + + try: + self.handle_error(idevice_connection_receive_timeout(self._c_connection, c_data, max_len, &bytes_received, timeout)) + result = c_data[:bytes_received] + return result + except BaseError, e: + raise + finally: + free(c_data) + + cpdef bytes receive(self, max_len): + cdef: + uint32_t bytes_received + char* c_data = <char *>malloc(max_len) + bytes result + + try: + self.handle_error(idevice_connection_receive(self._c_connection, c_data, max_len, &bytes_received)) + result = c_data[:bytes_received] + return result + except BaseError, e: + raise + finally: + free(c_data) + cpdef disconnect(self): cdef idevice_error_t err err = idevice_disconnect(self._c_connection) |