libp7/include/libp7/buffer.h

40 lines
1.7 KiB
C

/* ************************************************************************** */
/* _____ _ */
/* libp7/buffer.h |_ _|__ _ _| |__ ___ _ _ */
/* | Project: libp7 | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2017/02/05 17:23:04 |___/ */
/* */
/* ************************************************************************** */
#ifndef LIBP7_BUFFER_H
# define LIBP7_BUFFER_H
/* This file is there so it is possible to use a custom buffer for file
* transferring. There are two use cases:
* - if you use a buffer to send data: the size of the element to send should
* be put in `size`, and the `read` function will be used;
* - if you use a buffer to receive data: if the `announce` function is set,
* it will be called with the size of the file to receive, in order to
* prepare space for the file. If the announce function returns an error,
* then the file will not be sent.
*
* Here are the used functions. */
typedef int (*p7_buffer_read_t)(void*, unsigned char*, size_t);
typedef int (*p7_buffer_write_t)(void*, const unsigned char*, size_t);
typedef int (*p7_buffer_announce_t)(void*, p7uint_t);
/* And here is the structure of a buffer: */
typedef struct {
void *cookie;
p7uint_t size;
p7_buffer_read_t read;
p7_buffer_write_t write;
p7_buffer_announce_t announce;
} p7_buffer_t;
#endif /* LIBP7_BUFFER_H */