summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Hao Zhou2014-12-13 13:21:52 +0800
committerGravatar Martin Szulecki2015-01-12 18:33:54 +0100
commitaa14c053bc909c56d31c12799f13013f845ddb71 (patch)
tree93a84428b2f2a52a14f6e60df3e3633a9bcca94c
parent7b082b87102725a2e282ac5bfe8bf5ee1fb57437 (diff)
downloadlibimobiledevice-aa14c053bc909c56d31c12799f13013f845ddb71.tar.gz
libimobiledevice-aa14c053bc909c56d31c12799f13013f845ddb71.tar.bz2
cython: Add receive/receive_timeout methods for iDeviceConnection to receive data from a connection
-rw-r--r--cython/imobiledevice.pxd2
-rw-r--r--cython/imobiledevice.pyx30
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)