cake
/
libp7
Archived
1
0
Fork 1
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libp7/src/packet/send_data.c

75 lines
2.5 KiB
C

/* ************************************************************************** */
/* _____ _ */
/* packet/send_data.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: libp7 | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
#include <string.h>
/**
* p7_send_data:
* Send data packet.
*
* Carries 'raw' data in the context of a command. E.g. file data.
* Maximum data size is 256 octets.
*
* @arg handle the libp7 handle
* @arg total the total number of data packets in trans
* @arg id the packet id
* @arg data the data part
* @arg datasize the data part size (in bytes)
* @arg resp should listen to response (shifting-related)
* @return if it worked
*/
int p7_send_data(p7_handle_t *handle,
p7ushort_t total, p7ushort_t id,
const void *data, p7ushort_t datasize, int resp)
{
/* make new buffer */
unsigned char buf[8 + datasize];
p7_putascii(buf, total, 4);
p7_putascii(&buf[4], id, 4);
memcpy(&buf[8], data, datasize);
/* send packet */
return (p7_send_ext(handle, p7_pt_data, handle->_last_sent_command,
buf, 8 + datasize, resp));
}
/**
* p7_send_data_quicker:
* Send data packet.
*
* Carries 'raw' data in the context of a command. E.g. file data.
* Maximum data size is 256 octets. Buffer must have 8 spare bytes because
* that's the advantages of this function above the one before : it doesn't
* memcpy again.
*
* @arg handle the libp7 handle
* @arg total the total number of data packets in trans
* @arg id the packet id
* @arg buf the buffer with 8 spare bytes at the beginning
* @arg datasize the data part size (in bytes)
* @arg resp should listen to response (shifting-related)
* @return if it worked
*/
int p7_send_data_quicker(p7_handle_t *handle,
p7ushort_t total, p7ushort_t id,
void *buf, p7ushort_t datasize, int resp)
{
/* make new buffer */
unsigned char *cbuf = buf;
p7_putascii(cbuf, total, 4);
p7_putascii(&cbuf[4], id, 4);
/* send packet */
return (p7_send_ext(handle, p7_pt_data, handle->_last_sent_command,
buf, 8 + datasize, resp));
}