diff options
Diffstat (limited to 'cython')
| -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: | |||
| 38 | cdef class iDeviceConnection(Base): | 38 | cdef class iDeviceConnection(Base): |
| 39 | cdef idevice_connection_t _c_connection | 39 | cdef idevice_connection_t _c_connection |
| 40 | 40 | ||
| 41 | cpdef bytes receive_timeout(self, uint32_t max_len, unsigned int timeout) | ||
| 42 | cpdef bytes receive(self, max_len) | ||
| 41 | cpdef disconnect(self) | 43 | cpdef disconnect(self) |
| 42 | 44 | ||
| 43 | cdef class iDevice(Base): | 45 | 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): | |||
| 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) |
