summaryrefslogtreecommitdiffstats
path: root/cython/imobiledevice.pyx
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 /cython/imobiledevice.pyx
parent7b082b87102725a2e282ac5bfe8bf5ee1fb57437 (diff)
downloadlibimobiledevice-aa14c053bc909c56d31c12799f13013f845ddb71.tar.gz
libimobiledevice-aa14c053bc909c56d31c12799f13013f845ddb71.tar.bz2
cython: Add receive/receive_timeout methods for iDeviceConnection to receive data from a connection
Diffstat (limited to 'cython/imobiledevice.pyx')
-rw-r--r--cython/imobiledevice.pyx30
1 files changed, 30 insertions, 0 deletions
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):
128 def __init__(self, *args, **kwargs): 128 def __init__(self, *args, **kwargs):
129 raise TypeError("iDeviceConnection cannot be instantiated. Please use iDevice.connect()") 129 raise TypeError("iDeviceConnection cannot be instantiated. Please use iDevice.connect()")
130 130
131 cpdef bytes receive_timeout(self, uint32_t max_len, unsigned int timeout):
132 cdef:
133 uint32_t bytes_received
134 char* c_data = <char *>malloc(max_len)
135 bytes result
136
137 try:
138 self.handle_error(idevice_connection_receive_timeout(self._c_connection, c_data, max_len, &bytes_received, timeout))
139 result = c_data[:bytes_received]
140 return result
141 except BaseError, e:
142 raise
143 finally:
144 free(c_data)
145
146 cpdef bytes receive(self, max_len):
147 cdef:
148 uint32_t bytes_received
149 char* c_data = <char *>malloc(max_len)
150 bytes result
151
152 try:
153 self.handle_error(idevice_connection_receive(self._c_connection, c_data, max_len, &bytes_received))
154 result = c_data[:bytes_received]
155 return result
156 except BaseError, e:
157 raise
158 finally:
159 free(c_data)
160
131 cpdef disconnect(self): 161 cpdef disconnect(self):
132 cdef idevice_error_t err 162 cdef idevice_error_t err
133 err = idevice_disconnect(self._c_connection) 163 err = idevice_disconnect(self._c_connection)