def translate_type(t):
table = {
"float": 'c_float',
"uint32_t": 'c_uint32',
"uint64_t": 'c_uint64',
"size_t": 'c_size_t',
"float": 'c_float',
'int32_t': 'c_int32',
'int': 'c_int32',
'uint8_t': 'c_int8',
"char": "c_char",
"void": "None",
"void*": "c_void_p",
"const void*": 'c_void_p',
"const char*": 'c_char_p',
"const char* const*": 'POINTER(c_char_p)',
"struct wl_display*": "POINTER(wl_display)",
"struct wl_surface*": "POINTER(wl_surface)",
"const ObjectTableEntryNVX* const*": "POINTER(POINTER(ObjectTableEntryNVX))",
'v': ''
}
if t in table.keys():
return table[t]
if t.endswith("*"):
if t.startswith("const"):
ttype = t[6:len(t)-1]
ttype = table[ttype] if ttype in table else ttype
return "POINTER({})".format(ttype)
else:
ttype = t[:len(t)-1]
ttype = table[ttype] if ttype in table else ttype
return "POINTER({})".format(ttype)
return t
python类c_uint64()的实例源码
def parse_handles_def(f):
f.write("# Handles types\n")
handles = re.findall("VK_DEFINE_HANDLE\(Vk(\w+)\)", src, re.S)
for h in handles:
f.write("{} = c_size_t\n".format(h))
handles_non_dispatchable = re.findall("VK_DEFINE_NON_DISPATCHABLE_HANDLE\(Vk(\w+)\)", src, re.S)
for h in handles_non_dispatchable:
f.write("{} = c_uint64\n".format(h))
def parse_allocation_callback(f):
# Allocation callback must be defined before the structs, but there are no good way to differenciate them
# from the function pointers. Hence why they are hardcoded here
f.write("""
# Allocation callback
FnAllocationFunction = FUNCTYPE(c_void_p, c_void_p, c_size_t, c_size_t, SystemAllocationScope)
FnReallocationFunction = FUNCTYPE(c_void_p, c_void_p, c_size_t, c_size_t, SystemAllocationScope)
FnFreeFunction = FUNCTYPE(None, c_void_p, c_void_p)
FnInternalAllocationNotification = FUNCTYPE(None, c_void_p, c_size_t, InternalAllocationType, SystemAllocationScope)
FnInternalFreeNotification = FUNCTYPE(None, c_void_p, c_size_t, InternalAllocationType, SystemAllocationScope)
FnDebugReportCallbackEXT = FUNCTYPE(Bool32, DebugReportFlagsEXT, DebugReportObjectTypeEXT, c_uint64, c_size_t, c_uint32, c_char_p, c_char_p, c_void_p)
"""[1::])
def file_seek(self, friend_number, file_number, position):
"""
Sends a file seek control command to a friend for a given file transfer.
This function can only be called to resume a file transfer right before TOX_FILE_CONTROL_RESUME is sent.
:param friend_number: The friend number of the friend the file is being received from.
:param file_number: The friend-specific identifier for the file transfer.
:param position: The position that the file should be seeked to.
:return: True on success.
"""
tox_err_file_seek = c_int()
result = Tox.libtoxcore.tox_file_control(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number),
c_uint64(position), byref(tox_err_file_seek))
tox_err_file_seek = tox_err_file_seek.value
if tox_err_file_seek == TOX_ERR_FILE_SEEK['OK']:
return bool(result)
elif tox_err_file_seek == TOX_ERR_FILE_SEEK['FRIEND_NOT_FOUND']:
raise ArgumentError('The friend_number passed did not designate a valid friend.')
elif tox_err_file_seek == TOX_ERR_FILE_SEEK['FRIEND_NOT_CONNECTED']:
raise RuntimeError('This client is currently not connected to the friend.')
elif tox_err_file_seek == TOX_ERR_FILE_SEEK['NOT_FOUND']:
raise ArgumentError('No file transfer with the given file number was found for the given friend.')
elif tox_err_file_seek == TOX_ERR_FILE_SEEK['SEEK_DENIED']:
raise ArgumentError('File was not in a state where it could be seeked.')
elif tox_err_file_seek == TOX_ERR_FILE_SEEK['INVALID_POSITION']:
raise ArgumentError('Seek position was invalid')
elif tox_err_file_seek == TOX_ERR_FILE_SEEK['SENDQ']:
raise ArgumentError('Packet queue is full.')
def callback_file_chunk_request(self, callback, user_data):
"""
Set the callback for the `file_chunk_request` event. Pass None to unset.
This event is triggered when Core is ready to send more file data.
:param callback: Python function.
If the length parameter is 0, the file transfer is finished, and the client's resources associated with the file
number should be released. After a call with zero length, the file number can be reused for future file
transfers.
If the requested position is not equal to the client's idea of the current file or stream position, it will need
to seek. In case of read-once streams, the client should keep the last read chunk so that a seek back can be
supported. A seek-back only ever needs to read from the last requested chunk. This happens when a chunk was
requested, but the send failed. A seek-back request can occur an arbitrary number of times for any given chunk.
In response to receiving this callback, the client should call the function `tox_file_send_chunk` with the
requested chunk. If the number of bytes sent through that function is zero, the file transfer is assumed
complete. A client must send the full length of data requested with this callback.
Should take pointer (c_void_p) to Tox object,
The friend number (c_uint32) of the receiving friend for this file.
The file transfer identifier (c_uint32) returned by tox_file_send.
The file or stream position (c_uint64) from which to continue reading.
The number of bytes (c_size_t) requested for the current chunk.
pointer (c_void_p) to user_data
:param user_data: pointer (c_void_p) to user data
"""
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_uint64, c_size_t, c_void_p)
self.file_chunk_request_cb = c_callback(callback)
self.libtoxcore.tox_callback_file_chunk_request(self._tox_pointer, self.file_chunk_request_cb, user_data)
# -----------------------------------------------------------------------------------------------------------------
# File transmission: receiving
# -----------------------------------------------------------------------------------------------------------------
def callback_file_recv_chunk(self, callback, user_data):
"""
Set the callback for the `file_recv_chunk` event. Pass NULL to unset.
This event is first triggered when a file transfer request is received, and subsequently when a chunk of file
data for an accepted request was received.
:param callback: Python function.
When length is 0, the transfer is finished and the client should release the resources it acquired for the
transfer. After a call with length = 0, the file number can be reused for new file transfers.
If position is equal to file_size (received in the file_receive callback) when the transfer finishes, the file
was received completely. Otherwise, if file_size was UINT64_MAX, streaming ended successfully when length is 0.
Should take pointer (c_void_p) to Tox object,
The friend number (c_uint32) of the friend who is sending the file.
The friend-specific file number (c_uint32) the data received is associated with.
The file position (c_uint64) of the first byte in data.
A byte array (c_char_p) containing the received chunk.
The length (c_size_t) of the received chunk.
pointer (c_void_p) to user_data
:param user_data: pointer (c_void_p) to user data
"""
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_uint64, POINTER(c_uint8), c_size_t, c_void_p)
self.file_recv_chunk_cb = c_callback(callback)
self.libtoxcore.tox_callback_file_recv_chunk(self._tox_pointer, self.file_recv_chunk_cb, user_data)
# -----------------------------------------------------------------------------------------------------------------
# Low-level network information
# -----------------------------------------------------------------------------------------------------------------
def getindex(self):
index_size = ctypes.c_uint64(0)
index_data = ctypes.POINTER(ctypes.c_uint64)()
check_call(_LIB.MXDataIterGetIndex(self.handle,
ctypes.byref(index_data),
ctypes.byref(index_size)))
address = ctypes.addressof(index_data.contents)
dbuffer = (ctypes.c_uint64* index_size.value).from_address(address)
np_index = np.frombuffer(dbuffer, dtype=np.uint64)
return np_index.copy()
def read_var_uh_long(self):
_loc3_ = 0
_loc2_low = 0
_loc2_high = 0
_loc4_ = 0
while True:
_loc3_ = self.read_unsigned_byte()
if _loc4_ == 28:
break
if _loc3_ >= 128:
_loc2_low = _loc2_low | (_loc3_ & 127) << _loc4_
_loc4_ = _loc4_ + 7
continue
_loc2_low = _loc2_low | _loc3_ << _loc4_
return ctypes.c_uint64(_loc2_high * 4294967296 + _loc2_low).value
if _loc3_ >= 128:
_loc3_ = _loc3_ & 127
_loc2_low = _loc2_low | _loc3_ << _loc4_
_loc2_high = _lrshift32(_loc3_, 4)
_loc4_ = 3
while True:
_loc3_ = self.read_unsigned_byte()
if _loc4_ < 32:
if _loc3_ >= 128:
_loc2_high = _loc2_high | (_loc3_ & 127) << _loc4_
else:
break
_loc4_ = _loc4_ + 7
_loc2_high = _loc2_high | (_loc3_ << _loc4_)
return ctypes.c_uint64(_loc2_high * 4294967296 + _loc2_low).value
_loc2_low = _loc2_low | (_loc3_ << _loc4_)
_loc2_high = _lrshift32(_loc3_, 4)
return ctypes.c_uint64(_loc2_high * 4294967296 + _loc2_low).value
def call_hash(self, buf):
buf = list(bytearray(buf))
num_bytes = len(buf)
array_type = ctypes.c_ubyte * num_bytes
data = self._hash_lib.compute_hash(array_type(*buf), ctypes.c_uint32(num_bytes))
return ctypes.c_uint64(data).value
def __init__(self, drm, id_, type_):
self._drm = drm
self.id = id_
self.type = type_
self.props = []
arg = DrmModeObjGetPropertiesC()
arg.obj_id = self.id
arg.obj_type = self.type
fcntl.ioctl(self._drm.fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, arg)
if arg.count_props == 0:
#print("DrmProperties(%d, 0x%x): arg.count_props=%d" % (self.id, self.type, arg.count_props))
return
prop_ids = (ctypes.c_uint32*arg.count_props)()
arg.props_ptr = ctypes.cast(ctypes.pointer(prop_ids), ctypes.c_void_p).value
prop_values = (ctypes.c_uint64*arg.count_props)()
arg.prop_values_ptr = ctypes.cast(ctypes.pointer(prop_values), ctypes.c_void_p).value
fcntl.ioctl(self._drm.fd, DRM_IOCTL_MODE_OBJ_GETPROPERTIES, arg)
self._arg = arg
for i in range(arg.count_props):
propid = int(prop_ids[i])
propc = DrmModeObjGetPropertyC()
propc.prop_id = propid
fcntl.ioctl(self._drm.fd, DRM_IOCTL_MODE_GETPROPERTY, propc)
if propc.count_enum_blobs:
if propc.flags & DRM_MODE_PROP_ENUM:
prop = DrmPropertyEnum(self._drm, propid, self.id, self.type)
elif propc.flags & DRM_MODE_PROP_BITMASK:
prop = DrmPropertyBitmask(self._drm, propid, self.id, self.type, propc)
else:
raise ValueError("count_enum_blobs: propc.flags=0x%x" % propc.flags)
elif propc.flags & DRM_MODE_PROP_BLOB:
prop = DrmPropertyBlob(self._drm, propid, self.id, self.type, propc)
else:
raise ValueError("not count_enum_blobs: propc.flags=0x%x" % propc.flags)
self.props.append(prop)
def sendfile(fdout, fdin, offset, nbytes):
if sys.platform == 'darwin':
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_voidp,
ctypes.c_int]
_nbytes = ctypes.c_uint64(nbytes)
result = _sendfile(fdin, fdout, offset, _nbytes, None, 0)
if result == -1:
e = ctypes.get_errno()
if e == errno.EAGAIN and _nbytes.value is not None:
return _nbytes.value
raise OSError(e, os.strerror(e))
return _nbytes.value
elif sys.platform in ('freebsd', 'dragonfly',):
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64,
ctypes.c_uint64, ctypes.c_voidp,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_int]
_sbytes = ctypes.c_uint64()
result = _sendfile(fdin, fdout, offset, nbytes, None, _sbytes, 0)
if result == -1:
e = ctypes.get_errno()
if e == errno.EAGAIN and _sbytes.value is not None:
return _sbytes.value
raise OSError(e, os.strerror(e))
return _sbytes.value
else:
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_size_t]
_offset = ctypes.c_uint64(offset)
sent = _sendfile(fdout, fdin, _offset, nbytes)
if sent == -1:
e = ctypes.get_errno()
raise OSError(e, os.strerror(e))
return sent
def file_send_chunk(self, friend_number, file_number, position, data):
"""
Send a chunk of file data to a friend.
This function is called in response to the `file_chunk_request` callback. The length parameter should be equal
to the one received though the callback. If it is zero, the transfer is assumed complete. For files with known
size, Core will know that the transfer is complete after the last byte has been received, so it is not necessary
(though not harmful) to send a zero-length chunk to terminate. For streams, core will know that the transfer is
finished if a chunk with length less than the length requested in the callback is sent.
:param friend_number: The friend number of the receiving friend for this file.
:param file_number: The file transfer identifier returned by tox_file_send.
:param position: The file or stream position from which to continue reading.
:param data: Chunk of file data
:return: true on success.
"""
tox_err_file_send_chunk = c_int()
result = self.libtoxcore.tox_file_send_chunk(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number),
c_uint64(position), c_char_p(data), c_size_t(len(data)),
byref(tox_err_file_send_chunk))
tox_err_file_send_chunk = tox_err_file_send_chunk.value
if tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['OK']:
return bool(result)
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['NULL']:
raise ArgumentError('The length parameter was non-zero, but data was NULL.')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['FRIEND_NOT_FOUND']:
ArgumentError('The friend_number passed did not designate a valid friend.')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['FRIEND_NOT_CONNECTED']:
raise ArgumentError('This client is currently not connected to the friend.')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['NOT_FOUND']:
raise ArgumentError('No file transfer with the given file number was found for the given friend.')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['NOT_TRANSFERRING']:
raise ArgumentError('File transfer was found but isn\'t in a transferring state: (paused, done, broken, '
'etc...) (happens only when not called from the request chunk callback).')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['INVALID_LENGTH']:
raise ArgumentError('Attempted to send more or less data than requested. The requested data size is '
'adjusted according to maximum transmission unit and the expected end of the file. '
'Trying to send less or more than requested will return this error.')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['SENDQ']:
raise RuntimeError('Packet queue is full.')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['WRONG_POSITION']:
raise ArgumentError('Position parameter was wrong.')
def sendfile(fdout, fdin, offset, nbytes):
if sys.platform == 'darwin':
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_voidp,
ctypes.c_int]
_nbytes = ctypes.c_uint64(nbytes)
result = _sendfile(fdin, fdout, offset, _nbytes, None, 0)
if result == -1:
e = ctypes.get_errno()
if e == errno.EAGAIN and _nbytes.value is not None:
return _nbytes.value
raise OSError(e, os.strerror(e))
return _nbytes.value
elif sys.platform in ('freebsd', 'dragonfly',):
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64,
ctypes.c_uint64, ctypes.c_voidp,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_int]
_sbytes = ctypes.c_uint64()
result = _sendfile(fdin, fdout, offset, nbytes, None, _sbytes, 0)
if result == -1:
e = ctypes.get_errno()
if e == errno.EAGAIN and _sbytes.value is not None:
return _sbytes.value
raise OSError(e, os.strerror(e))
return _sbytes.value
else:
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_size_t]
_offset = ctypes.c_uint64(offset)
sent = _sendfile(fdout, fdin, _offset, nbytes)
if sent == -1:
e = ctypes.get_errno()
raise OSError(e, os.strerror(e))
return sent
def sendfile(fdout, fdin, offset, nbytes):
if sys.platform == 'darwin':
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_voidp,
ctypes.c_int]
_nbytes = ctypes.c_uint64(nbytes)
result = _sendfile(fdin, fdout, offset, _nbytes, None, 0)
if result == -1:
e = ctypes.get_errno()
if e == errno.EAGAIN and _nbytes.value is not None:
return _nbytes.value
raise OSError(e, os.strerror(e))
return _nbytes.value
elif sys.platform in ('freebsd', 'dragonfly',):
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64,
ctypes.c_uint64, ctypes.c_voidp,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_int]
_sbytes = ctypes.c_uint64()
result = _sendfile(fdin, fdout, offset, nbytes, None, _sbytes, 0)
if result == -1:
e = ctypes.get_errno()
if e == errno.EAGAIN and _sbytes.value is not None:
return _sbytes.value
raise OSError(e, os.strerror(e))
return _sbytes.value
else:
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_size_t]
_offset = ctypes.c_uint64(offset)
sent = _sendfile(fdout, fdin, _offset, nbytes)
if sent == -1:
e = ctypes.get_errno()
raise OSError(e, os.strerror(e))
return sent
def sendfile(fdout, fdin, offset, nbytes):
if sys.platform == 'darwin':
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_voidp,
ctypes.c_int]
_nbytes = ctypes.c_uint64(nbytes)
result = _sendfile(fdin, fdout, offset, _nbytes, None, 0)
if result == -1:
e = ctypes.get_errno()
if e == errno.EAGAIN and _nbytes.value is not None:
return _nbytes.value
raise OSError(e, os.strerror(e))
return _nbytes.value
elif sys.platform in ('freebsd', 'dragonfly',):
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64,
ctypes.c_uint64, ctypes.c_voidp,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_int]
_sbytes = ctypes.c_uint64()
result = _sendfile(fdin, fdout, offset, nbytes, None, _sbytes, 0)
if result == -1:
e = ctypes.get_errno()
if e == errno.EAGAIN and _sbytes.value is not None:
return _sbytes.value
raise OSError(e, os.strerror(e))
return _sbytes.value
else:
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_size_t]
_offset = ctypes.c_uint64(offset)
sent = _sendfile(fdout, fdin, _offset, nbytes)
if sent == -1:
e = ctypes.get_errno()
raise OSError(e, os.strerror(e))
return sent
def sendfile(fdout, fdin, offset, nbytes):
if sys.platform == 'darwin':
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_voidp,
ctypes.c_int]
_nbytes = ctypes.c_uint64(nbytes)
result = _sendfile(fdin, fdout, offset, _nbytes, None, 0)
if result == -1:
e = ctypes.get_errno()
if e == errno.EAGAIN and _nbytes.value is not None:
return _nbytes.value
raise OSError(e, os.strerror(e))
return _nbytes.value
elif sys.platform in ('freebsd', 'dragonfly',):
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64,
ctypes.c_uint64, ctypes.c_voidp,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_int]
_sbytes = ctypes.c_uint64()
result = _sendfile(fdin, fdout, offset, nbytes, None, _sbytes, 0)
if result == -1:
e = ctypes.get_errno()
if e == errno.EAGAIN and _sbytes.value is not None:
return _sbytes.value
raise OSError(e, os.strerror(e))
return _sbytes.value
else:
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_size_t]
_offset = ctypes.c_uint64(offset)
sent = _sendfile(fdout, fdin, _offset, nbytes)
if sent == -1:
e = ctypes.get_errno()
raise OSError(e, os.strerror(e))
return sent
def file_send_chunk(self, friend_number, file_number, position, data):
"""
Send a chunk of file data to a friend.
This function is called in response to the `file_chunk_request` callback. The length parameter should be equal
to the one received though the callback. If it is zero, the transfer is assumed complete. For files with known
size, Core will know that the transfer is complete after the last byte has been received, so it is not necessary
(though not harmful) to send a zero-length chunk to terminate. For streams, core will know that the transfer is
finished if a chunk with length less than the length requested in the callback is sent.
:param friend_number: The friend number of the receiving friend for this file.
:param file_number: The file transfer identifier returned by tox_file_send.
:param position: The file or stream position from which to continue reading.
:param data: Chunk of file data
:return: true on success.
"""
tox_err_file_send_chunk = c_int()
result = self.libtoxcore.tox_file_send_chunk(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number),
c_uint64(position), c_char_p(data), c_size_t(len(data)),
byref(tox_err_file_send_chunk))
tox_err_file_send_chunk = tox_err_file_send_chunk.value
if tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['OK']:
return bool(result)
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['NULL']:
raise ArgumentError('The length parameter was non-zero, but data was NULL.')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['FRIEND_NOT_FOUND']:
ArgumentError('The friend_number passed did not designate a valid friend.')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['FRIEND_NOT_CONNECTED']:
raise ArgumentError('This client is currently not connected to the friend.')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['NOT_FOUND']:
raise ArgumentError('No file transfer with the given file number was found for the given friend.')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['NOT_TRANSFERRING']:
raise ArgumentError('File transfer was found but isn\'t in a transferring state: (paused, done, broken, '
'etc...) (happens only when not called from the request chunk callback).')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['INVALID_LENGTH']:
raise ArgumentError('Attempted to send more or less data than requested. The requested data size is '
'adjusted according to maximum transmission unit and the expected end of the file. '
'Trying to send less or more than requested will return this error.')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['SENDQ']:
raise ArgumentError('Packet queue is full.')
elif tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['WRONG_POSITION']:
raise ArgumentError('Position parameter was wrong.')
def sendfile(fdout, fdin, offset, nbytes):
if sys.platform == 'darwin':
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_voidp,
ctypes.c_int]
_nbytes = ctypes.c_uint64(nbytes)
result = _sendfile(fdin, fdout, offset, _nbytes, None, 0)
if result == -1:
e = ctypes.get_errno()
if e == errno.EAGAIN and _nbytes.value is not None:
return _nbytes.value
raise OSError(e, os.strerror(e))
return _nbytes.value
elif sys.platform in ('freebsd', 'dragonfly',):
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_uint64,
ctypes.c_uint64, ctypes.c_voidp,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_int]
_sbytes = ctypes.c_uint64()
result = _sendfile(fdin, fdout, offset, nbytes, None, _sbytes, 0)
if result == -1:
e = ctypes.get_errno()
if e == errno.EAGAIN and _sbytes.value is not None:
return _sbytes.value
raise OSError(e, os.strerror(e))
return _sbytes.value
else:
_sendfile.argtypes = [ctypes.c_int, ctypes.c_int,
ctypes.POINTER(ctypes.c_uint64), ctypes.c_size_t]
_offset = ctypes.c_uint64(offset)
sent = _sendfile(fdout, fdin, _offset, nbytes)
if sent == -1:
e = ctypes.get_errno()
raise OSError(e, os.strerror(e))
return sent